Debian Codegraph @

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

raw
1 // |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally
2 // Copyright (C) 2015 André Bargull. All rights reserved.
3 // Copyright (C) 2017 Mozilla Corporation. All rights reserved.
4 // This code is governed by the BSD license found in the LICENSE file.
5
6 /*---
7 esid: sec-sharedarraybuffer-length
8 description: >
9 Throws a RangeError if requested Data Block is too large.
10 info: |
11 SharedArrayBuffer( length )
12
13 ...
14 3. Return AllocateSharedArrayBuffer(NewTarget, byteLength).
15
16 6.2.7.2 CreateSharedByteDataBlock(size)
17 ...
18 2. Let db be a new Shared Data Block value consisting of size
19 bytes. If it is impossible to create such a Shared Data Block,
20 throw a RangeError exception.
21 ...
22 features: [SharedArrayBuffer]
23 ---*/
24
25 assert.throws(RangeError, function() {
26 // Allocating 7 PiB should fail with a RangeError.
27 // Math.pow(1024, 5) = 1125899906842624
28 new SharedArrayBuffer(7 * 1125899906842624);
29 }, "`length` parameter is 7 PiB");
30
31 assert.throws(RangeError, function() {
32 // Allocating almost 8 PiB should fail with a RangeError.
33 // Math.pow(2, 53) = 9007199254740992
34 new SharedArrayBuffer(9007199254740992 - 1);
35 }, "`length` parameter is Math.pow(2, 53) - 1");
36
37 reportCompare(0, 0);