options-maxbytelength-data-allocation-after-object-creation.js (1304B)
1 // |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally 2 // Copyright (C) 2024 André Bargull. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 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 ] ) 11 12 ... 13 4. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength, requestedMaxByteLength). 14 15 AllocateSharedArrayBuffer( constructor, byteLength ) 16 17 ... 18 5. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBuffer.prototype%", slots). 19 ... 20 7. Let block be ? CreateSharedByteDataBlock(allocLength). 21 ... 22 23 features: [SharedArrayBuffer, resizable-arraybuffer, Reflect.construct] 24 ---*/ 25 26 function DummyError() {} 27 28 let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", { 29 get() { 30 throw new DummyError(); 31 } 32 }); 33 34 assert.throws(DummyError, function() { 35 let byteLength = 0; 36 let options = { 37 maxByteLength: 7 * 1125899906842624 38 }; 39 40 // Allocating 7 PiB should fail with a RangeError. 41 // Math.pow(1024, 5) = 1125899906842624 42 Reflect.construct(SharedArrayBuffer, [], newTarget); 43 }); 44 45 reportCompare(0, 0);