Skip to content

Commit

Permalink
lib: use Number.parseFloat from primordials
Browse files Browse the repository at this point in the history
PR-URL: #35499
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
  • Loading branch information
targos authored and BethGriggs committed Oct 13, 2020
1 parent 5d727f0 commit 7e8fdd3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/.eslintrc.yaml
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/util/inspect.js
Expand Up @@ -29,6 +29,7 @@ const {
MathSqrt,
Number,
NumberIsNaN,
NumberParseFloat,
NumberParseInt,
NumberPrototypeValueOf,
Object,
Expand Down Expand Up @@ -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'
Expand Down
10 changes: 7 additions & 3 deletions lib/repl.js
Expand Up @@ -46,6 +46,7 @@ const {
Error,
MathMax,
NumberIsNaN,
NumberParseFloat,
ObjectAssign,
ObjectCreate,
ObjectDefineProperty,
Expand All @@ -58,7 +59,9 @@ const {
PromiseRace,
RegExp,
Set,
StringPrototypeCharAt,
StringPrototypeIncludes,
StringPrototypeMatch,
Symbol,
SyntaxError,
SyntaxErrorPrototype,
Expand Down Expand Up @@ -791,9 +794,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) {
Expand Down

0 comments on commit 7e8fdd3

Please sign in to comment.