예제 #1
0
        private void DefineField(ResolutionVisitor resolutionVisitor, INameDeclaration nameDecl)
        {
            if (nameDecl == null)
            {
                // malformed code, for example catch w/o a variable.
                return;
            }
            var field = this[nameDecl.Name];

            if (nameDecl is ParameterDeclaration)
            {
                // function parameters are handled separately, so if this is a parameter declaration,
                // then it must be a catch variable.
                if (field == null)
                {
                    // no collision - create the catch-error field
                    field = new JSVariableField(FieldType.CatchError, nameDecl.Name);

                    this.AddField(field);
                }
                else
                {
                    // it's an error to declare anything in the catch scope with the same name as the
                    // error variable

                    ErrorSink.HandleError(JSError.DuplicateCatch, nameDecl.GetNameSpan(GlobalScope.Node.LocationResolver), resolutionVisitor._locationResolver, true);
                }
            }
            else
            {
                if (field == null)
                {
                    // could be global or local depending on the scope, so let the scope create it.
                    field = this.CreateField(nameDecl.Name);

                    // if this field is a constant, mark it now
                    var lexDeclaration = nameDecl.Parent as LexicalDeclaration;

                    this.AddField(field);
                }
                else
                {
                    // already defined!
                    // if this is a lexical declaration, then it's an error because we have two
                    // lexical declarations with the same name in the same scope.
                    if (nameDecl.Parent is LexicalDeclaration)
                    {
                        _errorSink.HandleError(
                            JSError.DuplicateLexicalDeclaration,
                            nameDecl.GetNameSpan(GlobalScope.Node.LocationResolver),
                            resolutionVisitor._locationResolver,
                            true
                            );
                    }
                }
            }

            nameDecl.VariableField = field;
        }
예제 #2
0
        /// <summary>
        /// Set up this scopes lexically- and var-declared fields
        /// </summary>
        public override void DeclareScope(ResolutionVisitor resolutionVisitor)
        {
            // bind lexical declarations
            DefineLexicalDeclarations(resolutionVisitor);

            // bind the variable declarations
            DefineVarDeclarations(resolutionVisitor);
        }
예제 #3
0
 protected void DefineVarDeclarations(ResolutionVisitor resolutionVisitor)
 {
     foreach (var varDecl in VarDeclaredNames)
     {
         // var-decls are always initialized to null
         DefineField(resolutionVisitor, varDecl);
     }
 }
예제 #4
0
        /// <summary>
        /// Set up this scopes lexically- and var-declared fields
        /// </summary>
        public override void DeclareScope(ResolutionVisitor resolutionVisitor)
        {
            // bind lexical declarations
            DefineLexicalDeclarations(resolutionVisitor);

            // bind the variable declarations
            DefineVarDeclarations(resolutionVisitor);
        }
예제 #5
0
 protected void DefineLexicalDeclarations(ResolutionVisitor resolutionVisitor)
 {
     foreach (var lexDecl in LexicallyDeclaredNames)
     {
         // use the function as the field value if it's a function
         DefineField(resolutionVisitor, lexDecl);
     }
 }
예제 #6
0
        /// <summary>
        /// Set up this scopes lexically- and var-declared fields, plus formal parameters and the arguments object
        /// </summary>
        public override void DeclareScope(ResolutionVisitor resolutionVisitor)
        {
            // we are a function expression that points to a function object. 
            // if the function object points back to us, then this is the main
            // function scope. But if it doesn't, then this is actually the parent
            // scope for named function expressions that should contain just a field
            // for the function name
            if (resolutionVisitor.GetScope(FunctionObject) == this)
            {
                // first bind any parameters
                DefineParameters();

                // bind lexical declarations next
                DefineLexicalDeclarations(resolutionVisitor);

                // bind the arguments object if this is a function scope
                DefineArgumentsObject();

                // bind the variable declarations
                DefineVarDeclarations(resolutionVisitor);

                DefineFunctionExpressionName();
            }
        }
예제 #7
0
        public static void Apply(Node node, ActivationObject scope, LocationResolver indexResolver, ErrorSink errorSink)
        {
            if (node != null && scope != null)
            {
                // create the visitor and run it. This will create all the child
                // scopes and populate all the scopes with the var-decl, lex-decl,
                // and lookup references within them.
                var visitor = new ResolutionVisitor(scope, indexResolver, errorSink);
                node.Walk(visitor);

                // now that all the scopes are created and they all know what decls
                // they contains, create all the fields
                visitor.CreateFields(scope);

                // now that all the fields have been created in all the scopes,
                // let's go through and resolve all the references
                visitor.ResolveLookups(scope);

                // now that everything is declared and resolved as per the language specs,
                // we need to go back and add ghosted fields for older versions of IE that
                // incorrectly implement catch-variables and named function expressions.
                visitor.AddGhostedFields(scope);
            }
        }
        public static void Apply(Node node, ActivationObject scope, LocationResolver indexResolver, ErrorSink errorSink)
        {
            if (node != null && scope != null)
            {
                // create the visitor and run it. This will create all the child
                // scopes and populate all the scopes with the var-decl, lex-decl,
                // and lookup references within them.
                var visitor = new ResolutionVisitor(scope, indexResolver, errorSink);
                node.Walk(visitor);

                // now that all the scopes are created and they all know what decls
                // they contains, create all the fields
                visitor.CreateFields(scope);

                // now that all the fields have been created in all the scopes,
                // let's go through and resolve all the references
                visitor.ResolveLookups(scope);

                // now that everything is declared and resolved as per the language specs,
                // we need to go back and add ghosted fields for older versions of IE that
                // incorrectly implement catch-variables and named function expressions.
                visitor.AddGhostedFields(scope);
            }
        }
