-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing 'shrink' test for Array.prototype.reduce
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
test/built-ins/Array/prototype/reduce/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,79 @@ | ||
// 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.reduce | ||
description: > | ||
Array.p.reduce behaves correctly when the backing resizable buffer is shrunk | ||
mid-iteration. | ||
includes: [compareArray.js, resizableArrayBufferUtils.js] | ||
features: [resizable-arraybuffer] | ||
---*/ | ||
|
||
let values; | ||
let rab; | ||
let resizeAfter; | ||
let resizeTo; | ||
// Collects the view of the resizable array buffer rab into values, with an | ||
// iteration during which, after resizeAfter steps, rab is resized to length | ||
// resizeTo. To be called by a method of the view being collected. | ||
// Note that rab, values, resizeAfter, and resizeTo may need to be reset | ||
// before calling this. | ||
function ResizeMidIteration(acc, n) { | ||
// Returns true by default. | ||
return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); | ||
} | ||
|
||
// 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) { | ||
values = []; | ||
rab = CreateRabForTest(ctor); | ||
const fixedLength = new ctor(rab, 0, 4); | ||
resizeAfter = 2; | ||
resizeTo = 3 * ctor.BYTES_PER_ELEMENT; | ||
Array.prototype.reduce.call(fixedLength, ResizeMidIteration, 'initial value'); | ||
assert.compareArray(values, [ | ||
0, | ||
2 | ||
]); | ||
} | ||
for (let ctor of ctors) { | ||
values = []; | ||
rab = CreateRabForTest(ctor); | ||
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); | ||
resizeAfter = 1; | ||
resizeTo = 3 * ctor.BYTES_PER_ELEMENT; | ||
Array.prototype.reduce.call(fixedLengthWithOffset, ResizeMidIteration, 'initial value'); | ||
assert.compareArray(values, [ | ||
4 | ||
]); | ||
} | ||
for (let ctor of ctors) { | ||
values = []; | ||
rab = CreateRabForTest(ctor); | ||
const lengthTracking = new ctor(rab, 0); | ||
resizeAfter = 2; | ||
resizeTo = 3 * ctor.BYTES_PER_ELEMENT; | ||
Array.prototype.reduce.call(lengthTracking, ResizeMidIteration, 'initial value'); | ||
assert.compareArray(values, [ | ||
0, | ||
2, | ||
4 | ||
]); | ||
} | ||
for (let ctor of ctors) { | ||
values = []; | ||
rab = CreateRabForTest(ctor); | ||
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); | ||
resizeAfter = 1; | ||
resizeTo = 3 * ctor.BYTES_PER_ELEMENT; | ||
Array.prototype.reduce.call(lengthTrackingWithOffset, ResizeMidIteration, 'initial value'); | ||
assert.compareArray(values, [ | ||
4 | ||
]); | ||
} |