mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
buffer: add constants object
Add `buffer.constants`, containing length limits for `Buffer` and `string` instances. This could be useful for programmers to tell whether a value can be turned into a string or not. Ref: https://github.com/nodejs/node/issues/13465 PR-URL: https://github.com/nodejs/node/pull/13467 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
50d151578d
commit
1e2905f46a
3 changed files with 85 additions and 12 deletions
|
@ -42,8 +42,31 @@ Buffer.prototype = FastBuffer.prototype;
|
|||
exports.Buffer = Buffer;
|
||||
exports.SlowBuffer = SlowBuffer;
|
||||
exports.INSPECT_MAX_BYTES = 50;
|
||||
|
||||
// Legacy.
|
||||
exports.kMaxLength = binding.kMaxLength;
|
||||
|
||||
const constants = Object.defineProperties({}, {
|
||||
MAX_LENGTH: {
|
||||
value: binding.kStringMaxLength,
|
||||
writable: false,
|
||||
enumerable: true
|
||||
},
|
||||
MAX_STRING_LENGTH: {
|
||||
value: binding.kStringMaxLength,
|
||||
writable: false,
|
||||
enumerable: true
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(exports, 'constants', {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
value: constants
|
||||
});
|
||||
|
||||
exports.kStringMaxLength = binding.kStringMaxLength;
|
||||
|
||||
const kFromErrorMsg = 'First argument must be a string, Buffer, ' +
|
||||
'ArrayBuffer, Array, or array-like object.';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue