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 <[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]>
  • 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.