public static EcmaValue Find([This] EcmaValue thisValue, EcmaValue predicate, EcmaValue thisArg) { TypedArray array = thisValue.GetUnderlyingObject <TypedArray>(); Guard.BufferNotDetached(array); Guard.ArgumentIsCallable(predicate); for (int i = 0, length = array.Length; i < length; i++) { EcmaValue value = array.GetValueFromBuffer(i); if (predicate.Call(thisArg, value, i, thisValue)) { return(value); } } return(default);
public static EcmaValue Every([This] EcmaValue thisValue, EcmaValue callback, EcmaValue thisArg) { TypedArray array = thisValue.GetUnderlyingObject <TypedArray>(); Guard.BufferNotDetached(array); Guard.ArgumentIsCallable(callback); for (int i = 0, len = array.Length; i < len; i++) { Guard.BufferNotDetached(array); EcmaValue value = array.GetValueFromBuffer(i); if (!(bool)callback.Call(thisArg, value, i, thisValue)) { return(false); } } return(true); }
public static EcmaValue Filter([This] EcmaValue thisValue, EcmaValue callback, EcmaValue thisArg) { TypedArray array = thisValue.GetUnderlyingObject <TypedArray>(); Guard.BufferNotDetached(array); Guard.ArgumentIsCallable(callback); List <EcmaValue> filtered = new List <EcmaValue>(); for (int i = 0, length = array.Length; i < length; i++) { EcmaValue value = array.GetValueFromBuffer(i); if (callback.Call(thisArg, value, i, thisValue)) { filtered.Add(value); } } TypedArray target = TypedArray.SpeciesCreate(array, filtered.Count); for (int i = 0; i < filtered.Count; i++) { target.SetOrThrow(i, filtered[i]); } return(target); }