public override void Put(string name, BoxedValue value) { if (name == "length") { this.PutLength(TypeConverter.ToNumber(value)); this.SetAttrs("length", DescriptorAttrs.DontEnum); //TODO: Shouldn't `PutLength` keep the `DontEnum` flag? return; } uint index; if (TypeConverter.TryToIndex(name, out index)) //TODO: I changed this to use TryToIndex, but that forgoes checking that `index.ToString() == name`, which may be necessary. { this.Put(index, value); return; } base.Put(name, value); }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var item = this.Find(binder.Name); if (item.HasValue) { var box = item.Value; if (box.IsFunction) { var func = box.Func; var boxedArgs = args.Select(a => BoxedValue.Box(a)).ToArray(); var ret = func.Call(this, boxedArgs); result = ret.UnboxObject(); return(true); } } result = null; return(false); }
public static BoxedValue Box(object value) { if (value is double) { return(Box((double)value)); } if (value is int) { return(Box((int)value)); } if (value is bool) { return(Box((bool)value)); } if (value is string) { return(Box((string)value)); } if (value is SuffixString) { return(Box((SuffixString)value)); } if (value is FunctionObject) { return(Box((FunctionObject)value)); } if (value is CommonObject) { return(Box((CommonObject)value)); } if (value is Undefined) { return(Box((Undefined)value)); } var box = new BoxedValue(); box.Clr = value; box.Tag = TypeTags.Clr; return(box); }
/// <summary> /// Puts the <paramref name="value"/> at the specified <paramref name="index"/>. /// </summary> /// <param name="index">The index.</param> /// <param name="value">The value.</param> public override void Put(uint index, BoxedValue value) { var ii = (int)index; if (LinkIntact && ii < LinkMap.Length) { var link = LinkMap[ii]; switch (link.Item1) { case ParameterStorageType.Private: PrivateScope[link.Item2] = value; break; case ParameterStorageType.Shared: SharedScope[link.Item2] = value; break; } } base.Put(index, value); }
public static BoxedValue JsBox(object o) { if (o is BoxedValue) { return((BoxedValue)o); } if (o == null) { return(Environment.BoxedNull); } var tag = TypeTag.OfType(o.GetType()); switch (tag) { case TypeTags.Bool: return(BoxedValue.Box((bool)o)); case TypeTags.Number: return(BoxedValue.Box((double)o)); default: return(BoxedValue.Box(o, tag)); } }
public static object ToClrObject(BoxedValue v) { switch (v.Tag) { case TypeTags.Undefined: return(null); case TypeTags.Bool: return(v.Bool); case TypeTags.Object: case TypeTags.Function: case TypeTags.String: case TypeTags.Clr: return(v.Clr); case TypeTags.SuffixString: return(v.Clr.ToString()); default: return(v.Number); } }
//---------------------------------------------------------------------------- public virtual void Put(uint index, BoxedValue value) { this.Put(index.ToString(), value); }
public static int ToInteger(BoxedValue b) { return(ToInteger(ToNumber(b))); }
public static ushort ToUInt16(BoxedValue b) { return((ushort)(uint)ToNumber(b)); }
public static BoxedValue ToBoxedValue(bool b) { return(BoxedValue.Box(b)); }
static Undefined() { instance = new Undefined(); boxed = BoxedValue.Box(instance, TypeTags.Undefined); }
public void Put(Undefined index, BoxedValue value) { this.Put("undefined", value); }
public static BoxedValue ToBoxedValue(FunctionObject f) { return(BoxedValue.Box(f)); }
public static BoxedValue ToBoxedValue(CommonObject o) { return(BoxedValue.Box(o)); }
public static BoxedValue ToBoxedValue(SuffixString s) { return(BoxedValue.Box(s)); }
public static BoxedValue ToPrimitive(BoxedValue v) { return(ToPrimitive(v, DefaultValueHint.None)); }
public static BoxedValue ToPrimitive(string s, DefaultValueHint hint) { return(BoxedValue.Box(s)); }
public static BoxedValue ToPrimitive(double d, DefaultValueHint hint) { return(BoxedValue.Box(d)); }
public static BoxedValue ToPrimitive(bool b, DefaultValueHint hint) { return(BoxedValue.Box(b)); }
public void Put(string name, BoxedValue value, ushort attrs) { this.Put(name, value); this.SetAttrs(name, attrs); }
public void Put(bool index, BoxedValue value) { this.Put(TypeConverter.ToString(index), value); }
public override void Put(uint index, double value) { this.Put(index, BoxedValue.Box(value)); }
public static BoxedValue ToBoxedValue(BoxedValue v) { return(v); }
public void Put(uint index, BoxedValue value) { this.storage[index] = value; }
public static BoxedValue ToBoxedValue(object c) { return(BoxedValue.Box(c)); }
public static BoxedValue ToBoxedValue(double d) { return(BoxedValue.Box(d)); }
public override void Put(uint index, object value, uint tag) { this.Put(index, BoxedValue.Box(value, tag)); }
public static int ToInt32(BoxedValue b) { return((int)(uint)ToNumber(b)); }
public bool TryGet(uint index, out BoxedValue value) { return(this.storage.TryGetValue(index, out value)); }
public static uint ToUInt32(BoxedValue b) { return((uint)ToNumber(b)); }