public static EcmaValue Fill([This] EcmaValue thisValue, EcmaValue value, EcmaValue start, EcmaValue end) { TypedArray array = thisValue.GetUnderlyingObject <TypedArray>(); Guard.BufferNotDetached(array); value = value.ToNumber(); int len = array.Length; int from = ArrayHelper.GetBoundIndex(start, len, 0); int until = ArrayHelper.GetBoundIndex(end, len, len); Guard.BufferNotDetached(array); for (int i = from; i < until; i++) { array.SetOrThrow(i, value); } return(thisValue); }
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); }