options-maxbytelength-data-allocation-after-object-creation.js (1135B)
1 // Copyright (C) 2024 André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-arraybuffer-length 6 description: > 7 The new ArrayBuffer instance is created prior to allocating the Data Block. 8 info: | 9 ArrayBuffer ( length [ , options ] ) 10 11 ... 12 4. Return ? AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength). 13 14 AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] ) 15 16 ... 17 4. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBuffer.prototype%", slots). 18 5. Let block be ? CreateByteDataBlock(byteLength). 19 ... 20 21 features: [resizable-arraybuffer, Reflect.construct] 22 ---*/ 23 24 function DummyError() {} 25 26 let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", { 27 get() { 28 throw new DummyError(); 29 } 30 }); 31 32 assert.throws(DummyError, function() { 33 let byteLength = 0; 34 let options = { 35 maxByteLength: 7 * 1125899906842624 36 }; 37 38 // Allocating 7 PiB should fail with a RangeError. 39 // Math.pow(1024, 5) = 1125899906842624 40 Reflect.construct(ArrayBuffer, [], newTarget); 41 }); 42 43 reportCompare(0, 0);