Beispiel #1
0
        public override JsCatchClause VisitCatchClause(JsCatchClause clause, Tuple <JsDeclarationScope, DeclarationScopeHierarchy> data)
        {
            data.Item2.ChildScopes.Add(clause);
            var hier = new DeclarationScopeHierarchy(data.Item1);

            _result[clause] = hier;
            return(base.VisitCatchClause(clause, Tuple.Create((JsDeclarationScope)clause, hier)));
        }
Beispiel #2
0
 public virtual JsNode Visit(JsCatchClause node)
 {
     return(DefaultVisit(node, x =>
     {
         x.Declaration = (JsVariableDeclarator)x.Declaration.Accept(this);
         x.Body = (JsBlockStatement)x.Body.Accept(this);
         return x;
     }));
 }
            public override JsCatchClause VisitCatchClause(JsCatchClause clause, Tuple <Dictionary <string, string>, HashSet <string> > data)
            {
                var    newData   = new Dictionary <string, string>(data.Item1);
                var    usedNames = new HashSet <string>(data.Item1.Values.Concat(data.Item2));
                string newName   = _generateName(clause.Identifier, usedNames);

                newData.Add(clause.Identifier, newName);
                return(JsStatement.Catch(newName, VisitStatement(clause.Body, Tuple.Create(newData, data.Item2))));
            }
Beispiel #4
0
 public override void VisitCatchClause(JsCatchClause node)
 {
     output.Append("catch ");
     if (node.Declaration != null)
     {
         output.Append("(");
         node.Declaration.Accept(this);
         output.Append(") ");
     }
     node.Body.Accept(this);
 }
Beispiel #5
0
        public JsNode VisitCatchClause(CatchClause node)
        {
            var node2 = new JsCatchClause();

            if (node.VariableName.IsNullOrEmpty())
            {
                node.VariableName = "$$e" + (VariableExceptionCounter++);                 //Generate a psuedo-unique variable name
            }
            node2.IdentifierName = node.VariableName;

            node2.Block = (JsBlock)Visit(node.Body);
            if (node2.Block != null)
            {
                node2.Descendants <JsThrowStatement>().Where(t => t.Expression == null).ForEach(t => t.Expression = Js.Member(node2.IdentifierName));
            }
            return(node2);
        }
        public override JsCatchClause VisitCatchClause(JsCatchClause clause, IDictionary <string, string> data)
        {
            IDictionary <string, string> newData;

            if (!_renames.TryGetValue(clause, out newData))
            {
                newData = data;
            }

            string newName;

            if (newData.TryGetValue(clause.Identifier, out newName))
            {
                return(JsStatement.Catch(newName, VisitStatement(clause.Body, newData)));
            }
            else
            {
                return(base.VisitCatchClause(clause, newData));
            }
        }
Beispiel #7
0
 public virtual void Visit(JsCatchClause node)
 {
     DefaultVisit(node);
     node.Declaration.Accept(this);
     node.Body.Accept(this);
 }
Beispiel #8
0
 public override JsCatchClause VisitCatchClause(JsCatchClause clause, Tuple <ImmutableStack <JsDeclarationScope>, HashSet <string> > data)
 {
     _result[clause] = new HashSet <string>();
     return(base.VisitCatchClause(clause, Tuple.Create(data.Item1.Push(clause), Union(data.Item2, new[] { clause.Identifier }))));
 }
