Commit dbf3ab5f authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[rab/gsab] Add RAB / GSAB support to various TA.prototype functions

Functions affected:
filter
find
findIndex
findLast
findLastIndex
forEach
reduce
reduceRight

Bug: v8:11111
Change-Id: Ifb40143e5b6ed4a3eb30cb25332e2387009e3274
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3205421
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77422}
parent 5c1adef7
...@@ -9,13 +9,14 @@ const kBuiltinNameEvery: constexpr string = '%TypedArray%.prototype.every'; ...@@ -9,13 +9,14 @@ const kBuiltinNameEvery: constexpr string = '%TypedArray%.prototype.every';
// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.every // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.every
transitioning macro EveryAllElements(implicit context: Context)( transitioning macro EveryAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, length: uintptr, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
callbackfn: Callable, thisArg: JSAny): Boolean { callbackfn: Callable, thisArg: JSAny): Boolean {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0. // 5. Let k be 0.
// 6. Repeat, while k < len // 6. Repeat, while k < len
for (let k: uintptr = 0; k < length; k++) { for (let k: uintptr = 0; k < attachedArrayAndLength.length; k++) {
// 6a. Let Pk be ! ToString(𝔽(k)). // 6a. Let Pk be ! ToString(𝔽(k)).
// There is no need to cast ToString to load elements. // There is no need to cast ToString to load elements.
...@@ -59,13 +60,12 @@ TypedArrayPrototypeEvery( ...@@ -59,13 +60,12 @@ TypedArrayPrototypeEvery(
// 3. Let len be IntegerIndexedObjectLength(O). // 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
const length = LoadJSTypedArrayLengthAndCheckDetached(array) const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds; otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception. // 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable; const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable;
const thisArg = arguments[1]; const thisArg = arguments[1];
return EveryAllElements( return EveryAllElements(attachedArrayAndLength, callbackfn, thisArg);
%RawDownCast<AttachedJSTypedArray>(array), length, callbackfn, thisArg);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameEvery); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameEvery);
} label IsDetachedOrOutOfBounds deferred { } label IsDetachedOrOutOfBounds deferred {
......
...@@ -13,14 +13,13 @@ transitioning javascript builtin TypedArrayPrototypeFilter( ...@@ -13,14 +13,13 @@ transitioning javascript builtin TypedArrayPrototypeFilter(
try { try {
// 1. Let O be the this value. // 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O). // 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise ThrowTypeError( otherwise ThrowTypeError(
MessageTemplate::kNotTypedArray, kBuiltinNameFilter); MessageTemplate::kNotTypedArray, kBuiltinNameFilter);
const src = typed_array::EnsureAttached(array) otherwise IsDetached;
// 3. Let len be O.[[ArrayLength]].
const len: uintptr = src.length;
const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception. // 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
const callbackfn = Cast<Callable>(arguments[0]) const callbackfn = Cast<Callable>(arguments[0])
otherwise ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); otherwise ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
...@@ -32,19 +31,20 @@ transitioning javascript builtin TypedArrayPrototypeFilter( ...@@ -32,19 +31,20 @@ transitioning javascript builtin TypedArrayPrototypeFilter(
// TODO(v8:4153): Support huge TypedArrays here. (growable fixed arrays // TODO(v8:4153): Support huge TypedArrays here. (growable fixed arrays
// can't be longer than kMaxSmiValue). // can't be longer than kMaxSmiValue).
let kept = growable_fixed_array::NewGrowableFixedArray(); let kept = growable_fixed_array::NewGrowableFixedArray();
let witness = typed_array::NewAttachedJSTypedArrayWitness(src); let witness = typed_array::NewAttachedJSTypedArrayWitness(
attachedArrayAndLength.array);
// 7. Let k be 0. // 7. Let k be 0.
// 8. Let captured be 0. // 8. Let captured be 0.
// 9. Repeat, while k < len // 9. Repeat, while k < len
for (let k: uintptr = 0; k < len; k++) { for (let k: uintptr = 0; k < attachedArrayAndLength.length; k++) {
let value: JSAny; let value: JSAny;
// a. Let Pk be ! ToString(k). // a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk). // b. Let kValue be ? Get(O, Pk).
try { try {
witness.Recheck() otherwise goto IsDetached; witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k); value = witness.Load(k);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
value = Undefined; value = Undefined;
} }
...@@ -80,7 +80,7 @@ transitioning javascript builtin TypedArrayPrototypeFilter( ...@@ -80,7 +80,7 @@ transitioning javascript builtin TypedArrayPrototypeFilter(
// 13. Return A. // 13. Return A.
return typedArray; return typedArray;
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFilter); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFilter);
} }
} }
......
...@@ -9,13 +9,14 @@ const kBuiltinNameFind: constexpr string = '%TypedArray%.prototype.find'; ...@@ -9,13 +9,14 @@ const kBuiltinNameFind: constexpr string = '%TypedArray%.prototype.find';
// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.find // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.find
transitioning macro FindAllElements(implicit context: Context)( transitioning macro FindAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, predicate: Callable, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
thisArg: JSAny): JSAny { predicate: Callable, thisArg: JSAny): JSAny {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
const length: uintptr = witness.Get().length; typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0.
// 6. Repeat, while k < len // 6. Repeat, while k < len
for (let k: uintptr = 0; k < length; k++) { for (let k: uintptr = 0; k < attachedArrayAndLength.length; k++) {
// 6a. Let Pk be ! ToString(𝔽(k)). // 6a. Let Pk be ! ToString(𝔽(k)).
// There is no need to cast ToString to load elements. // There is no need to cast ToString to load elements.
...@@ -23,9 +24,9 @@ transitioning macro FindAllElements(implicit context: Context)( ...@@ -23,9 +24,9 @@ transitioning macro FindAllElements(implicit context: Context)(
// kValue must be undefined when the buffer is detached. // kValue must be undefined when the buffer is detached.
let value: JSAny; let value: JSAny;
try { try {
witness.Recheck() otherwise goto IsDetached; witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k); value = witness.Load(k);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
value = Undefined; value = Undefined;
} }
...@@ -56,18 +57,22 @@ TypedArrayPrototypeFind( ...@@ -56,18 +57,22 @@ TypedArrayPrototypeFind(
// arguments[0] = callback // arguments[0] = callback
// arguments[1] = thisArg // arguments[1] = thisArg
try { try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(predicate) is false, throw a TypeError exception.
const predicate = Cast<Callable>(arguments[0]) otherwise NotCallable; const predicate = Cast<Callable>(arguments[0]) otherwise NotCallable;
const thisArg = arguments[1]; const thisArg = arguments[1];
return FindAllElements(uarray, predicate, thisArg); return FindAllElements(attachedArrayAndLength, predicate, thisArg);
} label NotCallable deferred { } label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFind); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFind);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFind); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFind);
} }
} }
......
...@@ -9,13 +9,14 @@ const kBuiltinNameFindIndex: constexpr string = ...@@ -9,13 +9,14 @@ const kBuiltinNameFindIndex: constexpr string =
'%TypedArray%.prototype.findIndex'; '%TypedArray%.prototype.findIndex';
transitioning macro FindIndexAllElements(implicit context: Context)( transitioning macro FindIndexAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, predicate: Callable, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
thisArg: JSAny): Number { predicate: Callable, thisArg: JSAny): Number {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
const length: uintptr = witness.Get().length; typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0.
// 6. Repeat, while k < len // 6. Repeat, while k < len
for (let k: uintptr = 0; k < length; k++) { for (let k: uintptr = 0; k < attachedArrayAndLength.length; k++) {
// 6a. Let Pk be ! ToString(𝔽(k)). // 6a. Let Pk be ! ToString(𝔽(k)).
// There is no need to cast ToString to load elements. // There is no need to cast ToString to load elements.
...@@ -23,9 +24,9 @@ transitioning macro FindIndexAllElements(implicit context: Context)( ...@@ -23,9 +24,9 @@ transitioning macro FindIndexAllElements(implicit context: Context)(
// kValue must be undefined when the buffer is detached. // kValue must be undefined when the buffer is detached.
let value: JSAny; let value: JSAny;
try { try {
witness.Recheck() otherwise goto IsDetached; witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k); value = witness.Load(k);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
value = Undefined; value = Undefined;
} }
...@@ -47,21 +48,25 @@ transitioning macro FindIndexAllElements(implicit context: Context)( ...@@ -47,21 +48,25 @@ transitioning macro FindIndexAllElements(implicit context: Context)(
transitioning javascript builtin transitioning javascript builtin
TypedArrayPrototypeFindIndex( TypedArrayPrototypeFindIndex(
js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny { js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
// arguments[0] = callback // arguments[0] = predicate
// arguments[1] = thisArg. // arguments[1] = thisArg.
try { try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(predicate) is false, throw a TypeError exception.
const predicate = Cast<Callable>(arguments[0]) otherwise NotCallable; const predicate = Cast<Callable>(arguments[0]) otherwise NotCallable;
const thisArg = arguments[1]; const thisArg = arguments[1];
return FindIndexAllElements(uarray, predicate, thisArg); return FindIndexAllElements(attachedArrayAndLength, predicate, thisArg);
} label NotCallable deferred { } label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindIndex); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindIndex);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFindIndex); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFindIndex);
} }
} }
......
...@@ -10,14 +10,13 @@ const kBuiltinNameFindLast: constexpr string = ...@@ -10,14 +10,13 @@ const kBuiltinNameFindLast: constexpr string =
// https://tc39.es/proposal-array-find-from-last/index.html#sec-%typedarray%.prototype.findlast // https://tc39.es/proposal-array-find-from-last/index.html#sec-%typedarray%.prototype.findlast
transitioning macro FindLastAllElements(implicit context: Context)( transitioning macro FindLastAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, predicate: Callable, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
thisArg: JSAny): JSAny { predicate: Callable, thisArg: JSAny): JSAny {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
// 3. Let len be O.[[ArrayLength]]. typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
const length: uintptr = witness.Get().length;
// 5. Let k be len - 1. // 5. Let k be len - 1.
// 6. Repeat, while k ≥ 0 // 6. Repeat, while k ≥ 0
for (let k: uintptr = length; k-- > 0;) { for (let k: uintptr = attachedArrayAndLength.length; k-- > 0;) {
// 6a. Let Pk be ! ToString(𝔽(k)). // 6a. Let Pk be ! ToString(𝔽(k)).
// There is no need to cast ToString to load elements. // There is no need to cast ToString to load elements.
...@@ -25,9 +24,9 @@ transitioning macro FindLastAllElements(implicit context: Context)( ...@@ -25,9 +24,9 @@ transitioning macro FindLastAllElements(implicit context: Context)(
// kValue must be undefined when the buffer was detached. // kValue must be undefined when the buffer was detached.
let value: JSAny; let value: JSAny;
try { try {
witness.Recheck() otherwise goto IsDetached; witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k); value = witness.Load(k);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
value = Undefined; value = Undefined;
} }
...@@ -54,24 +53,25 @@ transitioning macro FindLastAllElements(implicit context: Context)( ...@@ -54,24 +53,25 @@ transitioning macro FindLastAllElements(implicit context: Context)(
transitioning javascript builtin transitioning javascript builtin
TypedArrayPrototypeFindLast( TypedArrayPrototypeFindLast(
js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny { js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
// arguments[0] = callback // arguments[0] = predicate
// arguments[1] = thisArg // arguments[1] = thisArg
try { try {
// 1. Let O be the this value. // 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
// 2. Perform ? ValidateTypedArray(O). const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(predicate) is false, throw a TypeError exception. // 4. If IsCallable(predicate) is false, throw a TypeError exception.
const predicate = Cast<Callable>(arguments[0]) otherwise NotCallable; const predicate = Cast<Callable>(arguments[0]) otherwise NotCallable;
const thisArg = arguments[1]; const thisArg = arguments[1];
return FindLastAllElements(uarray, predicate, thisArg); return FindLastAllElements(attachedArrayAndLength, predicate, thisArg);
} label NotCallable deferred { } label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindLast); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindLast);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFindLast); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFindLast);
} }
} }
......
...@@ -10,14 +10,13 @@ const kBuiltinNameFindLastIndex: constexpr string = ...@@ -10,14 +10,13 @@ const kBuiltinNameFindLastIndex: constexpr string =
// https://tc39.es/proposal-array-find-from-last/index.html#sec-%typedarray%.prototype.findlastindex // https://tc39.es/proposal-array-find-from-last/index.html#sec-%typedarray%.prototype.findlastindex
transitioning macro FindLastIndexAllElements(implicit context: Context)( transitioning macro FindLastIndexAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, predicate: Callable, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
thisArg: JSAny): Number { predicate: Callable, thisArg: JSAny): Number {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
// 3. Let len be O.[[ArrayLength]]. typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
const length: uintptr = witness.Get().length;
// 5. Let k be len - 1. // 5. Let k be len - 1.
// 6. Repeat, while k ≥ 0 // 6. Repeat, while k ≥ 0
for (let k: uintptr = length; k-- > 0;) { for (let k: uintptr = attachedArrayAndLength.length; k-- > 0;) {
// 6a. Let Pk be ! ToString(𝔽(k)). // 6a. Let Pk be ! ToString(𝔽(k)).
// There is no need to cast ToString to load elements. // There is no need to cast ToString to load elements.
...@@ -25,9 +24,9 @@ transitioning macro FindLastIndexAllElements(implicit context: Context)( ...@@ -25,9 +24,9 @@ transitioning macro FindLastIndexAllElements(implicit context: Context)(
// kValue must be undefined when the buffer was detached. // kValue must be undefined when the buffer was detached.
let value: JSAny; let value: JSAny;
try { try {
witness.Recheck() otherwise goto IsDetached; witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k); value = witness.Load(k);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
value = Undefined; value = Undefined;
} }
...@@ -54,25 +53,25 @@ transitioning macro FindLastIndexAllElements(implicit context: Context)( ...@@ -54,25 +53,25 @@ transitioning macro FindLastIndexAllElements(implicit context: Context)(
transitioning javascript builtin transitioning javascript builtin
TypedArrayPrototypeFindLastIndex( TypedArrayPrototypeFindLastIndex(
js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny { js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
// arguments[0] = callback // arguments[0] = predicate
// arguments[1] = thisArg. // arguments[1] = thisArg
try { try {
// 1. Let O be the this value. // 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
// 2. Perform ? ValidateTypedArray(O). const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(predicate) is false, throw a TypeError exception. // 4. If IsCallable(predicate) is false, throw a TypeError exception.
const predicate = Cast<Callable>(arguments[0]) otherwise NotCallable; const predicate = Cast<Callable>(arguments[0]) otherwise NotCallable;
const thisArg = arguments[1]; const thisArg = arguments[1];
return FindLastIndexAllElements(attachedArrayAndLength, predicate, thisArg);
return FindLastIndexAllElements(uarray, predicate, thisArg);
} label NotCallable deferred { } label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindLastIndex); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindLastIndex);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
ThrowTypeError( ThrowTypeError(
MessageTemplate::kDetachedOperation, kBuiltinNameFindLastIndex); MessageTemplate::kDetachedOperation, kBuiltinNameFindLastIndex);
} }
......
...@@ -8,13 +8,14 @@ namespace typed_array { ...@@ -8,13 +8,14 @@ namespace typed_array {
const kBuiltinNameForEach: constexpr string = '%TypedArray%.prototype.forEach'; const kBuiltinNameForEach: constexpr string = '%TypedArray%.prototype.forEach';
transitioning macro ForEachAllElements(implicit context: Context)( transitioning macro ForEachAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, callbackfn: Callable, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
thisArg: JSAny): Undefined { callbackfn: Callable, thisArg: JSAny): Undefined {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
const length: uintptr = witness.Get().length; typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0.
// 6. Repeat, while k < len // 6. Repeat, while k < len
for (let k: uintptr = 0; k < length; k++) { for (let k: uintptr = 0; k < attachedArrayAndLength.length; k++) {
// 6a. Let Pk be ! ToString(𝔽(k)). // 6a. Let Pk be ! ToString(𝔽(k)).
// There is no need to cast ToString to load elements. // There is no need to cast ToString to load elements.
...@@ -22,9 +23,9 @@ transitioning macro ForEachAllElements(implicit context: Context)( ...@@ -22,9 +23,9 @@ transitioning macro ForEachAllElements(implicit context: Context)(
// kValue must be undefined when the buffer is detached. // kValue must be undefined when the buffer is detached.
let value: JSAny; let value: JSAny;
try { try {
witness.Recheck() otherwise goto IsDetached; witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k); value = witness.Load(k);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
value = Undefined; value = Undefined;
} }
...@@ -50,18 +51,22 @@ TypedArrayPrototypeForEach(js-implicit context: NativeContext, receiver: JSAny)( ...@@ -50,18 +51,22 @@ TypedArrayPrototypeForEach(js-implicit context: NativeContext, receiver: JSAny)(
// arguments[1] = this_arg. // arguments[1] = this_arg.
try { try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable; const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable;
const thisArg = arguments[1]; const thisArg = arguments[1];
return ForEachAllElements(uarray, callbackfn, thisArg); return ForEachAllElements(attachedArrayAndLength, callbackfn, thisArg);
} label NotCallable deferred { } label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameForEach); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameForEach);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameForEach); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameForEach);
} }
} }
......
...@@ -8,19 +8,19 @@ namespace typed_array { ...@@ -8,19 +8,19 @@ namespace typed_array {
const kBuiltinNameReduce: constexpr string = '%TypedArray%.prototype.reduce'; const kBuiltinNameReduce: constexpr string = '%TypedArray%.prototype.reduce';
transitioning macro ReduceAllElements(implicit context: Context)( transitioning macro ReduceAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, callbackfn: Callable, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
initialValue: JSAny|TheHole): JSAny { callbackfn: Callable, initialValue: JSAny|TheHole): JSAny {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
const length: uintptr = witness.Get().length; typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
let accumulator = initialValue; let accumulator = initialValue;
for (let k: uintptr = 0; k < length; k++) { for (let k: uintptr = 0; k < attachedArrayAndLength.length; k++) {
let value: JSAny; let value: JSAny;
try { try {
witness.Recheck() witness.RecheckIndex(k)
otherwise goto IsDetached; otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k); value = witness.Load(k);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
value = Undefined; value = Undefined;
} }
typeswitch (accumulator) { typeswitch (accumulator) {
...@@ -53,18 +53,22 @@ TypedArrayPrototypeReduce( ...@@ -53,18 +53,22 @@ TypedArrayPrototypeReduce(
// arguments[0] = callback // arguments[0] = callback
// arguments[1] = initialValue. // arguments[1] = initialValue.
try { try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable; const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable;
const initialValue = arguments.length >= 2 ? arguments[1] : TheHole; const initialValue = arguments.length >= 2 ? arguments[1] : TheHole;
return ReduceAllElements(uarray, callbackfn, initialValue); return ReduceAllElements(attachedArrayAndLength, callbackfn, initialValue);
} label NotCallable deferred { } label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduce); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduce);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameReduce); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameReduce);
} }
} }
......
...@@ -10,18 +10,18 @@ const kBuiltinNameReduceRight: constexpr string = ...@@ -10,18 +10,18 @@ const kBuiltinNameReduceRight: constexpr string =
// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reduceright // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.reduceright
transitioning macro ReduceRightAllElements(implicit context: Context)( transitioning macro ReduceRightAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, callbackfn: Callable, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
initialValue: JSAny|TheHole): JSAny { callbackfn: Callable, initialValue: JSAny|TheHole): JSAny {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
const length: uintptr = witness.Get().length; typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
let accumulator = initialValue; let accumulator = initialValue;
for (let k: uintptr = length; k-- > 0;) { for (let k: uintptr = attachedArrayAndLength.length; k-- > 0;) {
let value: JSAny; let value: JSAny;
try { try {
witness.Recheck() witness.RecheckIndex(k)
otherwise goto IsDetached; otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k); value = witness.Load(k);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
value = Undefined; value = Undefined;
} }
typeswitch (accumulator) { typeswitch (accumulator) {
...@@ -55,19 +55,24 @@ TypedArrayPrototypeReduceRight( ...@@ -55,19 +55,24 @@ TypedArrayPrototypeReduceRight(
// arguments[0] = callback // arguments[0] = callback
// arguments[1] = initialValue. // arguments[1] = initialValue.
try { try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
const uarray = typed_array::EnsureAttached(array) otherwise IsDetached; const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable; const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable;
const initialValue = arguments.length >= 2 ? arguments[1] : TheHole; const initialValue = arguments.length >= 2 ? arguments[1] : TheHole;
return ReduceRightAllElements(uarray, callbackfn, initialValue); return ReduceRightAllElements(
attachedArrayAndLength, callbackfn, initialValue);
} label NotCallable deferred { } label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduceRight); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduceRight);
} label IsDetached deferred { } label IsDetachedOrOutOfBounds deferred {
ThrowTypeError( ThrowTypeError(
MessageTemplate::kDetachedOperation, kBuiltinNameReduceRight); MessageTemplate::kDetachedOperation, kBuiltinNameReduceRight);
} }
......
...@@ -9,13 +9,14 @@ const kBuiltinNameSome: constexpr string = '%TypedArray%.prototype.some'; ...@@ -9,13 +9,14 @@ const kBuiltinNameSome: constexpr string = '%TypedArray%.prototype.some';
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.some // https://tc39.es/ecma262/#sec-%typedarray%.prototype.some
transitioning macro SomeAllElements(implicit context: Context)( transitioning macro SomeAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, length: uintptr, attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
callbackfn: Callable, thisArg: JSAny): Boolean { callbackfn: Callable, thisArg: JSAny): Boolean {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array); let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0. // 5. Let k be 0.
// 6. Repeat, while k < len // 6. Repeat, while k < len
for (let k: uintptr = 0; k < length; k++) { for (let k: uintptr = 0; k < attachedArrayAndLength.length; k++) {
// 6a. Let Pk be ! ToString(𝔽(k)). // 6a. Let Pk be ! ToString(𝔽(k)).
// There is no need to cast ToString to load elements. // There is no need to cast ToString to load elements.
...@@ -61,13 +62,12 @@ TypedArrayPrototypeSome( ...@@ -61,13 +62,12 @@ TypedArrayPrototypeSome(
// 3. Let len be IntegerIndexedObjectLength(O). // 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray; otherwise NotTypedArray;
const length = LoadJSTypedArrayLengthAndCheckDetached(array) const attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds; otherwise IsDetachedOrOutOfBounds;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception. // 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable; const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable;
const thisArg = arguments[1]; const thisArg = arguments[1];
return SomeAllElements( return SomeAllElements(attachedArrayAndLength, callbackfn, thisArg);
%RawDownCast<AttachedJSTypedArray>(array), length, callbackfn, thisArg);
} label NotTypedArray deferred { } label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameSome); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameSome);
} label IsDetachedOrOutOfBounds deferred { } label IsDetachedOrOutOfBounds deferred {
......
...@@ -195,21 +195,27 @@ macro EnsureAttached(array: JSTypedArray): AttachedJSTypedArray ...@@ -195,21 +195,27 @@ macro EnsureAttached(array: JSTypedArray): AttachedJSTypedArray
} }
} }
struct AttachedJSTypedArrayWitness { struct AttachedJSTypedArrayAndLength {
macro Get(): AttachedJSTypedArray { array: AttachedJSTypedArray;
return this.unstable; length: uintptr;
} }
macro EnsureAttachedAndReadLength(array: JSTypedArray):
AttachedJSTypedArrayAndLength
labels DetachedOrOutOfBounds {
const length = LoadJSTypedArrayLengthAndCheckDetached(array)
otherwise DetachedOrOutOfBounds;
return AttachedJSTypedArrayAndLength{
array: %RawDownCast<AttachedJSTypedArray>(array),
length: length
};
}
struct AttachedJSTypedArrayWitness {
macro GetStable(): JSTypedArray { macro GetStable(): JSTypedArray {
return this.stable; return this.stable;
} }
// TODO(v8:11111): Migrate users to use RecheckIndex.
macro Recheck(): void labels Detached {
if (IsDetachedBuffer(this.stable.buffer)) goto Detached;
this.unstable = %RawDownCast<AttachedJSTypedArray>(this.stable);
}
macro RecheckIndex(index: uintptr): void labels DetachedOrOutOfBounds { macro RecheckIndex(index: uintptr): void labels DetachedOrOutOfBounds {
const length = LoadJSTypedArrayLengthAndCheckDetached(this.stable) const length = LoadJSTypedArrayLengthAndCheckDetached(this.stable)
otherwise DetachedOrOutOfBounds; otherwise DetachedOrOutOfBounds;
......
...@@ -45,7 +45,11 @@ function WriteToTypedArray(array, index, value) { ...@@ -45,7 +45,11 @@ function WriteToTypedArray(array, index, value) {
function ToNumbers(array) { function ToNumbers(array) {
let result = []; let result = [];
for (let item of array) { for (let item of array) {
result.push(Number(item)); if (typeof item == 'bigint') {
result.push(Number(item));
} else {
result.push(item);
}
} }
return result; return result;
} }
......
...@@ -422,18 +422,6 @@ ...@@ -422,18 +422,6 @@
'built-ins/DataView/prototype/setUint16/resizable-buffer': [FAIL], 'built-ins/DataView/prototype/setUint16/resizable-buffer': [FAIL],
'built-ins/DataView/prototype/setUint32/resizable-buffer': [FAIL], 'built-ins/DataView/prototype/setUint32/resizable-buffer': [FAIL],
'built-ins/DataView/prototype/setUint8/resizable-buffer': [FAIL], 'built-ins/DataView/prototype/setUint8/resizable-buffer': [FAIL],
'built-ins/TypedArray/prototype/filter/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/filter/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/findIndex/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/findLastIndex/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/findLast/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/find/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/forEach/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/forEach/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/indexOf/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/indexOf/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
...@@ -444,10 +432,6 @@ ...@@ -444,10 +432,6 @@
'built-ins/TypedArray/prototype/lastIndexOf/return-abrupt-from-this-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/lastIndexOf/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/map/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/map/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/reduce/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/reduce/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/reduceRight/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/reduceRight/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/reverse/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/reverse/BigInt/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/reverse/return-abrupt-from-this-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/reverse/return-abrupt-from-this-out-of-bounds': [SKIP],
'built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds': [SKIP], 'built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds': [SKIP],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment