diff options
Diffstat (limited to 'deps/v8/src/builtins/typed-array-foreach.tq')
-rw-r--r-- | deps/v8/src/builtins/typed-array-foreach.tq | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/deps/v8/src/builtins/typed-array-foreach.tq b/deps/v8/src/builtins/typed-array-foreach.tq index dd134174568..d696d9c8dd8 100644 --- a/deps/v8/src/builtins/typed-array-foreach.tq +++ b/deps/v8/src/builtins/typed-array-foreach.tq @@ -5,52 +5,47 @@ #include 'src/builtins/builtins-typed-array-gen.h' namespace typed_array { - const kBuiltinNameForEach: constexpr string = - '%TypedArray%.prototype.forEach'; +const kBuiltinNameForEach: constexpr string = '%TypedArray%.prototype.forEach'; - transitioning macro ForEachAllElements(implicit context: Context)( - array: typed_array::AttachedJSTypedArray, callbackfn: Callable, - thisArg: JSAny): Undefined { - let witness = typed_array::NewAttachedJSTypedArrayWitness(array); - const length: uintptr = witness.Get().length; - for (let k: uintptr = 0; k < length; k++) { - // BUG(4895): We should throw on detached buffers rather than simply exit. - witness.Recheck() otherwise break; - const value: JSAny = witness.Load(k); - // TODO(v8:4153): Consider versioning this loop for Smi and non-Smi - // indices to optimize Convert<Number>(k) for the most common case. - Call( - context, callbackfn, thisArg, value, Convert<Number>(k), - witness.GetStable()); - } - return Undefined; +transitioning macro ForEachAllElements(implicit context: Context)( + array: typed_array::AttachedJSTypedArray, callbackfn: Callable, + thisArg: JSAny): Undefined { + let witness = typed_array::NewAttachedJSTypedArrayWitness(array); + const length: uintptr = witness.Get().length; + for (let k: uintptr = 0; k < length; k++) { + // BUG(4895): We should throw on detached buffers rather than simply exit. + witness.Recheck() otherwise break; + const value: JSAny = witness.Load(k); + // TODO(v8:4153): Consider versioning this loop for Smi and non-Smi + // indices to optimize Convert<Number>(k) for the most common case. + Call( + context, callbackfn, thisArg, value, Convert<Number>(k), + witness.GetStable()); } + return Undefined; +} - // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.every - transitioning javascript builtin - TypedArrayPrototypeForEach( - js-implicit context: NativeContext, - receiver: JSAny)(...arguments): Undefined { - // arguments[0] = callback - // arguments[1] = this_arg. +// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.every +transitioning javascript builtin +TypedArrayPrototypeForEach(js-implicit context: NativeContext, receiver: JSAny)( + ...arguments): Undefined { + // arguments[0] = callback + // arguments[1] = this_arg. - try { - const array: JSTypedArray = Cast<JSTypedArray>(receiver) - otherwise NotTypedArray; - const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; + try { + const array: JSTypedArray = Cast<JSTypedArray>(receiver) + otherwise NotTypedArray; + const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; - const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable; - const thisArg = arguments[1]; - return ForEachAllElements(uarray, callbackfn, thisArg); - } - label NotCallable deferred { - ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); - } - label NotTypedArray deferred { - ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameForEach); - } - label IsDetached deferred { - ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameForEach); - } + const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable; + const thisArg = arguments[1]; + return ForEachAllElements(uarray, callbackfn, thisArg); + } label NotCallable deferred { + ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); + } label NotTypedArray deferred { + ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameForEach); + } label IsDetached deferred { + ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameForEach); } } +} |