mirror of
https://github.com/zebrajr/node.git
synced 2025-12-07 12:20:50 +01:00
Several changes:
* Soft-Deprecate Buffer() constructors
* Add `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`
* Add `--zero-fill-buffers` command line option
* Add byteOffset and length to `new Buffer(arrayBuffer)` constructor
* buffer.fill('') previously had no effect, now zero-fills
* Update the docs
PR-URL: https://github.com/nodejs/node/pull/4682
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
33 lines
986 B
JavaScript
33 lines
986 B
JavaScript
'use strict';
|
|
// Flags: --expose-gc
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
// v8 fails silently if string length > v8::String::kMaxLength
|
|
// v8::String::kMaxLength defined in v8.h
|
|
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
|
|
|
|
const skipMessage =
|
|
'1..0 # Skipped: intensive toString tests due to memory confinements';
|
|
if (!common.enoughTestMem) {
|
|
console.log(skipMessage);
|
|
return;
|
|
}
|
|
assert(typeof gc === 'function', 'Run this test with --expose-gc');
|
|
|
|
try {
|
|
var buf = Buffer.allocUnsafe(kStringMaxLength);
|
|
// Try to allocate memory first then force gc so future allocations succeed.
|
|
Buffer.allocUnsafe(2 * kStringMaxLength);
|
|
gc();
|
|
} catch (e) {
|
|
// If the exception is not due to memory confinement then rethrow it.
|
|
if (e.message !== 'Array buffer allocation failed') throw (e);
|
|
console.log(skipMessage);
|
|
return;
|
|
}
|
|
|
|
const maxString = buf.toString('binary');
|
|
assert.equal(maxString.length, kStringMaxLength);
|