using System; using Jint.Native.Object; using Jint.Runtime; using Jint.Runtime.Interop; namespace Jint.Native.Array { /// /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4 /// public sealed class ArrayPrototype : ObjectInstance { private ArrayPrototype(Engine engine) : base(engine) { } public static ArrayPrototype CreatePrototypeObject(Engine engine, ArrayConstructor arrayConstructor) { var obj = new ArrayPrototype(engine) {Extensible = true}; obj.FastAddProperty("constructor", arrayConstructor, false, false, false); return obj; } public void Configure() { FastAddProperty("toString", new ClrFunctionInstance(Engine, ToArrayString), false, false, false); FastAddProperty("toLocaleString", new ClrFunctionInstance(Engine, ToLocaleString), false, false, false); FastAddProperty("concat", new ClrFunctionInstance(Engine, Concat), false, false, false); FastAddProperty("join", new ClrFunctionInstance(Engine, Join), false, false, false); FastAddProperty("pop", new ClrFunctionInstance(Engine, Pop), false, false, false); FastAddProperty("push", new ClrFunctionInstance(Engine, Push), false, false, false); FastAddProperty("reverse", new ClrFunctionInstance(Engine, Reverse), false, false, false); FastAddProperty("shift", new ClrFunctionInstance(Engine, Shift), false, false, false); FastAddProperty("slice", new ClrFunctionInstance(Engine, Slice), false, false, false); FastAddProperty("sort", new ClrFunctionInstance(Engine, Sort), false, false, false); FastAddProperty("splice", new ClrFunctionInstance(Engine, Splice), false, false, false); FastAddProperty("unshift", new ClrFunctionInstance(Engine, Unshift), false, false, false); FastAddProperty("indexOf", new ClrFunctionInstance(Engine, IndexOf), false, false, false); FastAddProperty("lastIndexOf", new ClrFunctionInstance(Engine, LastIndexOf), false, false, false); FastAddProperty("every", new ClrFunctionInstance(Engine, Every), false, false, false); FastAddProperty("some", new ClrFunctionInstance(Engine, Some), false, false, false); FastAddProperty("forEach", new ClrFunctionInstance(Engine, ForEach), false, false, false); FastAddProperty("map", new ClrFunctionInstance(Engine, Map), false, false, false); FastAddProperty("filter", new ClrFunctionInstance(Engine, Filter), false, false, false); FastAddProperty("reduce", new ClrFunctionInstance(Engine, Reduce), false, false, false); FastAddProperty("reduceRight", new ClrFunctionInstance(Engine, ReduceRight), false, false, false); } private object LastIndexOf(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Reduce(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Filter(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Map(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object ForEach(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Some(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Every(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object IndexOf(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Splice(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Unshift(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Sort(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Slice(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Shift(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } private object Reverse(object arg1, object[] arg2) { throw new NotImplementedException(); } private object Join(object arg1, object[] arg2) { throw new NotImplementedException(); } private object ToLocaleString(object arg1, object[] arg2) { throw new NotImplementedException(); } private object Concat(object arg1, object[] arg2) { throw new NotImplementedException(); } private object ToArrayString(object arg1, object[] arg2) { throw new NotImplementedException(); } private object ReduceRight(ArrayInstance arg1, object[] arg2) { throw new NotImplementedException(); } public object Push(object thisObject, object[] arguments) { ObjectInstance o = TypeConverter.ToObject(Engine, thisObject); object lenVal = o.Get("length"); uint n = TypeConverter.ToUint32(lenVal); foreach (object e in arguments) { o.Put(TypeConverter.ToString(n), e, true); n++; } o.Put("length", n, true); return n; } public object Pop(object thisObject, object[] arguments) { ObjectInstance o = TypeConverter.ToObject(Engine, thisObject); object lenVal = o.Get("length"); uint len = TypeConverter.ToUint32(lenVal); if (len == 0) { o.Put("length", 0, true); return Undefined.Instance; } else { string indx = TypeConverter.ToString(len - 1); object element = o.Get(indx); o.Delete(indx, true); o.Put("length", indx, true); return element; } } } }