Skip to content

Commit

Permalink
test: update tests after increasing typed array size to 4GB
Browse files Browse the repository at this point in the history
  • Loading branch information
ktran authored and nodejs-ci committed Jun 24, 2020
1 parent 34d89e7 commit 90e7ed6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const common = require('../common');

const assert = require('assert');
const vm = require('vm');

Expand All @@ -8,8 +9,8 @@ const SlowBuffer = require('buffer').SlowBuffer;
// 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(2 ** 32),
{ message: 'Invalid typed array length: 4294967296' }
() => new Uint8Array(2 ** 32 + 1),
{ message: 'Invalid typed array length: 4294967297' }
);

const b = Buffer.allocUnsafe(1024);
Expand Down
13 changes: 7 additions & 6 deletions test/parallel/test-buffer-over-max-length.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
require('../common');

const assert = require('assert');

const buffer = require('buffer');
Expand All @@ -12,11 +13,11 @@ const bufferMaxSizeMsg = {
message: /^The value "[^"]*" is invalid for option "size"$/
};

assert.throws(() => Buffer((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.alloc((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
assert.throws(() => Buffer.alloc((-1 >>> 0) + 2), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 2), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 2), bufferMaxSizeMsg);

assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
Expand All @@ -25,5 +26,5 @@ assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);

// issue GH-4331
assert.throws(() => Buffer.allocUnsafe(0x100000000), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafe(0x100000001), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFFF), bufferMaxSizeMsg);

0 comments on commit 90e7ed6

Please sign in to comment.