From 9df61b367137ce578645831a7d0877fccab541d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 28 Sep 2020 16:42:29 +0200 Subject: [PATCH] lib: use Number.parseFloat from primordials PR-URL: https://github.com/nodejs/node/pull/35499 Reviewed-By: Joyee Cheung Reviewed-By: Benjamin Gruenbaum Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Ujjwal Sharma Reviewed-By: Shingo Inoue --- lib/.eslintrc.yaml | 2 ++ lib/internal/util/inspect.js | 4 +++- lib/repl.js | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 29099193bb089e..35ced9e9011016 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -71,6 +71,8 @@ rules: message: "Use `const { WeakMap } = primordials;` instead of the global." - name: WeakSet message: "Use `const { WeakSet } = primordials;` instead of the global." + - name: parseFloat + message: "Use `const { NumberParseFloat } = primordials;` instead of the global." - name: parseInt message: "Use `const { NumberParseInt } = primordials;` instead of the global." no-restricted-syntax: diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index f4584bd84098d2..17768dfb53bf0c 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -29,6 +29,7 @@ const { MathSqrt, Number, NumberIsNaN, + NumberParseFloat, NumberParseInt, NumberPrototypeValueOf, Object, @@ -1960,7 +1961,8 @@ function formatWithOptionsInternal(inspectOptions, ...args) { if (typeof tempFloat === 'symbol') { tempStr = 'NaN'; } else { - tempStr = formatNumber(stylizeNoColor, parseFloat(tempFloat)); + tempStr = formatNumber(stylizeNoColor, + NumberParseFloat(tempFloat)); } break; case 99: // 'c' diff --git a/lib/repl.js b/lib/repl.js index 6d8b98b94825c5..78c256d60b5559 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -46,6 +46,7 @@ const { Error, MathMax, NumberIsNaN, + NumberParseFloat, ObjectAssign, ObjectCreate, ObjectDefineProperty, @@ -58,7 +59,9 @@ const { PromiseRace, RegExp, Set, + StringPrototypeCharAt, StringPrototypeIncludes, + StringPrototypeMatch, Symbol, SyntaxError, SyntaxErrorPrototype, @@ -767,9 +770,10 @@ function REPLServer(prompt, // Check to see if a REPL keyword was used. If it returns true, // display next prompt and return. if (trimmedCmd) { - if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) !== '.' && - NumberIsNaN(parseFloat(trimmedCmd))) { - const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/); + if (StringPrototypeCharAt(trimmedCmd, 0) === '.' && + StringPrototypeCharAt(trimmedCmd, 1) !== '.' && + NumberIsNaN(NumberParseFloat(trimmedCmd))) { + const matches = StringPrototypeMatch(trimmedCmd, /^\.([^\s]+)\s*(.*)$/); const keyword = matches && matches[1]; const rest = matches && matches[2]; if (_parseREPLKeyword.call(self, keyword, rest) === true) {