summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/staging/ArrayBuffer/resizable/fill-parameter-conversion-resizes-strict.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--js/src/tests/test262/staging/ArrayBuffer/resizable/fill-parameter-conversion-resizes-strict.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/js/src/tests/test262/staging/ArrayBuffer/resizable/fill-parameter-conversion-resizes-strict.js b/js/src/tests/test262/staging/ArrayBuffer/resizable/fill-parameter-conversion-resizes-strict.js
new file mode 100644
index 0000000000..3544bc20ed
--- /dev/null
+++ b/js/src/tests/test262/staging/ArrayBuffer/resizable/fill-parameter-conversion-resizes-strict.js
@@ -0,0 +1,97 @@
+// |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 FillParameterConversionResizes test
+ in V8's mjsunit test typedarray-resizablearraybuffer.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 TypedArrayFillHelper(ta, n, start, end) {
+ if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) {
+ ta.fill(BigInt(n), start, end);
+ } else {
+ ta.fill(n, start, end);
+ }
+}
+
+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 evil = {
+ valueOf: () => {
+ rab.resize(2 * ctor.BYTES_PER_ELEMENT);
+ return 3;
+ }
+ };
+ assert.throws(TypeError, () => {
+ TypedArrayFillHelper(fixedLength, evil, 1, 2);
+ });
+}
+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 evil = {
+ valueOf: () => {
+ rab.resize(2 * ctor.BYTES_PER_ELEMENT);
+ return 1;
+ }
+ };
+ assert.throws(TypeError, () => {
+ TypedArrayFillHelper(fixedLength, 3, evil, 2);
+ });
+}
+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 evil = {
+ valueOf: () => {
+ rab.resize(2 * ctor.BYTES_PER_ELEMENT);
+ return 2;
+ }
+ };
+ assert.throws(TypeError, () => {
+ TypedArrayFillHelper(fixedLength, 3, 1, evil);
+ });
+}
+
+reportCompare(0, 0);