Skip to content

Commit

Permalink
Adapt tests for increased TypedArray sizes (nodejs#161)
Browse files Browse the repository at this point in the history
V8 will increase the maximum TypedArray size in
https://crrev.com/c/4872536; this CL adapts the tests to allow for that.

Tests that hard-code smaller sizes or are already tested in V8 are
removed; one test is adapted to not rely on a specific limit.
# Conflicts:
#	test/parallel/test-buffer-alloc.js
#	test/parallel/test-buffer-tostring-rangeerror.js
  • Loading branch information
victorgomes committed Apr 23, 2024
1 parent 7b7365a commit 5413b21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ const {
kMaxLength,
} = require('buffer');

<<<<<<< HEAD
// Verify the maximum Uint8Array size. There is no concrete limit by spec. The
// internal limits should be updated if this fails.
assert.throws(
() => new Uint8Array(kMaxLength + 1),
{ message: `Invalid typed array length: ${kMaxLength + 1}` },
);

=======
>>>>>>> b3e1523f34 (Adapt tests for increased TypedArray sizes (#161))
const b = Buffer.allocUnsafe(1024);
assert.strictEqual(b.length, 1024);

Expand Down
22 changes: 16 additions & 6 deletions test/parallel/test-buffer-tostring-rangeerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ const {
},
} = require('buffer');

const len = MAX_STRING_LENGTH + 1;
// Find the maximum supported buffer length.
let limit = 1 << 31; // 2GB
while (true) {
try {
Buffer(limit);
limit *= 2;
} catch (e) {
break;
}
}

const message = {
code: 'ERR_STRING_TOO_LONG',
name: 'Error',
};
assert.throws(() => Buffer(len).toString('utf8'), message);
assert.throws(() => SlowBuffer(len).toString('utf8'), message);
assert.throws(() => Buffer.alloc(len).toString('utf8'), message);
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message);
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);
assert.throws(() => Buffer(limit).toString('utf8'), message);
assert.throws(() => SlowBuffer(limit).toString('utf8'), message);
assert.throws(() => Buffer.alloc(limit).toString('utf8'), message);
assert.throws(() => Buffer.allocUnsafe(limit).toString('utf8'), message);
assert.throws(() => Buffer.allocUnsafeSlow(limit).toString('utf8'), message);

0 comments on commit 5413b21

Please sign in to comment.