Beispiel #9
0
        private bool HandleTryStatement(JsTryStatement stmt, StackEntry location, ImmutableStack <StackEntry> stack, ImmutableStack <Tuple <string, State> > breakStack, ImmutableStack <Tuple <string, State> > continueStack, State currentState, State returnState, IList <JsStatement> currentBlock)
        {
            if (_isIteratorBlock && (FindInterestingConstructsVisitor.Analyze(stmt.GuardedStatement, InterestingConstruct.YieldReturn) || (stmt.Finally != null && stmt.Catch == null && !currentState.FinallyStack.IsEmpty)))
            {
                if (stmt.Catch != null)
                {
                    throw new InvalidOperationException("Cannot yield return from try with catch");
                }
                string           handlerName = _allocateFinallyHandler();
                JsBlockStatement handler;
                if (FindInterestingConstructsVisitor.Analyze(stmt.Finally, InterestingConstruct.Label))
                {
                    var inner = ProcessInner(stmt.Finally, breakStack, continueStack, currentState.FinallyStack, currentState.StateValue);
                    handler = new JsBlockStatement(new[]  { new JsSetNextStateStatement(inner.Item2) }.Concat(inner.Item1));
                    handler = new FinalizerRewriter(_stateVariableName, _labelStates).Process(handler);
                }
                else
                {
                    handler = stmt.Finally;
                }

                _finallyHandlers.Add(Tuple.Create(handlerName, handler));
                var stateAfter         = GetStateAfterStatement(location, stack, currentState.FinallyStack, returnState);
                var innerState         = CreateNewStateValue(currentState.FinallyStack, handlerName);
                var stateBeforeFinally = CreateNewStateValue(innerState.FinallyStack);
                currentBlock.Add(new JsSetNextStateStatement(innerState.StateValue));
                currentBlock.AddRange(Handle(ImmutableStack <StackEntry> .Empty.Push(new StackEntry(stmt.GuardedStatement, 0)), breakStack, continueStack, innerState, stateBeforeFinally));

                Enqueue(ImmutableStack <StackEntry> .Empty.Push(new StackEntry(new JsBlockStatement(new JsBlockStatement(new JsStatement[0], true)), 0)), breakStack, continueStack, stateBeforeFinally, stateAfter.Item1);
                if (!stack.IsEmpty || location.Index < location.Block.Statements.Count - 1)
                {
                    Enqueue(PushFollowing(stack, location), breakStack, continueStack, stateAfter.Item1, returnState);
                }
                return(false);
            }
            else if (_isIteratorBlock && stmt.Finally != null && !currentState.FinallyStack.IsEmpty)
            {
                // This is necessary to special-case in order to ensure that the inner finally block is executed before all outer ones.
                return(HandleTryStatement(new JsTryStatement(new JsTryStatement(stmt.GuardedStatement, stmt.Catch, null), null, stmt.Finally), location, stack, breakStack, continueStack, currentState, returnState, currentBlock));
            }
            else
            {
                var rewriter = new NestedJumpStatementRewriter(breakStack, continueStack, currentState, _exitState.Value);
                JsBlockStatement guarded;
                var guardedConstructs = FindInterestingConstructsVisitor.Analyze(stmt.GuardedStatement);
                if ((guardedConstructs & (InterestingConstruct.Label | InterestingConstruct.Await)) != InterestingConstruct.None)
                {
                    var inner = ProcessInner(stmt.GuardedStatement, breakStack, continueStack, currentState.FinallyStack, currentState.StateValue);
                    guarded = new JsBlockStatement(inner.Item1);
                    currentBlock.Add(new JsSetNextStateStatement(inner.Item2));
                }
                else
                {
                    guarded = rewriter.Process(stmt.GuardedStatement);
                }

                JsCatchClause @catch;
                if (stmt.Catch != null)
                {
                    if (FindInterestingConstructsVisitor.Analyze(stmt.Catch.Body, InterestingConstruct.Label))
                    {
                        var inner = ProcessInner(stmt.Catch.Body, breakStack, continueStack, currentState.FinallyStack, null);
                        @catch = new JsCatchClause(stmt.Catch.Identifier, new JsBlockStatement(new[] { new JsSetNextStateStatement(inner.Item2) }.Concat(inner.Item1)));
                    }
                    else
                    {
                        var body = rewriter.Process(stmt.Catch.Body);
                        @catch = ReferenceEquals(body, stmt.Catch.Body) ? stmt.Catch : new JsCatchClause(stmt.Catch.Identifier, body);
                    }
                }
                else
                {
                    @catch = null;
                }

                JsBlockStatement @finally;
                if (stmt.Finally != null)
                {
                    if (FindInterestingConstructsVisitor.Analyze(stmt.Finally, InterestingConstruct.Label))
                    {
                        var inner = ProcessInner(stmt.Finally, breakStack, continueStack, currentState.FinallyStack, null);
                        @finally = new JsBlockStatement(new[] { new JsSetNextStateStatement(inner.Item2) }.Concat(inner.Item1));
                    }
                    else
                    {
                        @finally = rewriter.Process(stmt.Finally);
                    }

                    if ((guardedConstructs & InterestingConstruct.Await) != InterestingConstruct.None)
                    {
                        // Wrap the finally block inside an 'if (doFinallyBlocks) {}'
                        @finally = new JsBlockStatement(new JsIfStatement(JsExpression.Identifier(_doFinallyBlocksVariableName), @finally, null));
                    }
                }
                else
                {
                    @finally = null;
                }

                if (currentBlock.Count > 0 && _childStates.ContainsKey(currentState.StateValue))
                {
                    var newBlock = new JsIfStatement(JsExpression.Same(JsExpression.Identifier(_stateVariableName), JsExpression.Number(currentState.StateValue)), new JsBlockStatement(currentBlock), null);
                    currentBlock.Clear();
                    currentBlock.Add(newBlock);
                }

                currentBlock.Add(new JsTryStatement(guarded, @catch, @finally));
                return(true);
            }
        }
Beispiel #10
0
 public override JsCatchClause VisitCatchClause(JsCatchClause clause, object data)
 {
     _result.Add(clause.Identifier);
     return(base.VisitCatchClause(clause, data));
 }
 public override JsCatchClause VisitCatchClause(JsCatchClause clause, Tuple <ImmutableStack <Function>, HashSet <string> > data)
 {
     return(base.VisitCatchClause(clause, Tuple.Create(data.Item1, Union(data.Item2, new[] { clause.Identifier }))));
 }
 public override JsCatchClause VisitCatchClause(JsCatchClause clause, HashSet <string> data)
 {
     return(base.VisitCatchClause(clause, _result[clause] = new HashSet <string> {
         clause.Identifier
     }));
 }
        public virtual JsCatchClause VisitCatchClause(JsCatchClause clause, TData data)
        {
            var body = VisitStatement(clause.Body, data);

            return(ReferenceEquals(body, clause.Body) ? clause : new JsCatchClause(clause.Identifier, body));
        }
Beispiel #14
0
 public void Visit(JsCatchClause node)
 {
     BeforeVisit(node);
     DefaultVisit(node, VisitCatchClause);
     AfterVisit(node);
 }
Beispiel #15
0
 public virtual void VisitCatchClause(JsCatchClause node)
 {
 }
Beispiel #16
0
 public override JsCatchClause VisitCatchClause(JsCatchClause clause, IList <string> data)
 {
     return(base.VisitCatchClause(clause, _result[clause] = new List <string>()));
 }