Esempio n. 1
0
        internal static Completion IteratorBindingInitializationBindingRestIdentifier(Identifier restParameterIdentifier, LexicalEnvironment?env, ArgumentIterator arguments)
        {
            var lhsComp = Interpreter.Instance().ResolveBinding(restParameterIdentifier.name, restParameterIdentifier.IsStrictMode, env);

            if (lhsComp.IsAbrupt())
            {
                return(lhsComp);
            }
            var lhs = (lhsComp.value as ReferenceValue) !;
            var A   = ArrayObject.ArrayCreate(0);
            int n   = 0;

            for (; ; n++)
            {
                if (arguments.Done)
                {
                    if (env == null)
                    {
                        return(lhs.PutValue(A));
                    }
                    return(lhs.InitializeReferencedBinding(A));
                }
                var nextValue = arguments.Next();
                var status    = Utils.CreateDataProperty(A, n.ToString(System.Globalization.CultureInfo.InvariantCulture), nextValue);
                if (!status.Other)
                {
                    throw new InvalidOperationException("BindingRestElement IteratorBindingInitialization: assert step 4g");
                }
            }
        }
Esempio n. 2
0
        internal static Completion IteratorBindingInitializationSingleNameBinding(Identifier identifier, AbstractAssignmentExpression?initializer, LexicalEnvironment?env, ArgumentIterator arguments)
        {
            var lhsComp = Interpreter.Instance().ResolveBinding(identifier.name, identifier.IsStrictMode, env);

            if (lhsComp.IsAbrupt())
            {
                return(lhsComp);
            }
            var    lhs = (lhsComp.value as ReferenceValue) !;
            IValue v;

            if (!arguments.Done)
            {
                v = arguments.Next();
            }
            else
            {
                v = UndefinedValue.Instance;
            }
            if (initializer != null && v == UndefinedValue.Instance)
            {
                if (initializer is FunctionExpression f && f.isAnonymous)
                {
                    var comp = f.NamedEvaluate(Interpreter.Instance(), identifier.name);
                    if (comp.IsAbrupt())
                    {
                        return(comp);
                    }
                    v = comp.value !;
                }
                else
                {
                    var comp = initializer.Evaluate(Interpreter.Instance()).GetValue();
                    if (comp.IsAbrupt())
                    {
                        return(comp);
                    }
                    v = comp.value !;
                }
            }