summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/staging/ArrayBuffer/resizable/find-grow-mid-iteration-strict.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--js/src/tests/test262/staging/ArrayBuffer/resizable/find-grow-mid-iteration-strict.js153
1 files changed, 153 insertions, 0 deletions
diff --git a/js/src/tests/test262/staging/ArrayBuffer/resizable/find-grow-mid-iteration-strict.js b/js/src/tests/test262/staging/ArrayBuffer/resizable/find-grow-mid-iteration-strict.js
new file mode 100644
index 0000000000..ec36398067
--- /dev/null
+++ b/js/src/tests/test262/staging/ArrayBuffer/resizable/find-grow-mid-iteration-strict.js
@@ -0,0 +1,153 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+'use strict';
+// Copyright 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-arraybuffer-length
+description: >
+ Automatically ported from FindGrowMidIteration test
+ in V8's mjsunit test typedarray-resizablearraybuffer.js
+includes: [compareArray.js]
+features: [resizable-arraybuffer]
+flags: [onlyStrict]
+---*/
+
+class MyUint8Array extends Uint8Array {
+}
+
+class MyFloat32Array extends Float32Array {
+}
+
+class MyBigInt64Array extends BigInt64Array {
+}
+
+const builtinCtors = [
+ Uint8Array,
+ Int8Array,
+ Uint16Array,
+ Int16Array,
+ Uint32Array,
+ Int32Array,
+ Float32Array,
+ Float64Array,
+ Uint8ClampedArray,
+ BigUint64Array,
+ BigInt64Array
+];
+
+const ctors = [
+ ...builtinCtors,
+ MyUint8Array,
+ MyFloat32Array,
+ MyBigInt64Array
+];
+
+function CreateResizableArrayBuffer(byteLength, maxByteLength) {
+ return new ArrayBuffer(byteLength, { maxByteLength: maxByteLength });
+}
+
+function WriteToTypedArray(array, index, value) {
+ if (array instanceof BigInt64Array || array instanceof BigUint64Array) {
+ array[index] = BigInt(value);
+ } else {
+ array[index] = value;
+ }
+}
+
+function TypedArrayFindHelper(ta, p) {
+ return ta.find(p);
+}
+
+function ArrayFindHelper(ta, p) {
+ return Array.prototype.find.call(ta, p);
+}
+
+function FindGrowMidIteration(findHelper) {
+ // 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 false;
+ }
+ for (let ctor of ctors) {
+ rab = CreateRabForTest(ctor);
+ const fixedLength = new ctor(rab, 0, 4);
+ values = [];
+ resizeAfter = 2;
+ resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
+ assert.sameValue(findHelper(fixedLength, CollectValuesAndResize), undefined);
+ assert.compareArray(values, [
+ 0,
+ 2,
+ 4,
+ 6
+ ]);
+ }
+ for (let ctor of ctors) {
+ rab = CreateRabForTest(ctor);
+ const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
+ values = [];
+ resizeAfter = 1;
+ resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
+ assert.sameValue(findHelper(fixedLengthWithOffset, CollectValuesAndResize), undefined);
+ assert.compareArray(values, [
+ 4,
+ 6
+ ]);
+ }
+ for (let ctor of ctors) {
+ rab = CreateRabForTest(ctor);
+ const lengthTracking = new ctor(rab, 0);
+ values = [];
+ resizeAfter = 2;
+ resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
+ assert.sameValue(findHelper(lengthTracking, CollectValuesAndResize), undefined);
+ assert.compareArray(values, [
+ 0,
+ 2,
+ 4,
+ 6
+ ]);
+ }
+ for (let ctor of ctors) {
+ rab = CreateRabForTest(ctor);
+ const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
+ values = [];
+ resizeAfter = 1;
+ resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
+ assert.sameValue(findHelper(lengthTrackingWithOffset, CollectValuesAndResize), undefined);
+ assert.compareArray(values, [
+ 4,
+ 6
+ ]);
+ }
+}
+
+FindGrowMidIteration(TypedArrayFindHelper);
+FindGrowMidIteration(ArrayFindHelper);
+
+reportCompare(0, 0);