public ObjectInstance Construct(JsValue[] arguments) { var instance = new ArrayInstance(Engine); instance.Prototype = PrototypeObject; instance.Extensible = true; if (arguments.Length == 1 && arguments.At(0).IsNumber()) { var length = TypeConverter.ToUint32(arguments[0]); if (TypeConverter.ToNumber(arguments[0]) != length) { throw new JavaScriptException(Engine.RangeError); } instance.FastAddProperty("length", length, true, false, false); } else { instance.FastAddProperty("length", 0, true, false, false); PrototypeObject.Push(instance, arguments); } return(instance); }
public ObjectInstance Construct(JsValue[] arguments) { var instance = new ArrayInstance(Engine); instance.Prototype = PrototypeObject; instance.Extensible = true; if (arguments.Length == 1 && arguments.At(0).IsNumber()) { var length = TypeConverter.ToUint32(arguments.At(0)); if (!TypeConverter.ToNumber(arguments[0]).Equals(length)) { throw new JavaScriptException(Engine.RangeError, "Invalid array length"); } instance.FastAddProperty("length", length, true, false, false); return(instance); } if (arguments.Length == 1) { JsValue a = arguments.At(0); if (a.IsObject()) { var wrapper = a.AsObject() as IObjectWrapper; if (wrapper != null) { var enumerable = wrapper.Target as IEnumerable; if (enumerable != null) { var jsArray = Engine.Array.Construct(Arguments.Empty); foreach (object item in enumerable) { var jsItem = JsValue.FromObject(Engine, item); Engine.Array.PrototypeObject.Push(jsArray, Arguments.From(jsItem)); } return(jsArray); } } } } instance.FastAddProperty("length", 0, true, false, false); PrototypeObject.Push(instance, arguments); return(instance); }
public ObjectInstance Construct(JsValue[] arguments) { var instance = new ArrayInstance(Engine); instance.Prototype = PrototypeObject; instance.Extensible = true; if (arguments.Length == 1 && arguments.At(0).IsNumber()) { var length = TypeConverter.ToUint32(arguments.At(0)); if (!TypeConverter.ToNumber(arguments[0]).Equals(length)) { throw new JavaScriptException(Engine.RangeError, "Invalid array length"); } instance.FastAddProperty("length", length, true, false, false); } else if (arguments.Length == 1 && arguments.At(0).IsObject() && arguments.At(0).As<ObjectWrapper>() != null) { var enumerable = arguments.At(0).As<ObjectWrapper>().Target as IEnumerable; if (enumerable != null) { var jsArray = Engine.Array.Construct(Arguments.Empty); foreach (var item in enumerable) { var jsItem = JsValue.FromObject(Engine, item); Engine.Array.PrototypeObject.Push(jsArray, Arguments.From(jsItem)); } return jsArray; } } else { instance.FastAddProperty("length", 0, true, false, false); PrototypeObject.Push(instance, arguments); } return instance; }