const K_MAX_LENGTH = 0x7fffffff
exports.kMaxLength = K_MAX_LENGTH
+/**
+ * Not used internally, but exported to maintain api compatability
+ * Uses 32-bit implementation value from Node defined in String:kMaxLength
+ *
+ * @see https://github.com/nodejs/node/blob/main/deps/v8/include/v8-primitive.h#L126
+ * @see https://github.com/nodejs/node/blob/main/src/node_buffer.cc#L1298
+ * @see https://github.com/nodejs/node/blob/main/lib/buffer.js#L142
+ */
+const K_STRING_MAX_LENGTH = (1 << 28) - 16
+exports.kStringMaxLength = K_STRING_MAX_LENGTH
+
+exports.constants = {
+ MAX_LENGTH: K_MAX_LENGTH,
+ MAX_STRING_LENGTH: K_STRING_MAX_LENGTH
+}
+
/**
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
var common = { skip: function () {} };
var assert = require('assert');
+const buffer = require('../../');
var Buffer = require('../../').Buffer;
var SlowBuffer = require('../../').SlowBuffer;
{
// Bug regression test
var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語
- var buffer = new Buffer(32);
- var size = buffer.write(testValue, 0, 'utf8');
-// console.log('bytes written to buffer: ' + size);
- var slice = buffer.toString('utf8', 0, size);
+ var testBuffer = new Buffer(32);
+ var size = testBuffer.write(testValue, 0, 'utf8');
+// console.log('bytes written to testBuffer: ' + size);
+ var slice = testBuffer.toString('utf8', 0, size);
assert.equal(slice, testValue);
}
// GH-5110
{
- var buffer = new Buffer('test');
- var string = JSON.stringify(buffer);
+ var testBuffer = new Buffer('test');
+ var string = JSON.stringify(testBuffer);
assert.strictEqual(string, '{"type":"Buffer","data":[116,101,115,116]}');
- assert.deepStrictEqual(buffer, JSON.parse(string, function(key, value) {
+ assert.deepStrictEqual(testBuffer, JSON.parse(string, function(key, value) {
return value && value.type === 'Buffer'
? new Buffer(value.data)
: value;
assert.throws(() => Buffer(-1),
'"size" argument must not be negative');
+// Verify constants
+assert.equal(0x7fffffff, buffer.kMaxLength)
+assert.equal(buffer.kMaxLength, buffer.constants.MAX_LENGTH)
+
+assert.equal((1 << 28) - 16, buffer.kStringMaxLength)
+assert.equal(buffer.kStringMaxLength, buffer.constants.MAX_STRING_LENGTH)