[rab/gsab] RAB/GSAB support for TA.p.map

Bug: v8:11111
Change-Id: Ia84fe23c85b193bc7e31349eddc3705447795c33
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3400960
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78718}
This commit is contained in:
Marja Hölttä 2022-01-21 12:22:11 +01:00 committed by V8 LUCI CQ
parent 40db472a32
commit d3dbd42615
9 changed files with 508 additions and 18 deletions

View File

@ -128,11 +128,8 @@ void ArrayBuiltinsAssembler::GenerateIteratingTypedArrayBuiltinBody(
TNode<JSTypedArray> typed_array = CAST(receiver_); TNode<JSTypedArray> typed_array = CAST(receiver_);
o_ = typed_array; o_ = typed_array;
// TODO(v8:11111): Support RAB / GSAB. Label throw_detached(this, Label::kDeferred);
TNode<JSArrayBuffer> array_buffer = LoadJSArrayBufferViewBuffer(typed_array); len_ = LoadJSTypedArrayLengthAndCheckDetached(typed_array, &throw_detached);
ThrowIfArrayBufferIsDetached(context_, array_buffer, name_);
len_ = LoadJSTypedArrayLength(typed_array);
Label throw_not_callable(this, Label::kDeferred); Label throw_not_callable(this, Label::kDeferred);
Label distinguish_types(this); Label distinguish_types(this);
@ -146,13 +143,16 @@ void ArrayBuiltinsAssembler::GenerateIteratingTypedArrayBuiltinBody(
BIND(&throw_not_callable); BIND(&throw_not_callable);
ThrowTypeError(context_, MessageTemplate::kCalledNonCallable, callbackfn_); ThrowTypeError(context_, MessageTemplate::kCalledNonCallable, callbackfn_);
BIND(&throw_detached);
ThrowTypeError(context_, MessageTemplate::kDetachedOperation, name_);
Label unexpected_instance_type(this); Label unexpected_instance_type(this);
BIND(&unexpected_instance_type); BIND(&unexpected_instance_type);
Unreachable(); Unreachable();
std::vector<int32_t> elements_kinds = { std::vector<int32_t> elements_kinds = {
#define ELEMENTS_KIND(Type, type, TYPE, ctype) TYPE##_ELEMENTS, #define ELEMENTS_KIND(Type, type, TYPE, ctype) TYPE##_ELEMENTS,
TYPED_ARRAYS(ELEMENTS_KIND) TYPED_ARRAYS(ELEMENTS_KIND) RAB_GSAB_TYPED_ARRAYS(ELEMENTS_KIND)
#undef ELEMENTS_KIND #undef ELEMENTS_KIND
}; };
std::list<Label> labels; std::list<Label> labels;
@ -168,6 +168,7 @@ void ArrayBuiltinsAssembler::GenerateIteratingTypedArrayBuiltinBody(
generator(this); generator(this);
TNode<JSArrayBuffer> array_buffer = LoadJSArrayBufferViewBuffer(typed_array);
TNode<Int32T> elements_kind = LoadMapElementsKind(typed_array_map); TNode<Int32T> elements_kind = LoadMapElementsKind(typed_array_map);
Switch(elements_kind, &unexpected_instance_type, elements_kinds.data(), Switch(elements_kind, &unexpected_instance_type, elements_kinds.data(),
label_ptrs.data(), labels.size()); label_ptrs.data(), labels.size());
@ -176,15 +177,25 @@ void ArrayBuiltinsAssembler::GenerateIteratingTypedArrayBuiltinBody(
for (auto it = labels.begin(); it != labels.end(); ++i, ++it) { for (auto it = labels.begin(); it != labels.end(); ++i, ++it) {
BIND(&*it); BIND(&*it);
source_elements_kind_ = static_cast<ElementsKind>(elements_kinds[i]); source_elements_kind_ = static_cast<ElementsKind>(elements_kinds[i]);
VisitAllTypedArrayElements(array_buffer, processor, direction, typed_array); // TODO(v8:11111): Only RAB-backed TAs need special handling here since the
// backing store can shrink mid-iteration. This implementation has an
// overzealous check for GSAB-backed length-tracking TAs. Then again, the
// non-RAB/GSAB code also has an overzealous detached check for SABs.
bool is_rab_gsab = IsRabGsabTypedArrayElementsKind(source_elements_kind_);
if (is_rab_gsab) {
source_elements_kind_ =
GetCorrespondingNonRabGsabElementsKind(source_elements_kind_);
}
VisitAllTypedArrayElements(array_buffer, processor, direction, typed_array,
is_rab_gsab);
ReturnFromBuiltin(a_.value()); ReturnFromBuiltin(a_.value());
} }
} }
void ArrayBuiltinsAssembler::VisitAllTypedArrayElements( void ArrayBuiltinsAssembler::VisitAllTypedArrayElements(
TNode<JSArrayBuffer> array_buffer, const CallResultProcessor& processor, TNode<JSArrayBuffer> array_buffer, const CallResultProcessor& processor,
ForEachDirection direction, TNode<JSTypedArray> typed_array) { ForEachDirection direction, TNode<JSTypedArray> typed_array,
// TODO(v8:11111): Support RAB / GSAB. bool can_shrink) {
VariableList list({&a_, &k_}, zone()); VariableList list({&a_, &k_}, zone());
TNode<UintPtrT> start = UintPtrConstant(0); TNode<UintPtrT> start = UintPtrConstant(0);
@ -203,7 +214,12 @@ void ArrayBuiltinsAssembler::VisitAllTypedArrayElements(
TVARIABLE(Object, value); TVARIABLE(Object, value);
Label detached(this, Label::kDeferred); Label detached(this, Label::kDeferred);
Label process(this); Label process(this);
GotoIf(IsDetachedBuffer(array_buffer), &detached); if (can_shrink) {
// If `index` is out of bounds, Get returns undefined.
CheckJSTypedArrayIndex(index, typed_array, &detached);
} else {
GotoIf(IsDetachedBuffer(array_buffer), &detached);
}
{ {
TNode<RawPtrT> data_ptr = LoadJSTypedArrayDataPtr(typed_array); TNode<RawPtrT> data_ptr = LoadJSTypedArrayDataPtr(typed_array);
value = LoadFixedTypedArrayElementAsTagged(data_ptr, index, value = LoadFixedTypedArrayElementAsTagged(data_ptr, index,

View File

@ -105,7 +105,8 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
void VisitAllTypedArrayElements(TNode<JSArrayBuffer> array_buffer, void VisitAllTypedArrayElements(TNode<JSArrayBuffer> array_buffer,
const CallResultProcessor& processor, const CallResultProcessor& processor,
ForEachDirection direction, ForEachDirection direction,
TNode<JSTypedArray> typed_array); TNode<JSTypedArray> typed_array,
bool can_shrink);
TNode<Object> callbackfn_; TNode<Object> callbackfn_;
TNode<JSReceiver> o_; TNode<JSReceiver> o_;

View File

@ -14121,6 +14121,15 @@ TNode<BoolT> CodeStubAssembler::IsJSArrayBufferViewDetachedOrOutOfBoundsBoolean(
return result.value(); return result.value();
} }
void CodeStubAssembler::CheckJSTypedArrayIndex(
TNode<UintPtrT> index, TNode<JSTypedArray> typed_array,
Label* detached_or_out_of_bounds) {
TNode<UintPtrT> len = LoadJSTypedArrayLengthAndCheckDetached(
typed_array, detached_or_out_of_bounds);
GotoIf(UintPtrGreaterThanOrEqual(index, len), detached_or_out_of_bounds);
}
// ES #sec-integerindexedobjectbytelength // ES #sec-integerindexedobjectbytelength
TNode<UintPtrT> CodeStubAssembler::LoadVariableLengthJSTypedArrayByteLength( TNode<UintPtrT> CodeStubAssembler::LoadVariableLengthJSTypedArrayByteLength(
TNode<Context> context, TNode<JSTypedArray> array, TNode<Context> context, TNode<JSTypedArray> array,

View File

@ -3631,6 +3631,10 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<BoolT> IsJSArrayBufferViewDetachedOrOutOfBoundsBoolean( TNode<BoolT> IsJSArrayBufferViewDetachedOrOutOfBoundsBoolean(
TNode<JSArrayBufferView> array_buffer_view); TNode<JSArrayBufferView> array_buffer_view);
void CheckJSTypedArrayIndex(TNode<UintPtrT> index,
TNode<JSTypedArray> typed_array,
Label* detached_or_out_of_bounds);
TNode<IntPtrT> RabGsabElementsKindToElementByteSize( TNode<IntPtrT> RabGsabElementsKindToElementByteSize(
TNode<Int32T> elementsKind); TNode<Int32T> elementsKind);
TNode<RawPtrT> LoadJSTypedArrayDataPtr(TNode<JSTypedArray> typed_array); TNode<RawPtrT> LoadJSTypedArrayDataPtr(TNode<JSTypedArray> typed_array);

View File

@ -2594,3 +2594,141 @@ function TestIterationAndGrow(ta, expected, gsab, grow_after,
Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString; Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString;
BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString; BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString;
})(); })();
(function TestMap() {
for (let ctor of ctors) {
const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
const fixedLength = new ctor(gsab, 0, 4);
const fixedLengthWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT, 2);
const lengthTracking = new ctor(gsab, 0);
const lengthTrackingWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT);
// Write some data into the array.
const taWrite = new ctor(gsab);
for (let i = 0; i < 4; ++i) {
WriteToTypedArray(taWrite, i, 2 * i);
}
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
function Helper(array) {
const values = [];
function GatherValues(n, ix) {
assertEquals(values.length, ix);
values.push(n);
if (typeof n == 'bigint') {
return n + 1n;
}
return n + 1;
}
const newValues = array.map(GatherValues);
for (let i = 0; i < values.length; ++i) {
if (typeof values[i] == 'bigint') {
assertEquals(newValues[i], values[i] + 1n);
} else {
assertEquals(newValues[i], values[i] + 1);
}
}
return ToNumbers(values);
}
assertEquals([0, 2, 4, 6], Helper(fixedLength));
assertEquals([4, 6], Helper(fixedLengthWithOffset));
assertEquals([0, 2, 4, 6], Helper(lengthTracking));
assertEquals([4, 6], Helper(lengthTrackingWithOffset));
// Grow.
gsab.grow(6 * ctor.BYTES_PER_ELEMENT);
for (let i = 0; i < 6; ++i) {
WriteToTypedArray(taWrite, i, 2 * i);
}
// Orig. array: [0, 2, 4, 6, 8, 10]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, 8, 10, ...] << lengthTracking
// [4, 6, 8, 10, ...] << lengthTrackingWithOffset
assertEquals([0, 2, 4, 6], Helper(fixedLength));
assertEquals([4, 6], Helper(fixedLengthWithOffset));
assertEquals([0, 2, 4, 6, 8, 10], Helper(lengthTracking));
assertEquals([4, 6, 8, 10], Helper(lengthTrackingWithOffset));
}
})();
(function MapGrowMidIteration() {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
function CreateGsabForTest(ctor) {
const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
// Write some data into the array.
const taWrite = new ctor(gsab);
for (let i = 0; i < 4; ++i) {
WriteToTypedArray(taWrite, i, 2 * i);
}
return gsab;
}
let values;
let gsab;
let growAfter;
let growTo;
function CollectValuesAndResize(n) {
if (typeof n == 'bigint') {
values.push(Number(n));
} else {
values.push(n);
}
if (values.length == growAfter) {
gsab.grow(growTo);
}
return n;
}
function Helper(array) {
values = [];
array.map(CollectValuesAndResize);
return values;
}
for (let ctor of ctors) {
gsab = CreateGsabForTest(ctor);
const fixedLength = new ctor(gsab, 0, 4);
growAfter = 2;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertEquals([0, 2, 4, 6], Helper(fixedLength));
}
for (let ctor of ctors) {
gsab = CreateGsabForTest(ctor);
const fixedLengthWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT, 2);
growAfter = 1;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertEquals([4, 6], Helper(fixedLengthWithOffset));
}
for (let ctor of ctors) {
gsab = CreateGsabForTest(ctor);
const lengthTracking = new ctor(gsab, 0);
growAfter = 2;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertEquals([0, 2, 4, 6], Helper(lengthTracking));
}
for (let ctor of ctors) {
gsab = CreateGsabForTest(ctor);
const lengthTrackingWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT);
growAfter = 1;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertEquals([4, 6], Helper(lengthTrackingWithOffset));
}
})();

View File

@ -56,6 +56,10 @@ function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
return new SharedArrayBuffer(byteLength, {maxByteLength: maxByteLength}); return new SharedArrayBuffer(byteLength, {maxByteLength: maxByteLength});
} }
function IsBigIntTypedArray(ta) {
return (ta instanceof BigInt64Array) || (ta instanceof BigUint64Array);
}
function ReadDataFromBuffer(ab, ctor) { function ReadDataFromBuffer(ab, ctor) {
let result = []; let result = [];
const ta = new ctor(ab, 0, ab.byteLength / ctor.BYTES_PER_ELEMENT); const ta = new ctor(ab, 0, ab.byteLength / ctor.BYTES_PER_ELEMENT);

View File

@ -654,7 +654,7 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js');
let values; let values;
let rab; let rab;
let detachAfter; let detachAfter;
function CollectValuesAndResize(n) { function CollectValuesAndDetach(n) {
if (typeof n == 'bigint') { if (typeof n == 'bigint') {
values.push(Number(n)); values.push(Number(n));
} else { } else {
@ -668,19 +668,19 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js');
function ForEachHelper(array) { function ForEachHelper(array) {
values = []; values = [];
array.forEach(CollectValuesAndResize); array.forEach(CollectValuesAndDetach);
return values; return values;
} }
function ReduceHelper(array) { function ReduceHelper(array) {
values = []; values = [];
array.reduce((acc, n) => { CollectValuesAndResize(n); }, "initial value"); array.reduce((acc, n) => { CollectValuesAndDetach(n); }, "initial value");
return values; return values;
} }
function ReduceRightHelper(array) { function ReduceRightHelper(array) {
values = []; values = [];
array.reduceRight((acc, n) => { CollectValuesAndResize(n); }, array.reduceRight((acc, n) => { CollectValuesAndDetach(n); },
"initial value"); "initial value");
return values; return values;
} }
@ -983,3 +983,76 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js');
Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString; Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString;
BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString; BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString;
})(); })();
(function MapDetachMidIteration() {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
function CreateRabForTest(ctor) {
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
// Write some data into the array.
const taWrite = new ctor(rab);
for (let i = 0; i < 4; ++i) {
WriteToTypedArray(taWrite, i, 2 * i);
}
return rab;
}
let values;
let rab;
let detachAfter;
function CollectValuesAndDetach(n, ix, ta) {
if (typeof n == 'bigint') {
values.push(Number(n));
} else {
values.push(n);
}
if (values.length == detachAfter) {
%ArrayBufferDetach(rab);
}
// We still need to return a valid BigInt / non-BigInt, even if
// n is `undefined`.
if (IsBigIntTypedArray(ta)) {
return 0n;
} else {
return 0;
}
}
function Helper(array) {
values = [];
array.map(CollectValuesAndDetach);
return values;
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLength = new ctor(rab, 0, 4);
detachAfter = 2;
assertEquals([0, 2, undefined, undefined], Helper(fixedLength));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
detachAfter = 1;
assertEquals([4, undefined], Helper(fixedLengthWithOffset));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTracking = new ctor(rab, 0);
detachAfter = 2;
assertEquals([0, 2, undefined, undefined], Helper(lengthTracking));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
detachAfter = 1;
assertEquals([4, undefined], Helper(lengthTrackingWithOffset));
}
})();

View File

@ -4693,3 +4693,249 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString; Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString;
BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString; BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString;
})(); })();
(function TestMap() {
for (let ctor of ctors) {
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
const fixedLength = new ctor(rab, 0, 4);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
const lengthTracking = new ctor(rab, 0);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
// Write some data into the array.
const taWrite = new ctor(rab);
for (let i = 0; i < taWrite.length; ++i) {
WriteToTypedArray(taWrite, i, 2 * i);
}
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
function Helper(array) {
const values = [];
function GatherValues(n, ix) {
assertEquals(values.length, ix);
values.push(n);
if (typeof n == 'bigint') {
return n + 1n;
}
return n + 1;
}
const newValues = array.map(GatherValues);
for (let i = 0; i < values.length; ++i) {
if (typeof values[i] == 'bigint') {
assertEquals(newValues[i], values[i] + 1n);
} else {
assertEquals(newValues[i], values[i] + 1);
}
}
return ToNumbers(values);
}
assertEquals([0, 2, 4, 6], Helper(fixedLength));
assertEquals([4, 6], Helper(fixedLengthWithOffset));
assertEquals([0, 2, 4, 6], Helper(lengthTracking));
assertEquals([4, 6], Helper(lengthTrackingWithOffset));
// Shrink so that fixed length TAs go out of bounds.
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
// Orig. array: [0, 2, 4]
// [0, 2, 4, ...] << lengthTracking
// [4, ...] << lengthTrackingWithOffset
assertThrows(() => { Helper(fixedLength); });
assertThrows(() => { Helper(fixedLengthWithOffset); });
assertEquals([0, 2, 4], Helper(lengthTracking));
assertEquals([4], Helper(lengthTrackingWithOffset));
// Shrink so that the TAs with offset go out of bounds.
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
assertThrows(() => { Helper(fixedLength); });
assertThrows(() => { Helper(fixedLengthWithOffset); });
assertThrows(() => { Helper(lengthTrackingWithOffset); });
assertEquals([0], Helper(lengthTracking));
// Shrink to zero.
rab.resize(0);
assertThrows(() => { Helper(fixedLength); });
assertThrows(() => { Helper(fixedLengthWithOffset); });
assertThrows(() => { Helper(lengthTrackingWithOffset); });
assertEquals([], Helper(lengthTracking));
// Grow so that all TAs are back in-bounds.
rab.resize(6 * ctor.BYTES_PER_ELEMENT);
for (let i = 0; i < 6; ++i) {
WriteToTypedArray(taWrite, i, 2 * i);
}
// Orig. array: [0, 2, 4, 6, 8, 10]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, 8, 10, ...] << lengthTracking
// [4, 6, 8, 10, ...] << lengthTrackingWithOffset
assertEquals([0, 2, 4, 6], Helper(fixedLength));
assertEquals([4, 6], Helper(fixedLengthWithOffset));
assertEquals([0, 2, 4, 6, 8, 10], Helper(lengthTracking));
assertEquals([4, 6, 8, 10], Helper(lengthTrackingWithOffset));
}
})();
(function MapShrinkMidIteration() {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
function CreateRabForTest(ctor) {
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
// Write some data into the array.
const taWrite = new ctor(rab);
for (let i = 0; i < 4; ++i) {
WriteToTypedArray(taWrite, i, 2 * i);
}
return rab;
}
let values;
let rab;
let resizeAfter;
let resizeTo;
function CollectValuesAndResize(n, ix, ta) {
if (typeof n == 'bigint') {
values.push(Number(n));
} else {
values.push(n);
}
if (values.length == resizeAfter) {
rab.resize(resizeTo);
}
// We still need to return a valid BigInt / non-BigInt, even if
// n is `undefined`.
if (IsBigIntTypedArray(ta)) {
return 0n;
}
return 0;
}
function Helper(array) {
values = [];
array.map(CollectValuesAndResize);
return values;
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLength = new ctor(rab, 0, 4);
resizeAfter = 2;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assertEquals([0, 2, undefined, undefined], Helper(fixedLength));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
resizeAfter = 1;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assertEquals([4, undefined], Helper(fixedLengthWithOffset));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTracking = new ctor(rab, 0);
resizeAfter = 2;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assertEquals([0, 2, 4, undefined], Helper(lengthTracking));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
resizeAfter = 1;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assertEquals([4, undefined], Helper(lengthTrackingWithOffset));
}
})();
(function MapGrowMidIteration() {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
function CreateRabForTest(ctor) {
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
// Write some data into the array.
const taWrite = new ctor(rab);
for (let i = 0; i < 4; ++i) {
WriteToTypedArray(taWrite, i, 2 * i);
}
return rab;
}
let values;
let rab;
let resizeAfter;
let resizeTo;
function CollectValuesAndResize(n) {
if (typeof n == 'bigint') {
values.push(Number(n));
} else {
values.push(n);
}
if (values.length == resizeAfter) {
rab.resize(resizeTo);
}
return n;
}
function Helper(array) {
values = [];
array.map(CollectValuesAndResize);
return values;
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLength = new ctor(rab, 0, 4);
resizeAfter = 2;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assertEquals([0, 2, 4, 6], Helper(fixedLength));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
resizeAfter = 1;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assertEquals([4, 6], Helper(fixedLengthWithOffset));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTracking = new ctor(rab, 0);
resizeAfter = 2;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assertEquals([0, 2, 4, 6], Helper(lengthTracking));
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
resizeAfter = 1;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assertEquals([4, 6], Helper(lengthTrackingWithOffset));
}
})();

