diff --git a/lib/buffer.js b/lib/buffer.js index 920f69b84f3713..5a0ca382fbf222 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -76,7 +76,7 @@ Buffer.prototype = FastBuffer.prototype; const constants = Object.defineProperties({}, { MAX_LENGTH: { - value: kStringMaxLength, + value: kMaxLength, writable: false, enumerable: true }, diff --git a/test/parallel/test-buffer-constants.js b/test/parallel/test-buffer-constants.js index 59f5b6d0deada4..820c8dc993ed8e 100644 --- a/test/parallel/test-buffer-constants.js +++ b/test/parallel/test-buffer-constants.js @@ -2,6 +2,7 @@ require('../common'); const assert = require('assert'); +const { kMaxLength, kStringMaxLength } = require('buffer'); const { MAX_LENGTH, MAX_STRING_LENGTH } = require('buffer').constants; assert.strictEqual(typeof MAX_LENGTH, 'number'); @@ -11,3 +12,7 @@ assert.throws(() => ' '.repeat(MAX_STRING_LENGTH + 1), /^RangeError: Invalid string length$/); assert.doesNotThrow(() => ' '.repeat(MAX_STRING_LENGTH)); + +// Legacy values match: +assert.strictEqual(kMaxLength, MAX_LENGTH); +assert.strictEqual(kStringMaxLength, MAX_STRING_LENGTH);