Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / SharedArrayBuffer / options-maxbytelength-data-allocation-after-object-creation.js
blob58e97486097b8268261f436c354a94ac9a3520ca
1 // |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
2 // Copyright (C) 2024 AndrĂ© Bargull. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-sharedarraybuffer-length
7 description: >
8   The new SharedArrayBuffer instance is created prior to allocating the Data Block.
9 info: |
10   SharedArrayBuffer ( length [ , options ] )
12   ...
13   4. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
15   AllocateSharedArrayBuffer( constructor, byteLength )
17   ...
18   5. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBuffer.prototype%", slots).
19   ...
20   7. Let block be ? CreateSharedByteDataBlock(allocLength).
21   ...
23 features: [SharedArrayBuffer, resizable-arraybuffer, Reflect.construct]
24 ---*/
26 function DummyError() {}
28 let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", {
29   get() {
30     throw new DummyError();
31   }
32 });
34 assert.throws(DummyError, function() {
35   let byteLength = 0;
36   let options = {
37     maxByteLength: 7 * 1125899906842624
38   };
40   // Allocating 7 PiB should fail with a RangeError.
41   // Math.pow(1024, 5) = 1125899906842624
42   Reflect.construct(SharedArrayBuffer, [], newTarget);
43 });
45 reportCompare(0, 0);