Skip to content

Improve tests for CreateByteDataBlock #3826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions test/built-ins/ArrayBuffer/allocation-limit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2023 André Bargull, Deniz Eren Evrendilek. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
Expand All @@ -7,25 +7,29 @@ description: >
Throws a RangeError if requested Data Block is too large.
info: |
ArrayBuffer( length )
...
3. Return AllocateArrayBuffer(NewTarget, byteLength).

...
6. Return AllocateArrayBuffer(NewTarget, byteLength).

6.2.6.1 CreateByteDataBlock(size)
AllocateArrayBuffer ( constructor, byteLength )
...
2. Let block be ? CreateByteDataBlock(byteLength).
...

CreateByteDataBlock( size )
1. If size > 2**53 - 1, throw a RangeError exception.
2. Let db be a new Data Block value consisting of size bytes. If it is
impossible to create such a Data Block, throw a RangeError exception.
...
---*/

assert.throws(RangeError, function() {
// Allocating 7 PiB should fail with a RangeError.
// Math.pow(1024, 5) = 1125899906842624
new ArrayBuffer(7 * 1125899906842624);
}, "`length` parameter is 7 PiB");
// Allocating almost 8 PiB should fail with a RangeError.
// Math.pow(2, 53) = 9007199254740992
new ArrayBuffer(9007199254740992);
}, "`length` parameter is Math.pow(2, 53)");

assert.throws(RangeError, function() {
// Allocating almost 8 PiB should fail with a RangeError.
// Allocating over 8 PiB should fail with a RangeError.
// Math.pow(2, 53) = 9007199254740992
new ArrayBuffer(9007199254740992 - 1);
}, "`length` parameter is Math.pow(2, 53) - 1");
new ArrayBuffer(9007199254740992 + 2);
}, "`length` parameter is Math.pow(2, 53) + 2");