Ejemplo n.º 1
0
        /// <summary>
        /// Creates a <see cref="ArgumentsObject"/> for the specified variadic
        /// <see cref="FunctionObject"/> <paramref name="f"/>.
        /// </summary>
        /// <param name="f">The f.</param>
        /// <param name="privateScope">The private scope.</param>
        /// <param name="sharedScope">The shared scope.</param>
        /// <param name="variadicArgs">The variadic args.</param>
        /// <returns>
        /// A <see cref="ArgumentsObject"/> for the specified variadic <see cref="FunctionObject"/>
        /// <paramref name="f"/>.
        /// </returns>
        public static ArgumentsObject CreateForVariadicFunction(
            FunctionObject f,
            BoxedValue[] privateScope,
            BoxedValue[] sharedScope,
            BoxedValue[] variadicArgs)
        {
            // TODO: This method has no tests. [asbjornu]

            var x =
                new ArgumentsObject(
                    f.Env,
                    f.MetaData.ParameterStorage,
                    privateScope,
                    sharedScope
                    );

            x.CopyLinkedValues();
            x.Put("constructor", f.Env.Constructors.Object, 0xffffff08);
            x.Put("length", variadicArgs.Length, 2);
            x.Put("callee", f, 2);

            // TODO: R# says this expression will always evaluate to false. Rewrite or remove? [asbjornu]
            if (!ReferenceEquals(variadicArgs, null))
            {
                var i = f.MetaData.ParameterStorage.Length;
                for (; i < variadicArgs.Length; i++)
                    x.Put((uint)i, variadicArgs[i]);
            }

            return x;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="ArgumentsObject"/> for the specified <see cref="FunctionObject"/>
        /// <paramref name="f"/>.
        /// </summary>
        /// <param name="f">The function for which to create an <see cref="ArgumentsObject"/>.</param>
        /// <param name="privateScope">The private scope.</param>
        /// <param name="sharedScope">The shared scope.</param>
        /// <param name="namedArgsPassed">The number of named arguments that is passed.</param>
        /// <param name="extraArgs">The extra arguments.</param>
        /// <returns>
        /// A <see cref="ArgumentsObject"/> for the specified <see cref="FunctionObject"/>
        /// <paramref name="f"/>.
        /// </returns>
        public static ArgumentsObject CreateForFunction(
            FunctionObject f,
            BoxedValue[] privateScope,
            BoxedValue[] sharedScope,
            int namedArgsPassed,
            BoxedValue[] extraArgs)
        {
            // TODO: This method has no tests. [asbjornu]

            var length = namedArgsPassed + extraArgs.Length;
            var storage =
                f.MetaData.ParameterStorage
                    .Take(namedArgsPassed)
                    .ToArray();

            var x =
                new ArgumentsObject(
                    f.Env,
                    storage,
                    privateScope,
                    sharedScope
                    );

            x.CopyLinkedValues();
            x.Put("constructor", f.Env.Constructors.Object);
            x.Put("length", length, DescriptorAttrs.DontEnum);
            x.Put("callee", f, DescriptorAttrs.DontEnum);

            for (var i = 0; i < extraArgs.Length; ++i)
                x.Put((uint)(i + namedArgsPassed), extraArgs[i]);

            return x;
        }