Exemplo n.º 1
0
        public void Visit(TryNode node)
        {
            if (node != null)
            {
                node.Index = NextOrderIndex;

                if (node.TryBlock != null)
                {
                    node.TryBlock.Accept(this);
                }

                // add this catch parameter to the list of catch parameters the variable
                // scope will need to ghost later.
                if (node.CatchParameter != null)
                {
                    CurrentVariableScope.GhostedCatchParameters.Add(node.CatchParameter);
                }

                if (node.CatchBlock != null)
                {
                    // create the catch-scope, add the catch parameter to it, and recurse the catch block.
                    // the block itself will push the scope onto the stack and pop it off, so we don't have to.
                    node.CatchBlock.BlockScope = new CatchScope(CurrentLexicalScope, node.CatchBlock.Context, m_settings, node.CatchParameter)
                    {
                        IsInWithScope = m_withDepth > 0
                    };
                    node.CatchBlock.BlockScope.LexicallyDeclaredNames.Add(node.CatchParameter);
                    node.CatchBlock.Accept(this);
                }

                if (node.FinallyBlock != null)
                {
                    node.FinallyBlock.Accept(this);
                }
            }
        }
Exemplo n.º 2
0
 public void Visit(TryNode node)
 {
     // invalid! ignore
     IsValid = false;
 }
 public void Visit(TryNode node)
 {
     // invalid! ignore
     IsValid = false;
 }
Exemplo n.º 4
0
 public void Visit(TryNode node)
 {
     Debug.Fail("shouldn't get here");
 }
Exemplo n.º 5
0
 public void Visit(TryNode node)
 {
     // not applicable; terminate
 }
        public void Visit(TryNode node)
        {
            if (node != null)
            {
                node.Index = NextOrderIndex;

                if (node.TryBlock != null)
                {
                    node.TryBlock.Accept(this);
                }

                // add this catch parameter to the list of catch parameters the variable
                // scope will need to ghost later.
                if (node.CatchParameter != null)
                {
                    CurrentVariableScope.GhostedCatchParameters.Add(node.CatchParameter);
                }

                if (node.CatchBlock != null)
                {
                    // create the catch-scope, add the catch parameter to it, and recurse the catch block.
                    // the block itself will push the scope onto the stack and pop it off, so we don't have to.
                    node.CatchBlock.BlockScope = new CatchScope(CurrentLexicalScope, node.CatchBlock.Context, m_settings, node.CatchParameter)
                    {
                        IsInWithScope = m_withDepth > 0
                    };
                    node.CatchBlock.BlockScope.LexicallyDeclaredNames.Add(node.CatchParameter);
                    node.CatchBlock.Accept(this);
                }

                if (node.FinallyBlock != null)
                {
                    node.FinallyBlock.Accept(this);
                }
            }
        }
 public void Visit(TryNode node)
 {
     Debug.Fail("shouldn't get here");
 }
 public void Visit(TryNode node)
 {
     // not applicable; terminate
 }
        public override void Visit(TryNode node)
        {
            if (node != null)
            {
                // anaylze the blocks
                base.Visit(node);

                // if the try block is empty, then set it to null
                if (node.TryBlock != null && node.TryBlock.Count == 0)
                {
                    node.TryBlock = null;
                }

                // eliminate an empty finally block UNLESS there is no catch block.
                if (node.FinallyBlock != null && node.FinallyBlock.Count == 0 && node.CatchBlock != null
                    && m_parser.Settings.IsModificationAllowed(TreeModifications.RemoveEmptyFinally))
                {
                    node.FinallyBlock = null;
                }

                // check strict-mode restrictions
                if (m_scopeStack.Peek().UseStrict && !string.IsNullOrEmpty(node.CatchVarName))
                {
                    // catch variable cannot be named "eval" or "arguments"
                    if (string.CompareOrdinal(node.CatchVarName, "eval") == 0
                        || string.CompareOrdinal(node.CatchVarName, "arguments") == 0)
                    {
                        node.CatchVarContext.HandleError(JSError.StrictModeVariableName, true);
                    }
                }

                if (node.CatchParameter != null)
                {
                    // if the block has a lexical scope, check it for conflicts
                    foreach(var lexDecl in node.CatchBlock.BlockScope.LexicallyDeclaredNames)
                    {
                        if (lexDecl != node.CatchParameter
                            && string.CompareOrdinal(lexDecl.Name, node.CatchParameter.Name) == 0)
                        {
                            // report the error (catchvar collides with lex/const) or warning (catchvar collides with funcdecl)
                            lexDecl.NameContext.HandleError(JSError.DuplicateLexicalDeclaration, lexDecl is LexicalDeclaration);

                            // link the inner one to the outer one so any renaming stays in sync.
                            if (lexDecl.VariableField != null)
                            {
                                lexDecl.VariableField.OuterField = node.CatchParameter.VariableField;
                                if (node.CatchParameter.VariableField != null && !lexDecl.VariableField.CanCrunch)
                                {
                                    node.CatchParameter.VariableField.CanCrunch = false;
                                }
                            }
                        }
                    }

                    // check to make sure there are no var-decl'd names with the same name. 
                    foreach (var varDecl in node.CatchBlock.BlockScope.VarDeclaredNames)
                    {
                        if (string.CompareOrdinal(varDecl.Name, node.CatchParameter.Name) == 0)
                        {
                            // report the warning (catchvar collides with var)
                            // we shouldn't have to link them; the catchvar should already ghosted.
                            varDecl.NameContext.HandleError(JSError.DuplicateLexicalDeclaration, false);
                        }
                    }
                }
            }
        }