Skip to content

Commit bddfe60

Browse files
victorgomespthier
authored andcommitted
Adapt tests for increased TypedArray sizes (#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.
1 parent 0381d91 commit bddfe60

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

test/parallel/test-buffer-alloc.js

Lines changed: 3 additions & 0 deletions
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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,23 @@ const {
1818
},
1919
} = require('buffer');
2020

21-
const len = MAX_STRING_LENGTH + 1;
22-
const message = {
23-
code: 'ERR_STRING_TOO_LONG',
24-
name: 'Error',
25-
};
26-
27-
function test(getBuffer) {
28-
let buf;
21+
// Find the maximum supported buffer length.
22+
let limit = 1 << 31; // 2GB
23+
while (true) {
2924
try {
30-
buf = getBuffer();
25+
Buffer(limit);
26+
limit *= 2;
3127
} catch (e) {
32-
// If the buffer allocation fails, we skip the test.
33-
if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED' || /Array buffer allocation failed/.test(e.message)) {
34-
return;
35-
}
28+
break;
3629
}
37-
assert.throws(() => { buf.toString('utf8'); }, message);
3830
}
3931

40-
test(() => Buffer(len));
41-
test(() => Buffer.alloc(len));
42-
test(() => Buffer.allocUnsafe(len));
43-
test(() => Buffer.allocUnsafeSlow(len));
32+
const message = {
33+
code: 'ERR_STRING_TOO_LONG',
34+
name: 'Error',
35+
};
36+
assert.throws(() => Buffer(limit).toString('utf8'), message);
37+
assert.throws(() => SlowBuffer(limit).toString('utf8'), message);
38+
assert.throws(() => Buffer.alloc(limit).toString('utf8'), message);
39+
assert.throws(() => Buffer.allocUnsafe(limit).toString('utf8'), message);
40+
assert.throws(() => Buffer.allocUnsafeSlow(limit).toString('utf8'), message);

0 commit comments

Comments
 (0)