|
@@ -46,7 +46,7 @@ namespace Jint.Native.Array
|
|
|
FastAddProperty("splice", new ClrFunctionInstance<object, ObjectInstance>(Engine, Splice, 2), true, false, true);
|
|
|
FastAddProperty("unshift", new ClrFunctionInstance<object, uint>(Engine, Unshift, 1), true, false, true);
|
|
|
FastAddProperty("indexOf", new ClrFunctionInstance<object, int>(Engine, IndexOf, 1), true, false, true);
|
|
|
- FastAddProperty("lastIndexOf", new ClrFunctionInstance<ArrayInstance, object>(Engine, LastIndexOf), true, false, true);
|
|
|
+ FastAddProperty("lastIndexOf", new ClrFunctionInstance<object, int>(Engine, LastIndexOf, 1), true, false, true);
|
|
|
FastAddProperty("every", new ClrFunctionInstance<ArrayInstance, object>(Engine, Every), true, false, true);
|
|
|
FastAddProperty("some", new ClrFunctionInstance<ArrayInstance, object>(Engine, Some), true, false, true);
|
|
|
FastAddProperty("forEach", new ClrFunctionInstance<ArrayInstance, object>(Engine, ForEach), true, false, true);
|
|
@@ -56,9 +56,42 @@ namespace Jint.Native.Array
|
|
|
FastAddProperty("reduceRight", new ClrFunctionInstance<ArrayInstance, object>(Engine, ReduceRight), true, false, true);
|
|
|
}
|
|
|
|
|
|
- private object LastIndexOf(ArrayInstance arg1, object[] arg2)
|
|
|
+ private int LastIndexOf(object thisObj, object[] arguments)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ var o = TypeConverter.ToObject(Engine, thisObj);
|
|
|
+ var lenValue = o.Get("length");
|
|
|
+ var len = TypeConverter.ToUint32(lenValue);
|
|
|
+ if (len == 0)
|
|
|
+ {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ var n = arguments.Length > 1 ? (int)TypeConverter.ToInteger(arguments[1]) : (int)len - 1;
|
|
|
+ int k;
|
|
|
+ if (n >= 0)
|
|
|
+ {
|
|
|
+ k = System.Math.Min(n, (int)len - 1); // min
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ k = (int)len - System.Math.Abs(n);
|
|
|
+ }
|
|
|
+ var searchElement = arguments.Length > 0 ? arguments[0] : Undefined.Instance;
|
|
|
+ for (; k > 0; k--)
|
|
|
+ {
|
|
|
+ var kString = TypeConverter.ToString(k);
|
|
|
+ var kPresent = o.HasProperty(kString);
|
|
|
+ if (kPresent)
|
|
|
+ {
|
|
|
+ var elementK = o.Get(kString);
|
|
|
+ var same = ExpressionInterpreter.StriclyEqual(elementK, searchElement);
|
|
|
+ if (same)
|
|
|
+ {
|
|
|
+ return k;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
private object Reduce(ArrayInstance arg1, object[] arg2)
|