-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: rename validateSafeInteger to validateInteger
validateInteger() was renamed to validateSafeInteger() in #26572. However, this function also works with unsafe integers. This commit restores the old name, and adds some basic tests. PR-URL: #29184 Refs: #26572 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
- Loading branch information
Showing
5 changed files
with
41 additions
and
16 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
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,25 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
const common = require('../common'); | ||
const { | ||
validateInteger | ||
} = require('internal/validators'); | ||
const { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } = Number; | ||
const outOfRangeError = { | ||
code: 'ERR_OUT_OF_RANGE', | ||
type: RangeError | ||
}; | ||
|
||
// validateInteger() defaults to validating safe integers. | ||
validateInteger(MAX_SAFE_INTEGER, 'foo'); | ||
validateInteger(MIN_SAFE_INTEGER, 'foo'); | ||
common.expectsError(() => { | ||
validateInteger(MAX_SAFE_INTEGER + 1, 'foo'); | ||
}, outOfRangeError); | ||
common.expectsError(() => { | ||
validateInteger(MIN_SAFE_INTEGER - 1, 'foo'); | ||
}, outOfRangeError); | ||
|
||
// validateInteger() works with unsafe integers. | ||
validateInteger(MAX_SAFE_INTEGER + 1, 'foo', 0, MAX_SAFE_INTEGER + 1); | ||
validateInteger(MIN_SAFE_INTEGER - 1, 'foo', MIN_SAFE_INTEGER - 1); |