예제 #9
0
        /// <summary>
        /// Set up this scopes lexically- and var-declared fields, plus formal parameters and the arguments object
        /// </summary>
        public override void DeclareScope(ResolutionVisitor resolutionVisitor)
        {
            // we are a function expression that points to a function object.
            // if the function object points back to us, then this is the main
            // function scope. But if it doesn't, then this is actually the parent
            // scope for named function expressions that should contain just a field
            // for the function name
            if (resolutionVisitor.GetScope(FunctionObject) == this)
            {
                // first bind any parameters
                DefineParameters();

                // bind lexical declarations next
                DefineLexicalDeclarations(resolutionVisitor);

                // bind the arguments object if this is a function scope
                DefineArgumentsObject();

                // bind the variable declarations
                DefineVarDeclarations(resolutionVisitor);

                DefineFunctionExpressionName();
            }
        }
예제 #10
0
 /// <summary>
 /// Set up this scopes lexically-declared fields
 /// </summary>
 public override void DeclareScope(ResolutionVisitor resolutionVisitor)
 {
     // only bind lexical declarations
     DefineLexicalDeclarations(resolutionVisitor);
 }
예제 #11
0
 /// <summary>
 /// Set up this scope's fields from the declarations it contains
 /// </summary>
 public abstract void DeclareScope(ResolutionVisitor resolutionVisitor);
예제 #12
0
 /// <summary>
 /// Set up this scopes lexically-declared fields
 /// </summary>
 public override void DeclareScope(ResolutionVisitor resolutionVisitor)
 {
     // only bind lexical declarations
     DefineLexicalDeclarations(resolutionVisitor);
 }
        private void DefineField(ResolutionVisitor resolutionVisitor, INameDeclaration nameDecl)
        {
            if (nameDecl == null) {
                // malformed code, for example catch w/o a variable.
                return;
            }
            var field = this[nameDecl.Name];
            if (nameDecl is ParameterDeclaration)
            {
                // function parameters are handled separately, so if this is a parameter declaration,
                // then it must be a catch variable. 
                if (field == null)
                {
                    // no collision - create the catch-error field
                    field = new JSVariableField(FieldType.CatchError, nameDecl.Name);

                    this.AddField(field);
                }
                else
                {
                    // it's an error to declare anything in the catch scope with the same name as the
                    // error variable
                    
                    ErrorSink.HandleError(JSError.DuplicateCatch, nameDecl.GetNameSpan(GlobalScope.Node.LocationResolver), resolutionVisitor._locationResolver, true);
                }
            }
            else
            {
                if (field == null)
                {
                    // could be global or local depending on the scope, so let the scope create it.
                    field = this.CreateField(nameDecl.Name);
                    
                    // if this field is a constant, mark it now
                    var lexDeclaration = nameDecl.Parent as LexicalDeclaration;

                    this.AddField(field);
                }
                else
                {
                    // already defined! 
                    // if this is a lexical declaration, then it's an error because we have two
                    // lexical declarations with the same name in the same scope.
                    if (nameDecl.Parent is LexicalDeclaration)
                    {
                        _errorSink.HandleError(
                            JSError.DuplicateLexicalDeclaration, 
                            nameDecl.GetNameSpan(GlobalScope.Node.LocationResolver), 
                            resolutionVisitor._locationResolver, 
                            true
                        );
                    }
                }
            }

            nameDecl.VariableField = field;
        }
 protected void DefineVarDeclarations(ResolutionVisitor resolutionVisitor)
 {
     foreach (var varDecl in VarDeclaredNames)
     {
         // var-decls are always initialized to null
         DefineField(resolutionVisitor, varDecl);
     }
 }
 protected void DefineLexicalDeclarations(ResolutionVisitor resolutionVisitor)
 {
     foreach (var lexDecl in LexicallyDeclaredNames)
     {
         // use the function as the field value if it's a function
         DefineField(resolutionVisitor, lexDecl);
     }
 }
 /// <summary>
 /// Set up this scope's fields from the declarations it contains
 /// </summary>
 public abstract void DeclareScope(ResolutionVisitor resolutionVisitor);