Skip to content

Commit 7e8fdd3

Browse files
targosBethGriggs
authored andcommitted
lib: use Number.parseFloat from primordials
PR-URL: #35499 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Shingo Inoue <[email protected]>
1 parent 5d727f0 commit 7e8fdd3

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ rules:
7171
message: "Use `const { WeakMap } = primordials;` instead of the global."
7272
- name: WeakSet
7373
message: "Use `const { WeakSet } = primordials;` instead of the global."
74+
- name: parseFloat
75+
message: "Use `const { NumberParseFloat } = primordials;` instead of the global."
7476
- name: parseInt
7577
message: "Use `const { NumberParseInt } = primordials;` instead of the global."
7678
no-restricted-syntax:

lib/internal/util/inspect.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
MathSqrt,
3030
Number,
3131
NumberIsNaN,
32+
NumberParseFloat,
3233
NumberParseInt,
3334
NumberPrototypeValueOf,
3435
Object,
@@ -1960,7 +1961,8 @@ function formatWithOptionsInternal(inspectOptions, ...args) {
19601961
if (typeof tempFloat === 'symbol') {
19611962
tempStr = 'NaN';
19621963
} else {
1963-
tempStr = formatNumber(stylizeNoColor, parseFloat(tempFloat));
1964+
tempStr = formatNumber(stylizeNoColor,
1965+
NumberParseFloat(tempFloat));
19641966
}
19651967
break;
19661968
case 99: // 'c'

lib/repl.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const {
4646
Error,
4747
MathMax,
4848
NumberIsNaN,
49+
NumberParseFloat,
4950
ObjectAssign,
5051
ObjectCreate,
5152
ObjectDefineProperty,
@@ -58,7 +59,9 @@ const {
5859
PromiseRace,
5960
RegExp,
6061
Set,
62+
StringPrototypeCharAt,
6163
StringPrototypeIncludes,
64+
StringPrototypeMatch,
6265
Symbol,
6366
SyntaxError,
6467
SyntaxErrorPrototype,
@@ -791,9 +794,10 @@ function REPLServer(prompt,
791794
// Check to see if a REPL keyword was used. If it returns true,
792795
// display next prompt and return.
793796
if (trimmedCmd) {
794-
if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) !== '.' &&
795-
NumberIsNaN(parseFloat(trimmedCmd))) {
796-
const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/);
797+
if (StringPrototypeCharAt(trimmedCmd, 0) === '.' &&
798+
StringPrototypeCharAt(trimmedCmd, 1) !== '.' &&
799+
NumberIsNaN(NumberParseFloat(trimmedCmd))) {
800+
const matches = StringPrototypeMatch(trimmedCmd, /^\.([^\s]+)\s*(.*)$/);
797801
const keyword = matches && matches[1];
798802
const rest = matches && matches[2];
799803
if (_parseREPLKeyword.call(self, keyword, rest) === true) {

0 commit comments

Comments
 (0)