Beispiel #1
0
        public void VisitNode(JSTryCatchBlock tcb)
        {
            // Hoisting a label out of the try {} body is safe since it always runs.
            MaybeHoist(tcb, tcb.Body.SelfAndChildren.OfType <JSStatement>());

            VisitChildren(tcb);
        }
        public void VisitNode(JSTryCatchBlock tcb)
        {
            if ((tcb.Finally != null) && (tcb.Catch == null))
            {
                do
                {
                    if (!tcb.Finally.Children.All((n) => n is JSExpressionStatement))
                    {
                        break;
                    }

                    var statements = tcb.Finally.Children.OfType <JSExpressionStatement>().ToArray();

                    if (statements.Any((es) => es.Expression.HasGlobalStateDependency))
                    {
                        break;
                    }

                    if (!statements.All((es) => IsEffectivelyConstant(es.Expression)))
                    {
                        break;
                    }

                    ParentNode.ReplaceChild(tcb, tcb.Body);
                    VisitReplacement(tcb.Body);
                    return;
                } while (false);
            }

            VisitChildren(tcb);
        }
Beispiel #3
0
        public void VisitNode(JSTryCatchBlock tcb)
        {
            if (tcb.CatchVariable != null)
            {
                State.Assignments.Add(
                    new FunctionAnalysis1stPass.Assignment(
                        GetParentNodeIndices(), StatementIndex, NodeIndex,
                        tcb.CatchVariable, new JSNullExpression(), JSOperator.Assignment,
                        tcb.CatchVariable.IdentifierType, tcb.CatchVariable.IdentifierType
                        )
                    );

                ModifiedVariable(tcb.CatchVariable);
            }

            VisitChildren(tcb);
        }
Beispiel #4
0
        public void VisitNode(JSTryCatchBlock tcb)
        {
            if ((tcb.Catch ?? tcb.Finally) == null)
            {
                Visit(tcb.Body);
                return;
            }

            Output.WriteRaw("try");
            Output.Space();
            Output.OpenBrace();

            Visit(tcb.Body);

            if (tcb.Catch != null)
            {
                Output.CloseAndReopenBrace((o) => {
                    if (o != Output)
                    {
                        throw new InvalidOperationException("Output mismatch");
                    }

                    o.WriteRaw("catch");
                    o.Space();
                    o.LPar();
                    Visit(tcb.CatchVariable);
                    o.RPar();
                });

                Visit(tcb.Catch);
            }

            if (tcb.Finally != null)
            {
                Output.CloseAndReopenBrace("finally");

                Visit(tcb.Finally);
            }

            Output.CloseBrace();
        }