コード例 #1
0
        public void VisitNode(JSNewArrayElementReference naer)
        {
            var isInsideLoop     = (Stack.Any((node) => node is JSLoopStatement));
            var parentPassByRef  = ParentNode as JSPassByReferenceExpression;
            var parentInvocation = Stack.OfType <JSInvocationExpression>().FirstOrDefault();
            var doesValueEscape  = DoesValueEscapeFromInvocation(parentInvocation, naer, true);

            if (
                isInsideLoop &&
                (parentPassByRef != null) &&
                (parentInvocation != null) &&
                !doesValueEscape
                )
            {
                var replacement = CreateHoistedVariable(
                    (hoistedVariable) => JSInvocationExpression.InvokeMethod(
                        new JSFakeMethod("retarget", hoistedVariable.GetActualType(TypeSystem), new TypeReference[] { TypeSystem.Object, TypeSystem.Int32 }, MethodTypes),
                        hoistedVariable, new JSExpression[] { naer.Array, naer.Index }
                        ),
                    naer.GetActualType(TypeSystem),
                    naer.MakeUntargeted()
                    );

                ParentNode.ReplaceChild(naer, replacement);
                VisitReplacement(replacement);
            }

            VisitChildren(naer);
        }
コード例 #2
0
        public void VisitNode(JSNewArrayElementReference naer)
        {
            var isInsideLoop = (Stack.Any((node) => node is JSLoopStatement));
            var parentPassByRef = ParentNode as JSPassByReferenceExpression;
            var parentInvocation = Stack.OfType<JSInvocationExpression>().FirstOrDefault();
            var doesValueEscape = DoesValueEscapeFromInvocation(parentInvocation, naer);

            if (
                isInsideLoop &&
                (parentPassByRef != null) &&
                (parentInvocation != null) &&
                !doesValueEscape
            ) {
                var replacement = CreateHoistedVariable(
                    (hoistedVariable) => JSInvocationExpression.InvokeMethod(
                        new JSFakeMethod("retarget", hoistedVariable.GetActualType(TypeSystem), new TypeReference[] { TypeSystem.Object, TypeSystem.Int32 }, MethodTypes),
                        hoistedVariable, new JSExpression[] { naer.Array, naer.Index }
                    ),
                    naer.GetActualType(TypeSystem),
                    naer.MakeUntargeted()
                );

                ParentNode.ReplaceChild(naer, replacement);
                VisitReplacement(replacement);
            }

            VisitChildren(naer);
        }