-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #13465 PR-URL: #13467 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
- Loading branch information
Showing
3 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
const { MAX_LENGTH, MAX_STRING_LENGTH } = require('buffer').constants; | ||
|
||
assert.strictEqual(typeof MAX_LENGTH, 'number'); | ||
assert.strictEqual(typeof MAX_STRING_LENGTH, 'number'); | ||
assert(MAX_STRING_LENGTH <= MAX_LENGTH); | ||
assert.throws(() => ' '.repeat(MAX_STRING_LENGTH + 1), | ||
/^RangeError: Invalid string length$/); | ||
|
||
assert.doesNotThrow(() => ' '.repeat(MAX_STRING_LENGTH)); |