123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- using System;
- using Jint.Native.Object;
- using Jint.Runtime;
- using Jint.Runtime.Interop;
- namespace Jint.Native.Array
- {
- /// <summary>
- /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4
- /// </summary>
- 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<object, object>(Engine, ToArrayString), false, false, false);
- FastAddProperty("toLocaleString", new ClrFunctionInstance<object, object>(Engine, ToLocaleString), false, false, false);
- FastAddProperty("concat", new ClrFunctionInstance<object, object>(Engine, Concat), false, false, false);
- FastAddProperty("join", new ClrFunctionInstance<object, object>(Engine, Join), false, false, false);
- FastAddProperty("pop", new ClrFunctionInstance<ArrayInstance, object>(Engine, Pop), false, false, false);
- FastAddProperty("push", new ClrFunctionInstance<ArrayInstance, object>(Engine, Push), false, false, false);
- FastAddProperty("reverse", new ClrFunctionInstance<object, object>(Engine, Reverse), false, false, false);
- FastAddProperty("shift", new ClrFunctionInstance<ArrayInstance, object>(Engine, Shift), false, false, false);
- FastAddProperty("slice", new ClrFunctionInstance<ArrayInstance, object>(Engine, Slice), false, false, false);
- FastAddProperty("sort", new ClrFunctionInstance<ArrayInstance, object>(Engine, Sort), false, false, false);
- FastAddProperty("splice", new ClrFunctionInstance<ArrayInstance, object>(Engine, Splice), false, false, false);
- FastAddProperty("unshift", new ClrFunctionInstance<ArrayInstance, object>(Engine, Unshift), false, false, false);
- FastAddProperty("indexOf", new ClrFunctionInstance<ArrayInstance, object>(Engine, IndexOf), false, false, false);
- FastAddProperty("lastIndexOf", new ClrFunctionInstance<ArrayInstance, object>(Engine, LastIndexOf), false, false, false);
- FastAddProperty("every", new ClrFunctionInstance<ArrayInstance, object>(Engine, Every), false, false, false);
- FastAddProperty("some", new ClrFunctionInstance<ArrayInstance, object>(Engine, Some), false, false, false);
- FastAddProperty("forEach", new ClrFunctionInstance<ArrayInstance, object>(Engine, ForEach), false, false, false);
- FastAddProperty("map", new ClrFunctionInstance<ArrayInstance, object>(Engine, Map), false, false, false);
- FastAddProperty("filter", new ClrFunctionInstance<ArrayInstance, object>(Engine, Filter), false, false, false);
- FastAddProperty("reduce", new ClrFunctionInstance<ArrayInstance, object>(Engine, Reduce), false, false, false);
- FastAddProperty("reduceRight", new ClrFunctionInstance<ArrayInstance, object>(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;
- }
- }
- }
- }
|