|
@@ -1,5 +1,7 @@
|
|
-using Jint.Native.Function;
|
|
|
|
|
|
+using System.Linq;
|
|
|
|
+using Jint.Native.Function;
|
|
using Jint.Native.Object;
|
|
using Jint.Native.Object;
|
|
|
|
+using Jint.Runtime;
|
|
using Jint.Runtime.Descriptors;
|
|
using Jint.Runtime.Descriptors;
|
|
using Jint.Runtime.Descriptors.Specialized;
|
|
using Jint.Runtime.Descriptors.Specialized;
|
|
|
|
|
|
@@ -17,9 +19,6 @@ namespace Jint.Native.Array
|
|
Prototype.DefineOwnProperty("constructor", new DataDescriptor(this) { Writable = true, Enumerable = false, Configurable = false }, false);
|
|
Prototype.DefineOwnProperty("constructor", new DataDescriptor(this) { Writable = true, Enumerable = false, Configurable = false }, false);
|
|
Prototype.DefineOwnProperty("prototype", new DataDescriptor(Prototype) { Writable = true, Enumerable = false, Configurable = false }, false);
|
|
Prototype.DefineOwnProperty("prototype", new DataDescriptor(Prototype) { Writable = true, Enumerable = false, Configurable = false }, false);
|
|
|
|
|
|
- // Array prototype properties
|
|
|
|
- Prototype.DefineOwnProperty("length", new ClrAccessDescriptor<ArrayInstance>(_engine, x => x.Length), false);
|
|
|
|
-
|
|
|
|
// Array prototype functions
|
|
// Array prototype functions
|
|
Prototype.DefineOwnProperty("push", new ClrDataDescriptor<ArrayInstance, object>(engine, Push), false);
|
|
Prototype.DefineOwnProperty("push", new ClrDataDescriptor<ArrayInstance, object>(engine, Push), false);
|
|
Prototype.DefineOwnProperty("pop", new ClrDataDescriptor<ArrayInstance, object>(engine, Pop), false);
|
|
Prototype.DefineOwnProperty("pop", new ClrDataDescriptor<ArrayInstance, object>(engine, Pop), false);
|
|
@@ -33,24 +32,45 @@ namespace Jint.Native.Array
|
|
public ObjectInstance Construct(object[] arguments)
|
|
public ObjectInstance Construct(object[] arguments)
|
|
{
|
|
{
|
|
var instance = new ArrayInstance(_engine, Prototype);
|
|
var instance = new ArrayInstance(_engine, Prototype);
|
|
-
|
|
|
|
- foreach (var arg in arguments)
|
|
|
|
- {
|
|
|
|
- instance.Push(arg);
|
|
|
|
- }
|
|
|
|
|
|
+ instance.FastAddProperty("length", 0, true, false, true);
|
|
|
|
+ Push(instance, arguments);
|
|
|
|
|
|
return instance;
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
|
|
- private static object Push(ArrayInstance thisObject, object[] arguments)
|
|
|
|
|
|
+ private object Push(object thisObject, object[] arguments)
|
|
{
|
|
{
|
|
- thisObject.Push(arguments[0]);
|
|
|
|
- return arguments[0];
|
|
|
|
|
|
+ var o = TypeConverter.ToObject(_engine, thisObject);
|
|
|
|
+ var lenVal = o.Get("length");
|
|
|
|
+ var n = TypeConverter.ToUint32(lenVal);
|
|
|
|
+ foreach (var e in arguments)
|
|
|
|
+ {
|
|
|
|
+ o.Put(TypeConverter.ToString(n), e, true);
|
|
|
|
+ n++;
|
|
|
|
+ }
|
|
|
|
+ o.Put("length", n, true);
|
|
|
|
+
|
|
|
|
+ return n;
|
|
}
|
|
}
|
|
|
|
|
|
- private static object Pop(ArrayInstance thisObject, object[] arguments)
|
|
|
|
|
|
+ private object Pop(object thisObject, object[] arguments)
|
|
{
|
|
{
|
|
- return thisObject.Pop();
|
|
|
|
|
|
+ var o = TypeConverter.ToObject(_engine, thisObject);
|
|
|
|
+ var lenVal = o.Get("length");
|
|
|
|
+ var len = TypeConverter.ToUint32(lenVal);
|
|
|
|
+ if (len == 0)
|
|
|
|
+ {
|
|
|
|
+ o.Put("length", 0, true);
|
|
|
|
+ return Undefined.Instance;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var indx = TypeConverter.ToString(len - 1);
|
|
|
|
+ var element = o.Get(indx);
|
|
|
|
+ o.Delete(indx, true);
|
|
|
|
+ o.Put("length", indx, true);
|
|
|
|
+ return element;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|