Skip to content

Commit b3e1523

Browse files
authored
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 274f4d6 commit b3e1523

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

test/parallel/test-buffer-alloc.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ const vm = require('vm');
66

77
const SlowBuffer = require('buffer').SlowBuffer;
88

9-
// Verify the maximum Uint8Array size. There is no concrete limit by spec. The
10-
// internal limits should be updated if this fails.
11-
assert.throws(
12-
() => new Uint8Array(2 ** 32 + 1),
13-
{ message: 'Invalid typed array length: 4294967297' }
14-
);
15-
169
const b = Buffer.allocUnsafe(1024);
1710
assert.strictEqual(b.length, 1024);
1811

test/parallel/test-buffer-over-max-length.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,8 @@ const bufferMaxSizeMsg = {
1212
name: 'RangeError',
1313
};
1414

15-
assert.throws(() => Buffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
16-
assert.throws(() => SlowBuffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
17-
assert.throws(() => Buffer.alloc((-1 >>> 0) + 2), bufferMaxSizeMsg);
18-
assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 2), bufferMaxSizeMsg);
19-
assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 2), bufferMaxSizeMsg);
20-
2115
assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
2216
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
2317
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg);
2418
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
2519
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);
26-
27-
// issue GH-4331
28-
assert.throws(() => Buffer.allocUnsafe(0x100000001), bufferMaxSizeMsg);
29-
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFFF), bufferMaxSizeMsg);

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@ require('../common');
88
const assert = require('assert');
99
const SlowBuffer = require('buffer').SlowBuffer;
1010

11-
const len = 1422561062959;
11+
// Find the maximum supported buffer length.
12+
let limit = 1 << 31; // 2GB
13+
while (true) {
14+
try {
15+
Buffer(limit);
16+
limit *= 2;
17+
} catch (e) {
18+
break;
19+
}
20+
}
21+
1222
const message = {
1323
code: 'ERR_OUT_OF_RANGE',
1424
name: 'RangeError',
1525
};
16-
assert.throws(() => Buffer(len).toString('utf8'), message);
17-
assert.throws(() => SlowBuffer(len).toString('utf8'), message);
18-
assert.throws(() => Buffer.alloc(len).toString('utf8'), message);
19-
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message);
20-
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);
26+
assert.throws(() => Buffer(limit).toString('utf8'), message);
27+
assert.throws(() => SlowBuffer(limit).toString('utf8'), message);
28+
assert.throws(() => Buffer.alloc(limit).toString('utf8'), message);
29+
assert.throws(() => Buffer.allocUnsafe(limit).toString('utf8'), message);
30+
assert.throws(() => Buffer.allocUnsafeSlow(limit).toString('utf8'), message);

0 commit comments

Comments
 (0)