options-maxbytelength-allocation-limit.js (1263B)
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 Throws a RangeError if the requested Data Block is too large. 8 info: | 9 ArrayBuffer ( length [ , options ] ) 10 11 ... 12 4. Return ? AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength). 13 14 AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] ) 15 16 ... 17 5. Let block be ? CreateByteDataBlock(byteLength). 18 ... 19 20 CreateByteDataBlock ( size ) 21 22 ... 23 2. Let db be a new Data Block value consisting of size bytes. If it is 24 impossible to create such a Data Block, throw a RangeError exception. 25 ... 26 27 features: [resizable-arraybuffer] 28 ---*/ 29 30 assert.throws(RangeError, function() { 31 // Allocating 7 PiB should fail with a RangeError. 32 // Math.pow(1024, 5) = 1125899906842624 33 new ArrayBuffer(0, {maxByteLength: 7 * 1125899906842624}); 34 }, "`maxByteLength` option is 7 PiB"); 35 36 assert.throws(RangeError, function() { 37 // Allocating almost 8 PiB should fail with a RangeError. 38 // Math.pow(2, 53) = 9007199254740992 39 new ArrayBuffer(0, {maxByteLength: 9007199254740992 - 1}); 40 }, "`maxByteLength` option is Math.pow(2, 53) - 1"); 41 42 reportCompare(0, 0);