Esempio 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);
        }
Esempio 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);
        }
Esempio n. 3
0
        public static BoxedValue Box(FunctionObject value)
        {
            var box = new BoxedValue();

            box.Clr = value;
            box.Tag = TypeTags.Function;
            return(box);
        }
Esempio n. 4
0
        public FunctionObject NewFunction(ulong id, int args, BoxedValue[] closureScope, FSharpList <Tuple <int, CommonObject> > dynamicScope)
        {
            FunctionObject func  = new FunctionObject(this, id, closureScope, dynamicScope);
            CommonObject   proto = this.NewPrototype();

            proto.Put("constructor", func, 2);
            func.Put("prototype", proto, 4);
            func.Put("length", (double)args, 7);
            return(func);
        }
Esempio n. 5
0
        public Delegate GetDelegate(FunctionObject function, Type delegateType)
        {
            Delegate compiled;

            if (!delegateCache.TryGetValue(delegateType, out compiled))
            {
                delegateCache[delegateType] = compiled = Compiler(function, delegateType);
            }

            return(compiled);
        }
Esempio n. 6
0
 public void Put(string name, FunctionObject value, ushort attrs)
 {
     this.Put(name, value);
     this.SetAttrs(name, attrs);
 }
Esempio n. 7
0
 public void Put(uint index, FunctionObject value)
 {
     this.Put(index, value, TypeTags.Function);
 }
Esempio n. 8
0
 public void Put(string name, FunctionObject value)
 {
     this.Put(name, value, TypeTags.Function);
 }
Esempio n. 9
0
 public static object ToClrObject(FunctionObject f)
 {
     return(f);
 }
Esempio n. 10
0
 public static double ToNumber(FunctionObject f)
 {
     return(ToNumber(f.DefaultValue(DefaultValueHint.Number)));
 }
Esempio n. 11
0
 public static BoxedValue ToBoxedValue(FunctionObject f)
 {
     return(BoxedValue.Box(f));
 }
Esempio n. 12
0
 public static CommonObject ToObject(Environment env, FunctionObject f)
 {
     return(f);
 }
Esempio n. 13
0
 public T GetDelegate <T>(FunctionObject function) where T : class
 {
     return((T)(object)GetDelegate(function, typeof(T)));
 }