public BoxedValue Call(CommonObject @this, BoxedValue[] args) { return (MetaData .GetDelegate <Func <FunctionObject, CommonObject, BoxedValue[], BoxedValue> >(this) .Invoke(this, @this, args)); }
public CommonObject(Environment env, CommonObject prototype) { this.Env = env; this.Prototype = prototype; this.PropertySchema = env.Maps.Base; this.Properties = new Descriptor[env.Maps.Base.IndexMap.Count]; }
public CommonObject(Environment env, Schema map, CommonObject prototype) { this.Env = env; this.Prototype = prototype; this.PropertySchema = map; this.Properties = new Descriptor[map.IndexMap.Count]; }
public CommonObject NewInstance() { CommonObject o = Env.NewObject(); o.Prototype = InstancePrototype; return(o); }
public BoxedValue Call <T0, T1, T2, T3>(CommonObject @this, T0 a0, T1 a1, T2 a2, T3 a3) { return (MetaData .GetDelegate <Func <FunctionObject, CommonObject, T0, T1, T2, T3, BoxedValue> >(this) .Invoke(this, @this, a0, a1, a2, a3)); }
public BoxedValue Call <T0>(CommonObject @this, T0 a0) { return (MetaData .GetDelegate <Func <FunctionObject, CommonObject, T0, BoxedValue> >(this) .Invoke(this, @this, a0)); }
internal CommonObject(Environment env) { this.Env = env; this.Prototype = null; this.PropertySchema = null; this.Properties = null; }
public static string ToString(CommonObject o) { var s = o as StringObject; return(s != null ? s.Value.Value.String : ToString(o.DefaultValue(DefaultValueHint.String))); }
public static BoxedValue Box(CommonObject value) { var box = new BoxedValue(); box.Clr = value; box.Tag = TypeTags.Object; return(box); }
public static double ToNumber(CommonObject o) { var n = o as NumberObject; return(n != null ? n.Value.Value.Number : ToNumber(o.DefaultValue(DefaultValueHint.Number))); }
public T RaiseError <T>(CommonObject prototype, string message) { ErrorObject error = new ErrorObject(this) { Prototype = prototype }; error.Put("message", message); throw new UserError(BoxedValue.Box((CommonObject)error), 0, 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); }
public bool Has(CommonObject index) { string s = TypeConverter.ToString(index); uint parsed = 0; if (TypeConverter.TryToIndex(s, out parsed)) { return(this.Has(parsed)); } return(this.Has(s)); }
public BoxedValue PickReturnObject(BoxedValue r, CommonObject o) { switch (r.Tag) { case TypeTags.Function: return(BoxedValue.Box(r.Func)); case TypeTags.Object: return(BoxedValue.Box(r.Object)); default: return(BoxedValue.Box(o)); } }
public bool Delete(CommonObject index) { string name = TypeConverter.ToString(index); uint parsed = 0; if (TypeConverter.TryToIndex(name, out parsed)) { return(this.Delete(parsed)); } return(this.Delete(name)); }
public BoxedValue Get(CommonObject index) { string s = TypeConverter.ToString(index); uint parsed = 0; if (TypeConverter.TryToIndex(s, out parsed)) { return(this.Get(parsed)); } return(this.Get(s)); }
public static BoxedValue GetValue(CommonObject o) { var vo = o as ValueObject; if (vo == null) { return(o.Env.RaiseTypeError <BoxedValue>("Cannot read the value of a non-value object.")); } return(vo.Value.Value); }
public static BoxedValue Box(CommonObject value) { if (value == null) { return(Environment.BoxedNull); } var box = new BoxedValue(); box.Clr = value; box.Tag = TypeTags.Object; return(box); }
public void Put(CommonObject index, object value, uint tag) { string s = TypeConverter.ToString(index); uint parsed = 0; if (TypeConverter.TryToIndex(s, out parsed)) { this.Put(parsed, value, tag); } else { this.Put(s, value, tag); } }
private static Descriptor Find(CommonObject @this, string name) { while (@this != null) { int index; if (@this.PropertySchema.IndexMap.TryGetValue(name, out index)) { return(@this.Properties[index]); } @this = @this.Prototype; } return(new Descriptor()); }
public bool HasInstance(CommonObject v) { var o = Get("prototype"); if (!o.IsObject) { return(Env.RaiseTypeError <bool>("prototype property is not an object")); } v = (v != null) ? v.Prototype : null; while (v != null) { if (Object.ReferenceEquals(o.Object, v)) { return(true); } v = v.Prototype; } return(false); }
public static BoxedValue ToBoxedValue(CommonObject o) { return(BoxedValue.Box(o)); }
public void Put(string name, CommonObject value, ushort attrs) { this.Put(name, value); this.SetAttrs(name, attrs); }
public void Put(uint index, CommonObject value) { this.Put(index, value, TypeTags.Object); }
public void Put(string name, CommonObject value) { this.Put(name, value, TypeTags.Object); }
public static CommonObject ToObject(Environment env, CommonObject o) { return(o); }
public static bool ToBoolean(CommonObject o) { return(true); }
public static BoxedValue ToPrimitive(CommonObject o, DefaultValueHint hint) { return(o.DefaultValue(hint)); }
private Tuple <uint, HashSet <string> > collectProperties(uint length, HashSet <string> set, CommonObject current) { if (current != null) { var array = current as ArrayObject; if (array != null) { length = length < array.Length ? array.Length : length; } foreach (var pair in current.PropertySchema.IndexMap) { var descriptor = current.Properties[pair.Value]; if (descriptor.HasValue && descriptor.IsEnumerable) { set.Add(pair.Key); } } return(collectProperties(length, set, current.Prototype)); } else { return(Tuple.Create(length, set)); } }
public static object ToClrObject(CommonObject o) { return(o); }