summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/SharedArrayBuffer
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/SharedArrayBuffer')
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-allocation-limit.js41
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-compared-before-object-creation.js43
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-data-allocation-after-object-creation.js45
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/length.js11
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/name.js14
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/length.js11
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/name.js11
-rw-r--r--js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/not-a-constructor.js2
8 files changed, 154 insertions, 24 deletions
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-allocation-limit.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-allocation-limit.js
new file mode 100644
index 0000000000..4462981d9e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-allocation-limit.js
@@ -0,0 +1,41 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!this.hasOwnProperty('SharedArrayBuffer')||!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- SharedArrayBuffer,resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2024 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-sharedarraybuffer-length
+description: >
+ Throws a RangeError if the requested Data Block is too large.
+info: |
+ SharedArrayBuffer ( length [ , options ] )
+
+ ...
+ 4. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
+
+ AllocateSharedArrayBuffer ( constructor, byteLength [ , maxByteLength ] )
+
+ ...
+ 7. Let block be ? CreateSharedByteDataBlock(allocLength).
+ ...
+
+ CreateSharedByteDataBlock ( size )
+
+ 1. Let db be a new Shared Data Block value consisting of size bytes. If it is
+ impossible to create such a Shared Data Block, throw a RangeError exception.
+
+features: [SharedArrayBuffer, resizable-arraybuffer]
+---*/
+
+assert.throws(RangeError, function() {
+ // Allocating 7 PiB should fail with a RangeError.
+ // Math.pow(1024, 5) = 1125899906842624
+ new SharedArrayBuffer(0, {maxByteLength: 7 * 1125899906842624});
+}, "`maxByteLength` option is 7 PiB");
+
+assert.throws(RangeError, function() {
+ // Allocating almost 8 PiB should fail with a RangeError.
+ // Math.pow(2, 53) = 9007199254740992
+ new SharedArrayBuffer(0, {maxByteLength: 9007199254740992 - 1});
+}, "`maxByteLength` option is Math.pow(2, 53) - 1");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-compared-before-object-creation.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-compared-before-object-creation.js
new file mode 100644
index 0000000000..89544d6fa3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-compared-before-object-creation.js
@@ -0,0 +1,43 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!this.hasOwnProperty('SharedArrayBuffer')||!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- SharedArrayBuffer,resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2024 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-sharedarraybuffer-length
+description: >
+ The byteLength argument is validated before OrdinaryCreateFromConstructor.
+info: |
+ SharedArrayBuffer ( length [ , options ] )
+
+ ...
+ 4. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
+
+ AllocateSharedArrayBuffer ( constructor, byteLength [ , maxByteLength ] )
+
+ ...
+ 3. If allocatingGrowableBuffer is true, then
+ a. If byteLength > maxByteLength, throw a RangeError exception.
+ ...
+ 5. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBuffer.prototype%", slots).
+ ...
+
+features: [SharedArrayBuffer, resizable-arraybuffer, Reflect.construct]
+---*/
+
+let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", {
+ get() {
+ throw new Test262Error();
+ }
+});
+
+assert.throws(RangeError, function() {
+ let byteLength = 10;
+ let options = {
+ maxByteLength: 0,
+ };
+
+ // Throws a RangeError, because `byteLength` is larger than `options.maxByteLength`.
+ Reflect.construct(SharedArrayBuffer, [byteLength, options], newTarget);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-data-allocation-after-object-creation.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-data-allocation-after-object-creation.js
new file mode 100644
index 0000000000..58e9748609
--- /dev/null
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-data-allocation-after-object-creation.js
@@ -0,0 +1,45 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!this.hasOwnProperty('SharedArrayBuffer')||!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- SharedArrayBuffer,resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2024 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-sharedarraybuffer-length
+description: >
+ The new SharedArrayBuffer instance is created prior to allocating the Data Block.
+info: |
+ SharedArrayBuffer ( length [ , options ] )
+
+ ...
+ 4. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
+
+ AllocateSharedArrayBuffer( constructor, byteLength )
+
+ ...
+ 5. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBuffer.prototype%", slots).
+ ...
+ 7. Let block be ? CreateSharedByteDataBlock(allocLength).
+ ...
+
+features: [SharedArrayBuffer, resizable-arraybuffer, Reflect.construct]
+---*/
+
+function DummyError() {}
+
+let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", {
+ get() {
+ throw new DummyError();
+ }
+});
+
+assert.throws(DummyError, function() {
+ let byteLength = 0;
+ let options = {
+ maxByteLength: 7 * 1125899906842624
+ };
+
+ // Allocating 7 PiB should fail with a RangeError.
+ // Math.pow(1024, 5) = 1125899906842624
+ Reflect.construct(SharedArrayBuffer, [], newTarget);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/length.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/length.js
index 22a944cb3c..2133165fa9 100644
--- a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/length.js
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/length.js
@@ -12,10 +12,11 @@ features: [SharedArrayBuffer]
var desc = Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength");
-assert.sameValue(desc.get.length, 0);
-
-verifyNotEnumerable(desc.get, "length");
-verifyNotWritable(desc.get, "length");
-verifyConfigurable(desc.get, "length");
+verifyProperty(desc.get, "length", {
+ value: 0,
+ writable: false,
+ enumerable: false,
+ configurable: true
+});
reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/name.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/name.js
index 28dff46979..b5312ca087 100644
--- a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/name.js
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/byteLength/name.js
@@ -14,13 +14,11 @@ var descriptor = Object.getOwnPropertyDescriptor(
SharedArrayBuffer.prototype, 'byteLength'
);
-assert.sameValue(
- descriptor.get.name, 'get byteLength',
- 'The value of `descriptor.get.name` is `"get byteLength"`'
-);
-
-verifyNotEnumerable(descriptor.get, 'name');
-verifyNotWritable(descriptor.get, 'name');
-verifyConfigurable(descriptor.get, 'name');
+verifyProperty(descriptor.get, "name", {
+ value: "get byteLength",
+ writable: false,
+ enumerable: false,
+ configurable: true
+});
reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/length.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/length.js
index 6760427fb6..d9396865e1 100644
--- a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/length.js
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/length.js
@@ -24,10 +24,11 @@ includes: [propertyHelper.js]
features: [SharedArrayBuffer]
---*/
-assert.sameValue(SharedArrayBuffer.prototype.slice.length, 2);
-
-verifyNotEnumerable(SharedArrayBuffer.prototype.slice, "length");
-verifyNotWritable(SharedArrayBuffer.prototype.slice, "length");
-verifyConfigurable(SharedArrayBuffer.prototype.slice, "length");
+verifyProperty(SharedArrayBuffer.prototype.slice, "length", {
+ value: 2,
+ writable: false,
+ enumerable: false,
+ configurable: true
+});
reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/name.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/name.js
index a3407d4b8a..56b2c85c1b 100644
--- a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/name.js
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/name.js
@@ -21,10 +21,11 @@ includes: [propertyHelper.js]
features: [SharedArrayBuffer]
---*/
-assert.sameValue(SharedArrayBuffer.prototype.slice.name, "slice");
-
-verifyNotEnumerable(SharedArrayBuffer.prototype.slice, "name");
-verifyNotWritable(SharedArrayBuffer.prototype.slice, "name");
-verifyConfigurable(SharedArrayBuffer.prototype.slice, "name");
+verifyProperty(SharedArrayBuffer.prototype.slice, "name", {
+ value: "slice",
+ writable: false,
+ enumerable: false,
+ configurable: true
+});
reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/not-a-constructor.js b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/not-a-constructor.js
index 49713162b8..c12b163b0b 100644
--- a/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/not-a-constructor.js
+++ b/js/src/tests/test262/built-ins/SharedArrayBuffer/prototype/slice/not-a-constructor.js
@@ -30,7 +30,7 @@ assert.sameValue(
assert.throws(TypeError, () => {
let sab = new SharedArrayBuffer(1); new sab.slice();
-}, '`let sab = new SharedArrayBuffer(1); new sab.slice()` throws TypeError');
+});
reportCompare(0, 0);