-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RAB: Integrate staging tests for the .values method (#4179)
* Import relevant files from #3888 * Removing parts in resizableArrayBufferUtils.js and adding it in includes, while applying review changes from PRs for previously tested methods. * Removes unnecessary .from calls, as suggested in previous PR review comment: #4138 (comment)
- Loading branch information
Showing
6 changed files
with
529 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
test/built-ins/Array/prototype/values/resizable-buffer-grow-mid-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2023 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-array.prototype.values | ||
description: > | ||
Array.p.values behaves correctly on TypedArrays backed by resizable buffers and | ||
resized mid-iteration. | ||
features: [resizable-arraybuffer] | ||
includes: [compareArray.js, resizableArrayBufferUtils.js] | ||
---*/ | ||
|
||
// Orig. array: [0, 2, 4, 6] | ||
// [0, 2, 4, 6] << fixedLength | ||
// [4, 6] << fixedLengthWithOffset | ||
// [0, 2, 4, 6, ...] << lengthTracking | ||
// [4, 6, ...] << lengthTrackingWithOffset | ||
|
||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const fixedLength = new ctor(rab, 0, 4); | ||
// The fixed length array is not affected by resizing. | ||
TestIterationAndResize(Array.prototype.values.call(fixedLength), [ | ||
0, | ||
2, | ||
4, | ||
6 | ||
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); | ||
// The fixed length array is not affected by resizing. | ||
TestIterationAndResize(Array.prototype.values.call(fixedLengthWithOffset), [ | ||
4, | ||
6 | ||
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const lengthTracking = new ctor(rab, 0); | ||
TestIterationAndResize(Array.prototype.values.call(lengthTracking), [ | ||
0, | ||
2, | ||
4, | ||
6, | ||
0, | ||
0 | ||
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); | ||
TestIterationAndResize(Array.prototype.values.call(lengthTrackingWithOffset), [ | ||
4, | ||
6, | ||
0, | ||
0 | ||
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); | ||
} |
52 changes: 52 additions & 0 deletions
52
test/built-ins/Array/prototype/values/resizable-buffer-shrink-mid-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-array.prototype.values | ||
description: > | ||
Array.p.values behaves correctly on TypedArrays backed by resizable buffers | ||
that are shrunk mid-iteration. | ||
features: [resizable-arraybuffer] | ||
includes: [compareArray.js, resizableArrayBufferUtils.js] | ||
---*/ | ||
|
||
// Orig. array: [0, 2, 4, 6] | ||
// [0, 2, 4, 6] << fixedLength | ||
// [4, 6] << fixedLengthWithOffset | ||
// [0, 2, 4, 6, ...] << lengthTracking | ||
// [4, 6, ...] << lengthTrackingWithOffset | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const fixedLength = new ctor(rab, 0, 4); | ||
|
||
// The fixed length array goes out of bounds when the RAB is resized. | ||
assert.throws(TypeError, () => { | ||
TestIterationAndResize(Array.prototype.values.call(fixedLength), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); | ||
}); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); | ||
assert.throws(TypeError, () => { | ||
TestIterationAndResize(Array.prototype.values.call(fixedLengthWithOffset), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); | ||
}); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const lengthTracking = new ctor(rab, 0); | ||
TestIterationAndResize(Array.prototype.values.call(lengthTracking), [ | ||
0, | ||
2, | ||
4 | ||
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); | ||
|
||
// The fixed length array goes out of bounds when the RAB is resized. | ||
TestIterationAndResize(Array.prototype.values.call(lengthTrackingWithOffset), [ | ||
4, | ||
6 | ||
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); | ||
} |
156 changes: 156 additions & 0 deletions
156
test/built-ins/Array/prototype/values/resizable-buffer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// Copyright 2023 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-array.prototype.values | ||
description: > | ||
Array.p.values behaves correctly on TypedArrays backed by resizable buffers. | ||
includes: [compareArray.js, resizableArrayBufferUtils.js] | ||
features: [resizable-arraybuffer] | ||
---*/ | ||
|
||
function IteratorToNumbers(iterator) { | ||
const result = []; | ||
for (let value of iterator) { | ||
result.push(Number(value)); | ||
} | ||
return result; | ||
} | ||
|
||
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 < 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 | ||
|
||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(fixedLength)), [ | ||
0, | ||
2, | ||
4, | ||
6 | ||
]); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(fixedLengthWithOffset)), [ | ||
4, | ||
6 | ||
]); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTracking)), [ | ||
0, | ||
2, | ||
4, | ||
6 | ||
]); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTrackingWithOffset)), [ | ||
4, | ||
6 | ||
]); | ||
|
||
// 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 | ||
|
||
// TypedArray.prototype.{entries, keys, values} throw right away when | ||
// called. Array.prototype.{entries, keys, values} don't throw, but when | ||
// we try to iterate the returned ArrayIterator, that throws. | ||
Array.prototype.values.call(fixedLength); | ||
Array.prototype.values.call(fixedLengthWithOffset); | ||
|
||
assert.throws(TypeError, () => { | ||
Array.from(Array.prototype.values.call(fixedLength)); | ||
}); | ||
assert.throws(TypeError, () => { | ||
Array.from(Array.prototype.values.call(fixedLengthWithOffset)); | ||
}); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTracking)), [ | ||
0, | ||
2, | ||
4 | ||
]); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTrackingWithOffset)), [4]); | ||
|
||
// Shrink so that the TAs with offset go out of bounds. | ||
rab.resize(1 * ctor.BYTES_PER_ELEMENT); | ||
Array.prototype.values.call(fixedLength); | ||
Array.prototype.values.call(fixedLengthWithOffset); | ||
Array.prototype.values.call(lengthTrackingWithOffset); | ||
|
||
assert.throws(TypeError, () => { | ||
Array.from(Array.prototype.values.call(fixedLength)); | ||
}); | ||
assert.throws(TypeError, () => { | ||
Array.from(Array.prototype.values.call(fixedLengthWithOffset)); | ||
}); | ||
assert.throws(TypeError, () => { | ||
Array.from(Array.prototype.values.call(lengthTrackingWithOffset)); | ||
}); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTracking)), [0]); | ||
|
||
// Shrink to zero. | ||
rab.resize(0); | ||
Array.prototype.values.call(fixedLength); | ||
Array.prototype.values.call(fixedLengthWithOffset); | ||
Array.prototype.values.call(lengthTrackingWithOffset); | ||
|
||
assert.throws(TypeError, () => { | ||
Array.from(Array.prototype.values.call(fixedLength)); | ||
}); | ||
assert.throws(TypeError, () => { | ||
Array.from(Array.prototype.values.call(fixedLengthWithOffset)); | ||
}); | ||
assert.throws(TypeError, () => { | ||
Array.from(Array.prototype.values.call(lengthTrackingWithOffset)); | ||
}); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(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 | ||
|
||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(fixedLength)), [ | ||
0, | ||
2, | ||
4, | ||
6 | ||
]); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(fixedLengthWithOffset)), [ | ||
4, | ||
6 | ||
]); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTracking)), [ | ||
0, | ||
2, | ||
4, | ||
6, | ||
8, | ||
10 | ||
]); | ||
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTrackingWithOffset)), [ | ||
4, | ||
6, | ||
8, | ||
10 | ||
]); | ||
} |
60 changes: 60 additions & 0 deletions
60
test/built-ins/TypedArray/prototype/values/resizable-buffer-grow-mid-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2023 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-%typedarray%.prototype.values | ||
description: > | ||
TypedArray.p.values behaves correctly on TypedArrays backed by resizable | ||
buffers and resized mid-iteration. | ||
features: [resizable-arraybuffer] | ||
includes: [compareArray.js, resizableArrayBufferUtils.js] | ||
---*/ | ||
|
||
// Orig. array: [0, 2, 4, 6] | ||
// [0, 2, 4, 6] << fixedLength | ||
// [4, 6] << fixedLengthWithOffset | ||
// [0, 2, 4, 6, ...] << lengthTracking | ||
// [4, 6, ...] << lengthTrackingWithOffset | ||
|
||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const fixedLength = new ctor(rab, 0, 4); | ||
// The fixed length array is not affected by resizing. | ||
TestIterationAndResize(fixedLength.values(), [ | ||
0, | ||
2, | ||
4, | ||
6 | ||
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); | ||
// The fixed length array is not affected by resizing. | ||
TestIterationAndResize(fixedLengthWithOffset.values(), [ | ||
4, | ||
6 | ||
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const lengthTracking = new ctor(rab, 0); | ||
TestIterationAndResize(lengthTracking.values(), [ | ||
0, | ||
2, | ||
4, | ||
6, | ||
0, | ||
0 | ||
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); | ||
TestIterationAndResize(lengthTrackingWithOffset.values(), [ | ||
4, | ||
6, | ||
0, | ||
0 | ||
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); | ||
} |
52 changes: 52 additions & 0 deletions
52
test/built-ins/TypedArray/prototype/values/resizable-buffer-shrink-mid-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-%typedarray%.prototype.values | ||
description: > | ||
TypedArray.p.values behaves correctly on TypedArrays backed by resizable | ||
buffers that are shrunk mid-iteration. | ||
features: [resizable-arraybuffer] | ||
includes: [compareArray.js, resizableArrayBufferUtils.js] | ||
---*/ | ||
|
||
// Orig. array: [0, 2, 4, 6] | ||
// [0, 2, 4, 6] << fixedLength | ||
// [4, 6] << fixedLengthWithOffset | ||
// [0, 2, 4, 6, ...] << lengthTracking | ||
// [4, 6, ...] << lengthTrackingWithOffset | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const fixedLength = new ctor(rab, 0, 4); | ||
|
||
// The fixed length array goes out of bounds when the RAB is resized. | ||
assert.throws(TypeError, () => { | ||
TestIterationAndResize(fixedLength.values(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); | ||
}); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); | ||
assert.throws(TypeError, () => { | ||
TestIterationAndResize(fixedLengthWithOffset.values(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); | ||
}); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const lengthTracking = new ctor(rab, 0); | ||
TestIterationAndResize(lengthTracking.values(), [ | ||
0, | ||
2, | ||
4 | ||
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); | ||
} | ||
for (let ctor of ctors) { | ||
const rab = CreateRabForTest(ctor); | ||
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); | ||
|
||
// The fixed length array goes out of bounds when the RAB is resized. | ||
TestIterationAndResize(lengthTrackingWithOffset.values(), [ | ||
4, | ||
6 | ||
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); | ||
} |
Oops, something went wrong.