diff options
Diffstat (limited to 'deps/v8/src/builtins/typed-array-reduceright.tq')
-rw-r--r-- | deps/v8/src/builtins/typed-array-reduceright.tq | 104 |
1 files changed, 50 insertions, 54 deletions
diff --git a/deps/v8/src/builtins/typed-array-reduceright.tq b/deps/v8/src/builtins/typed-array-reduceright.tq index ab334a1b866..9ba2f70de4e 100644 --- a/deps/v8/src/builtins/typed-array-reduceright.tq +++ b/deps/v8/src/builtins/typed-array-reduceright.tq @@ -5,69 +5,65 @@ #include 'src/builtins/builtins-typed-array-gen.h' namespace typed_array { - const kBuiltinNameReduceRight: constexpr string = - '%TypedArray%.prototype.reduceRight'; +const kBuiltinNameReduceRight: constexpr string = + '%TypedArray%.prototype.reduceRight'; - transitioning macro ReduceRightAllElements(implicit context: Context)( - array: typed_array::AttachedJSTypedArray, callbackfn: Callable, - initialValue: JSAny|TheHole): JSAny { - let witness = typed_array::NewAttachedJSTypedArrayWitness(array); - const length: uintptr = witness.Get().length; - let accumulator = initialValue; - for (let k: uintptr = length; k-- > 0;) { - // BUG(4895): We should throw on detached buffers rather than simply exit. - witness.Recheck() otherwise break; - const value: JSAny = witness.Load(k); - typeswitch (accumulator) { - case (TheHole): { - accumulator = value; - } - case (accumulatorNotHole: JSAny): { - // TODO(v8:4153): Consider versioning this loop for Smi and non-Smi - // indices to optimize Convert<Number>(k) for the most common case. - accumulator = Call( - context, callbackfn, Undefined, accumulatorNotHole, value, - Convert<Number>(k), witness.GetStable()); - } - } - } +transitioning macro ReduceRightAllElements(implicit context: Context)( + array: typed_array::AttachedJSTypedArray, callbackfn: Callable, + initialValue: JSAny|TheHole): JSAny { + let witness = typed_array::NewAttachedJSTypedArrayWitness(array); + const length: uintptr = witness.Get().length; + let accumulator = initialValue; + for (let k: uintptr = length; k-- > 0;) { + // BUG(4895): We should throw on detached buffers rather than simply exit. + witness.Recheck() otherwise break; + const value: JSAny = witness.Load(k); typeswitch (accumulator) { case (TheHole): { - ThrowTypeError( - MessageTemplate::kReduceNoInitial, kBuiltinNameReduceRight); + accumulator = value; } - case (accumulator: JSAny): { - return accumulator; + case (accumulatorNotHole: JSAny): { + // TODO(v8:4153): Consider versioning this loop for Smi and non-Smi + // indices to optimize Convert<Number>(k) for the most common case. + accumulator = Call( + context, callbackfn, Undefined, accumulatorNotHole, value, + Convert<Number>(k), witness.GetStable()); } } } + typeswitch (accumulator) { + case (TheHole): { + ThrowTypeError( + MessageTemplate::kReduceNoInitial, kBuiltinNameReduceRight); + } + case (accumulator: JSAny): { + return accumulator; + } + } +} - // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reduceright - transitioning javascript builtin - TypedArrayPrototypeReduceRight( - js-implicit context: NativeContext, - receiver: JSAny)(...arguments): JSAny { - // arguments[0] = callback - // arguments[1] = initialValue. - try { - const array: JSTypedArray = Cast<JSTypedArray>(receiver) - otherwise NotTypedArray; - const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; +// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reduceright +transitioning javascript builtin +TypedArrayPrototypeReduceRight( + js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny { + // arguments[0] = callback + // arguments[1] = initialValue. + 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 initialValue = arguments.length >= 2 ? arguments[1] : TheHole; + const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable; + const initialValue = arguments.length >= 2 ? arguments[1] : TheHole; - return ReduceRightAllElements(uarray, callbackfn, initialValue); - } - label NotCallable deferred { - ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); - } - label NotTypedArray deferred { - ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduceRight); - } - label IsDetached deferred { - ThrowTypeError( - MessageTemplate::kDetachedOperation, kBuiltinNameReduceRight); - } + return ReduceRightAllElements(uarray, callbackfn, initialValue); + } label NotCallable deferred { + ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); + } label NotTypedArray deferred { + ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduceRight); + } label IsDetached deferred { + ThrowTypeError( + MessageTemplate::kDetachedOperation, kBuiltinNameReduceRight); } } +} |