-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buffer: check INSPECT_MAX_BYTES with validateNumber
PR-URL: #46599 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const buffer = require('buffer'); | ||
|
||
const rangeErrorObjs = [NaN, -1]; | ||
const typeErrorObj = 'and even this'; | ||
|
||
for (const obj of rangeErrorObjs) { | ||
assert.throws( | ||
() => buffer.INSPECT_MAX_BYTES = obj, | ||
{ | ||
code: 'ERR_OUT_OF_RANGE', | ||
name: 'RangeError', | ||
} | ||
); | ||
|
||
assert.throws( | ||
() => buffer.INSPECT_MAX_BYTES = obj, | ||
{ | ||
code: 'ERR_OUT_OF_RANGE', | ||
name: 'RangeError', | ||
} | ||
); | ||
} | ||
|
||
assert.throws( | ||
() => buffer.INSPECT_MAX_BYTES = typeErrorObj, | ||
{ | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError', | ||
} | ||
); |