/// <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); }
/// <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); }
public static BoxedValue Box(FunctionObject value) { var box = new BoxedValue(); box.Clr = value; box.Tag = TypeTags.Function; return(box); }
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); }
public Delegate GetDelegate(FunctionObject function, Type delegateType) { Delegate compiled; if (!delegateCache.TryGetValue(delegateType, out compiled)) { delegateCache[delegateType] = compiled = Compiler(function, delegateType); } return(compiled); }
public void Put(string name, FunctionObject value, ushort attrs) { this.Put(name, value); this.SetAttrs(name, attrs); }
public void Put(uint index, FunctionObject value) { this.Put(index, value, TypeTags.Function); }
public void Put(string name, FunctionObject value) { this.Put(name, value, TypeTags.Function); }
public static object ToClrObject(FunctionObject f) { return(f); }
public static double ToNumber(FunctionObject f) { return(ToNumber(f.DefaultValue(DefaultValueHint.Number))); }
public static BoxedValue ToBoxedValue(FunctionObject f) { return(BoxedValue.Box(f)); }
public static CommonObject ToObject(Environment env, FunctionObject f) { return(f); }
public T GetDelegate <T>(FunctionObject function) where T : class { return((T)(object)GetDelegate(function, typeof(T))); }