mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00

validateInteger() was renamed to validateSafeInteger() in https://github.com/nodejs/node/pull/26572. However, this function also works with unsafe integers. This commit restores the old name, and adds some basic tests. PR-URL: https://github.com/nodejs/node/pull/29184 Refs: https://github.com/nodejs/node/pull/26572 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
26 lines
800 B
JavaScript
26 lines
800 B
JavaScript
// 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);
|