Backed out 2 changesets (bug 1888310, bug 1884625) for causing failures on browser_ap...
[gecko.git] / js / src / tests / test262 / built-ins / ArrayBuffer / options-maxbytelength-allocation-limit.js
blobe9c5b221d99208ed53d23253ee110b98aed09c16
1 // |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- 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-arraybuffer-length
7 description: >
8   Throws a RangeError if the requested Data Block is too large.
9 info: |
10   ArrayBuffer ( length [ , options ] )
12   ...
13   4. Return ? AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
15   AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] )
17   ...
18   5. Let block be ? CreateByteDataBlock(byteLength).
19   ...
21   CreateByteDataBlock ( size )
23   ...
24   2. Let db be a new Data Block value consisting of size bytes. If it is
25      impossible to create such a Data Block, throw a RangeError exception.
26   ...
28 features: [resizable-arraybuffer]
29 ---*/
31 assert.throws(RangeError, function() {
32   // Allocating 7 PiB should fail with a RangeError.
33   // Math.pow(1024, 5) = 1125899906842624
34   new ArrayBuffer(0, {maxByteLength: 7 * 1125899906842624});
35 }, "`maxByteLength` option is 7 PiB");
37 assert.throws(RangeError, function() {
38   // Allocating almost 8 PiB should fail with a RangeError.
39   // Math.pow(2, 53) = 9007199254740992
40   new ArrayBuffer(0, {maxByteLength: 9007199254740992 - 1});
41 }, "`maxByteLength` option is Math.pow(2, 53) - 1");
43 reportCompare(0, 0);