Debian Codegraph @

js/src/tests/test262/built-ins/SharedArrayBuffer/options-maxbytelength-allocation-limit.js

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