View File

@ -283,8 +283,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=11111 # https://bugs.chromium.org/p/v8/issues/detail?id=11111
'built-ins/ArrayBuffer/prototype/transfer/*': [FAIL], 'built-ins/ArrayBuffer/prototype/transfer/*': [FAIL],
'built-ins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer': [PASS], 'built-ins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer': [PASS],
'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/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],
@ -294,7 +292,8 @@
'built-ins/TypedArray/prototype/sort/return-abrupt-from-this-out-of-bounds': [FAIL], 'built-ins/TypedArray/prototype/sort/return-abrupt-from-this-out-of-bounds': [FAIL],
'built-ins/TypedArrayConstructors/ctors/typedarray-arg/out-of-bounds-when-species-retrieved-different-type': [FAIL], 'built-ins/TypedArrayConstructors/ctors/typedarray-arg/out-of-bounds-when-species-retrieved-different-type': [FAIL],
'built-ins/TypedArrayConstructors/ctors/typedarray-arg/out-of-bounds-when-species-retrieved-same-type': [FAIL], 'built-ins/TypedArrayConstructors/ctors/typedarray-arg/out-of-bounds-when-species-retrieved-same-type': [FAIL],
'built-ins/TypedArray/prototype/map/callbackfn-resize': [SKIP], # See also https://github.com/tc39/test262/issues/3380
'built-ins/TypedArray/prototype/map/callbackfn-resize': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=12525 # https://bugs.chromium.org/p/v8/issues/detail?id=12525
# regexp-v-flag not yet in Stage 3. # regexp-v-flag not yet in Stage 3.