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';
// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.every
transitioning macro EveryAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, length: uintptr,
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
callbackfn: Callable, thisArg: JSAny): Boolean {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array);
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0.
// 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)).
// There is no need to cast ToString to load elements.
......@@ -59,13 +60,12 @@ TypedArrayPrototypeEvery(
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray;
const length = LoadJSTypedArrayLengthAndCheckDetached(array)
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 thisArg = arguments[1];
return EveryAllElements(
%RawDownCast<AttachedJSTypedArray>(array), length, callbackfn, thisArg);
return EveryAllElements(attachedArrayAndLength, callbackfn, thisArg);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameEvery);
} label IsDetachedOrOutOfBounds deferred {
......
......@@ -13,14 +13,13 @@ transitioning javascript builtin TypedArrayPrototypeFilter(
try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise ThrowTypeError(
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.
const callbackfn = Cast<Callable>(arguments[0])
otherwise ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
......@@ -32,19 +31,20 @@ transitioning javascript builtin TypedArrayPrototypeFilter(
// TODO(v8:4153): Support huge TypedArrays here. (growable fixed arrays
// can't be longer than kMaxSmiValue).
let kept = growable_fixed_array::NewGrowableFixedArray();
let witness = typed_array::NewAttachedJSTypedArrayWitness(src);
let witness = typed_array::NewAttachedJSTypedArrayWitness(
attachedArrayAndLength.array);
// 7. Let k be 0.
// 8. Let captured be 0.
// 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;
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
try {
witness.Recheck() otherwise goto IsDetached;
witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
value = Undefined;
}
......@@ -80,7 +80,7 @@ transitioning javascript builtin TypedArrayPrototypeFilter(
// 13. Return A.
return typedArray;
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFilter);
}
}
......
......@@ -9,13 +9,14 @@ const kBuiltinNameFind: constexpr string = '%TypedArray%.prototype.find';
// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.find
transitioning macro FindAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, predicate: Callable,
thisArg: JSAny): JSAny {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array);
const length: uintptr = witness.Get().length;
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
predicate: Callable, thisArg: JSAny): JSAny {
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0.
// 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)).
// There is no need to cast ToString to load elements.
......@@ -23,9 +24,9 @@ transitioning macro FindAllElements(implicit context: Context)(
// kValue must be undefined when the buffer is detached.
let value: JSAny;
try {
witness.Recheck() otherwise goto IsDetached;
witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
value = Undefined;
}
......@@ -56,18 +57,22 @@ TypedArrayPrototypeFind(
// arguments[0] = callback
// arguments[1] = thisArg
try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
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 thisArg = arguments[1];
return FindAllElements(uarray, predicate, thisArg);
return FindAllElements(attachedArrayAndLength, predicate, thisArg);
} label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFind);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFind);
}
}
......
......@@ -9,13 +9,14 @@ const kBuiltinNameFindIndex: constexpr string =
'%TypedArray%.prototype.findIndex';
transitioning macro FindIndexAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, predicate: Callable,
thisArg: JSAny): Number {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array);
const length: uintptr = witness.Get().length;
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
predicate: Callable, thisArg: JSAny): Number {
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0.
// 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)).
// There is no need to cast ToString to load elements.
......@@ -23,9 +24,9 @@ transitioning macro FindIndexAllElements(implicit context: Context)(
// kValue must be undefined when the buffer is detached.
let value: JSAny;
try {
witness.Recheck() otherwise goto IsDetached;
witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
value = Undefined;
}
......@@ -47,21 +48,25 @@ transitioning macro FindIndexAllElements(implicit context: Context)(
transitioning javascript builtin
TypedArrayPrototypeFindIndex(
js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
// arguments[0] = callback
// arguments[0] = predicate
// arguments[1] = thisArg.
try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
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 thisArg = arguments[1];
return FindIndexAllElements(uarray, predicate, thisArg);
return FindIndexAllElements(attachedArrayAndLength, predicate, thisArg);
} label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindIndex);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFindIndex);
}
}
......
......@@ -10,14 +10,13 @@ const kBuiltinNameFindLast: constexpr string =
// https://tc39.es/proposal-array-find-from-last/index.html#sec-%typedarray%.prototype.findlast
transitioning macro FindLastAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, predicate: Callable,
thisArg: JSAny): JSAny {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array);
// 3. Let len be O.[[ArrayLength]].
const length: uintptr = witness.Get().length;
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
predicate: Callable, thisArg: JSAny): JSAny {
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be len - 1.
// 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)).
// There is no need to cast ToString to load elements.
......@@ -25,9 +24,9 @@ transitioning macro FindLastAllElements(implicit context: Context)(
// kValue must be undefined when the buffer was detached.
let value: JSAny;
try {
witness.Recheck() otherwise goto IsDetached;
witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
value = Undefined;
}
......@@ -54,24 +53,25 @@ transitioning macro FindLastAllElements(implicit context: Context)(
transitioning javascript builtin
TypedArrayPrototypeFindLast(
js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
// arguments[0] = callback
// arguments[0] = predicate
// arguments[1] = thisArg
try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray;
// 2. Perform ? ValidateTypedArray(O).
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 thisArg = arguments[1];
return FindLastAllElements(uarray, predicate, thisArg);
return FindLastAllElements(attachedArrayAndLength, predicate, thisArg);
} label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindLast);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFindLast);
}
}
......
......@@ -10,14 +10,13 @@ const kBuiltinNameFindLastIndex: constexpr string =
// https://tc39.es/proposal-array-find-from-last/index.html#sec-%typedarray%.prototype.findlastindex
transitioning macro FindLastIndexAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, predicate: Callable,
thisArg: JSAny): Number {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array);
// 3. Let len be O.[[ArrayLength]].
const length: uintptr = witness.Get().length;
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
predicate: Callable, thisArg: JSAny): Number {
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be len - 1.
// 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)).
// There is no need to cast ToString to load elements.
......@@ -25,9 +24,9 @@ transitioning macro FindLastIndexAllElements(implicit context: Context)(
// kValue must be undefined when the buffer was detached.
let value: JSAny;
try {
witness.Recheck() otherwise goto IsDetached;
witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
value = Undefined;
}
......@@ -54,25 +53,25 @@ transitioning macro FindLastIndexAllElements(implicit context: Context)(
transitioning javascript builtin
TypedArrayPrototypeFindLastIndex(
js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
// arguments[0] = callback
// arguments[1] = thisArg.
// arguments[0] = predicate
// arguments[1] = thisArg
try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray;
// 2. Perform ? ValidateTypedArray(O).
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 thisArg = arguments[1];
return FindLastIndexAllElements(uarray, predicate, thisArg);
return FindLastIndexAllElements(attachedArrayAndLength, predicate, thisArg);
} label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindLastIndex);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(
MessageTemplate::kDetachedOperation, kBuiltinNameFindLastIndex);
}
......
......@@ -8,13 +8,14 @@ namespace typed_array {
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;
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
callbackfn: Callable, thisArg: JSAny): Undefined {
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0.
// 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)).
// There is no need to cast ToString to load elements.
......@@ -22,9 +23,9 @@ transitioning macro ForEachAllElements(implicit context: Context)(
// kValue must be undefined when the buffer is detached.
let value: JSAny;
try {
witness.Recheck() otherwise goto IsDetached;
witness.RecheckIndex(k) otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
value = Undefined;
}
......@@ -50,18 +51,22 @@ TypedArrayPrototypeForEach(js-implicit context: NativeContext, receiver: JSAny)(
// arguments[1] = this_arg.
try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
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 thisArg = arguments[1];
return ForEachAllElements(uarray, callbackfn, thisArg);
return ForEachAllElements(attachedArrayAndLength, callbackfn, thisArg);
} label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameForEach);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameForEach);
}
}
......
......@@ -8,19 +8,19 @@ namespace typed_array {
const kBuiltinNameReduce: constexpr string = '%TypedArray%.prototype.reduce';
transitioning macro ReduceAllElements(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;
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
callbackfn: Callable, initialValue: JSAny|TheHole): JSAny {
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
let accumulator = initialValue;
for (let k: uintptr = 0; k < length; k++) {
for (let k: uintptr = 0; k < attachedArrayAndLength.length; k++) {
let value: JSAny;
try {
witness.Recheck()
otherwise goto IsDetached;
witness.RecheckIndex(k)
otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
value = Undefined;
}
typeswitch (accumulator) {
......@@ -53,18 +53,22 @@ TypedArrayPrototypeReduce(
// arguments[0] = callback
// arguments[1] = initialValue.
try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
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 initialValue = arguments.length >= 2 ? arguments[1] : TheHole;
return ReduceAllElements(uarray, callbackfn, initialValue);
return ReduceAllElements(attachedArrayAndLength, callbackfn, initialValue);
} label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduce);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameReduce);
}
}
......
......@@ -10,18 +10,18 @@ const kBuiltinNameReduceRight: constexpr string =
// https://tc39.github.io/ecma262/#sec-%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;
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
callbackfn: Callable, initialValue: JSAny|TheHole): JSAny {
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
let accumulator = initialValue;
for (let k: uintptr = length; k-- > 0;) {
for (let k: uintptr = attachedArrayAndLength.length; k-- > 0;) {
let value: JSAny;
try {
witness.Recheck()
otherwise goto IsDetached;
witness.RecheckIndex(k)
otherwise goto IsDetachedOrOutOfBounds;
value = witness.Load(k);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
value = Undefined;
}
typeswitch (accumulator) {
......@@ -55,19 +55,24 @@ TypedArrayPrototypeReduceRight(
// arguments[0] = callback
// arguments[1] = initialValue.
try {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
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 initialValue = arguments.length >= 2 ? arguments[1] : TheHole;
return ReduceRightAllElements(uarray, callbackfn, initialValue);
return ReduceRightAllElements(
attachedArrayAndLength, callbackfn, initialValue);
} label NotCallable deferred {
ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduceRight);
} label IsDetached deferred {
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(
MessageTemplate::kDetachedOperation, kBuiltinNameReduceRight);
}
......
......@@ -9,13 +9,14 @@ const kBuiltinNameSome: constexpr string = '%TypedArray%.prototype.some';
// https://tc39.es/ecma262/#sec-%typedarray%.prototype.some
transitioning macro SomeAllElements(implicit context: Context)(
array: typed_array::AttachedJSTypedArray, length: uintptr,
attachedArrayAndLength: typed_array::AttachedJSTypedArrayAndLength,
callbackfn: Callable, thisArg: JSAny): Boolean {
let witness = typed_array::NewAttachedJSTypedArrayWitness(array);
let witness =
typed_array::NewAttachedJSTypedArrayWitness(attachedArrayAndLength.array);
// 5. Let k be 0.
// 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)).
// There is no need to cast ToString to load elements.
......@@ -61,13 +62,12 @@ TypedArrayPrototypeSome(
// 3. Let len be IntegerIndexedObjectLength(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray;
const length = LoadJSTypedArrayLengthAndCheckDetached(array)
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 thisArg = arguments[1];
return SomeAllElements(
%RawDownCast<AttachedJSTypedArray>(array), length, callbackfn, thisArg);
return SomeAllElements(attachedArrayAndLength, callbackfn, thisArg);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameSome);
} label IsDetachedOrOutOfBounds deferred {
......
......@@ -195,21 +195,27 @@ macro EnsureAttached(array: JSTypedArray): AttachedJSTypedArray
}
}
struct AttachedJSTypedArrayWitness {
macro Get(): AttachedJSTypedArray {
return this.unstable;
}
struct AttachedJSTypedArrayAndLength {
array: AttachedJSTypedArray;
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 {
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 {
const length = LoadJSTypedArrayLengthAndCheckDetached(this.stable)
otherwise DetachedOrOutOfBounds;
......
......@@ -45,7 +45,11 @@ function WriteToTypedArray(array, index, value) {
function ToNumbers(array) {
let result = [];
for (let item of array) {
result.push(Number(item));
if (typeof item == 'bigint') {
result.push(Number(item));
} else {
result.push(item);
}
}
return result;
}
......
......@@ -422,18 +422,6 @@
'built-ins/DataView/prototype/setUint16/resizable-buffer': [FAIL],
'built-ins/DataView/prototype/setUint32/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/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 @@
'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/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/return-abrupt-from-this-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