mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
a4fdb1abe0
V8 will soon support typed arrays as large as the maximum array buffer
length. This patch replaces hardcoded values related to
Buffer.kMaxLength with the actual constant.
It also fixes a test that was passing by accident.
Refs: 44b2995900
PR-URL: https://github.com/nodejs/node/pull/49876
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
26 lines
775 B
JavaScript
26 lines
775 B
JavaScript
'use strict';
|
|
require('../common');
|
|
|
|
// This test ensures that Node.js throws an Error when trying to convert a
|
|
// large buffer into a string.
|
|
// Regression test for https://github.com/nodejs/node/issues/649.
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
SlowBuffer,
|
|
constants: {
|
|
MAX_STRING_LENGTH,
|
|
},
|
|
} = require('buffer');
|
|
|
|
const len = MAX_STRING_LENGTH + 1;
|
|
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);
|