001    // Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file
002    // for details. All rights reserved. Use of this source code is governed by a
003    // BSD-style license that can be found in the LICENSE file.
004    
005    package com.google.dart.compiler.backend.js.ast;
006    
007    import com.google.dart.compiler.backend.js.JsReservedIdentifiers;
008    
009    /**
010     * The root scope is the parent of every scope. All identifiers in this scope
011     * are not obfuscatable. This scope is prefilled with reserved global
012     * JavaScript symbols.
013     */
014    public final class JsRootScope extends JsScope {
015      private final JsProgram program;
016    
017      public JsRootScope(JsProgram program) {
018        super("Root");
019        this.program = program;
020      }
021    
022      @Override
023      public JsProgram getProgram() {
024        return program;
025      }
026    
027      @Override
028      protected JsName findOwnName(String ident) {
029        JsName name = super.findOwnName(ident);
030        if (name == null) {
031            if (JsReservedIdentifiers.reservedGlobalSymbols.contains(ident)) {
032            /*
033             * Lazily add JsNames for reserved identifiers.  Since a JsName for a reserved global symbol
034             * must report a legitimate enclosing scope, we can't simply have a shared set of symbol
035             * names.
036             */
037            name = doCreateName(ident);
038          }
039        }
040        return name;
041      }
042    }