Skip to content

Commit 5413b21

Browse files
committed
Adapt tests for increased TypedArray sizes (nodejs#161)
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
1 parent 7b7365a commit 5413b21

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

test/parallel/test-buffer-alloc.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ const {
99
kMaxLength,
1010
} = require('buffer');
1111

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

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

test/parallel/test-buffer-tostring-rangeerror.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@ const {
1313
},
1414
} = require('buffer');
1515

16-
const len = MAX_STRING_LENGTH + 1;
16+
// Find the maximum supported buffer length.
17+
let limit = 1 << 31; // 2GB
18+
while (true) {
19+
try {
20+
Buffer(limit);
21+
limit *= 2;
22+
} catch (e) {
23+
break;
24+
}
25+
}
26+
1727
const message = {
1828
code: 'ERR_STRING_TOO_LONG',
1929
name: 'Error',
2030
};
21-
assert.throws(() => Buffer(len).toString('utf8'), message);
22-
assert.throws(() => SlowBuffer(len).toString('utf8'), message);
23-
assert.throws(() => Buffer.alloc(len).toString('utf8'), message);
24-
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message);
25-
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);
31+
assert.throws(() => Buffer(limit).toString('utf8'), message);
32+
assert.throws(() => SlowBuffer(limit).toString('utf8'), message);
33+
assert.throws(() => Buffer.alloc(limit).toString('utf8'), message);
34+
assert.throws(() => Buffer.allocUnsafe(limit).toString('utf8'), message);
35+
assert.throws(() => Buffer.allocUnsafeSlow(limit).toString('utf8'), message);

0 commit comments

Comments
 (0)