mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 17:01:08 +00:00

Remove instances where `--expose-internals` is used to gain access to buffer.kStringMaxLength. The property is availalble without a flag. It is undocumented but the same as the documented `buffer.constants.MAX_STRING_LENGTH` so use that. (We even have a test that confirms that they are the same value.) PR-URL: https://github.com/nodejs/node/pull/25309 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
30 lines
963 B
JavaScript
30 lines
963 B
JavaScript
'use strict';
|
|
|
|
const common = require('../../common');
|
|
const skipMessage = 'intensive toString tests due to memory confinements';
|
|
if (!common.enoughTestMem)
|
|
common.skip(skipMessage);
|
|
|
|
const binding = require(`./build/${common.buildType}/binding`);
|
|
const assert = require('assert');
|
|
|
|
// v8 fails silently if string length > v8::String::kMaxLength
|
|
// v8::String::kMaxLength defined in v8.h
|
|
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
|
|
|
|
let buf;
|
|
try {
|
|
buf = Buffer.allocUnsafe(kStringMaxLength);
|
|
} catch (e) {
|
|
// If the exception is not due to memory confinement then rethrow it.
|
|
if (e.message !== 'Array buffer allocation failed') throw (e);
|
|
common.skip(skipMessage);
|
|
}
|
|
|
|
// Ensure we have enough memory available for future allocations to succeed.
|
|
if (!binding.ensureAllocation(2 * kStringMaxLength))
|
|
common.skip(skipMessage);
|
|
|
|
const maxString = buf.toString('latin1');
|
|
assert.strictEqual(maxString.length, kStringMaxLength);
|