summaryrefslogtreecommitdiff
path: root/lib/internal/util/inspect.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-04-30 19:04:55 +0200
committerRich Trott <rtrott@gmail.com>2019-05-02 22:21:11 -0700
commit8dae89b396df64e6a9e44cb94efe27809a5a3d89 (patch)
treebf340d5214f3268e42e7b632aad6156e5ca9c294 /lib/internal/util/inspect.js
parentc903c99d4bac9e13a34e97a4a98bd290925fda68 (diff)
downloadandroid-node-v8-8dae89b396df64e6a9e44cb94efe27809a5a3d89.tar.gz
android-node-v8-8dae89b396df64e6a9e44cb94efe27809a5a3d89.tar.bz2
android-node-v8-8dae89b396df64e6a9e44cb94efe27809a5a3d89.zip
util: better number formatters
This makes sure the `%d`, `%f`, `%i` and `%s` formatters properly visualize `-0`. On top, this also switches to using a safer symbol toString function by using the primordial function. PR-URL: https://github.com/nodejs/node/pull/27499 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/internal/util/inspect.js')
-rw-r--r--lib/internal/util/inspect.js17
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 8ffa303268..22dec67330 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -1078,7 +1078,7 @@ function formatPrimitive(fn, value, ctx) {
if (typeof value === 'undefined')
return fn('undefined', 'undefined');
// es6 symbol primitive
- return fn(value.toString(), 'symbol');
+ return fn(SymbolPrototype.toString(value), 'symbol');
}
function formatNamespaceObject(ctx, value, recurseTimes, keys) {
@@ -1484,9 +1484,8 @@ function reduceToSingleString(
return `${braces[0]}${ln}${join(output, `,\n${indentation} `)} ${braces[1]}`;
}
-const emptyOptions = {};
function format(...args) {
- return formatWithOptions(emptyOptions, ...args);
+ return formatWithOptions(undefined, ...args);
}
@@ -1532,16 +1531,14 @@ function formatWithOptions(inspectOptions, ...args) {
switch (nextChar) {
case 115: // 's'
const tempArg = args[++a];
- if (typeof tempArg === 'object' && tempArg !== null) {
+ if (typeof tempArg !== 'string' &&
+ typeof tempArg !== 'function') {
tempStr = inspect(tempArg, {
...inspectOptions,
compact: 3,
colors: false,
depth: 0
});
- // eslint-disable-next-line valid-typeof
- } else if (typeof tempArg === 'bigint') {
- tempStr = `${tempArg}n`;
} else {
tempStr = String(tempArg);
}
@@ -1557,7 +1554,7 @@ function formatWithOptions(inspectOptions, ...args) {
} else if (typeof tempNum === 'symbol') {
tempStr = 'NaN';
} else {
- tempStr = `${Number(tempNum)}`;
+ tempStr = formatNumber(stylizeNoColor, Number(tempNum));
}
break;
case 79: // 'O'
@@ -1581,7 +1578,7 @@ function formatWithOptions(inspectOptions, ...args) {
} else if (typeof tempInteger === 'symbol') {
tempStr = 'NaN';
} else {
- tempStr = `${parseInt(tempInteger)}`;
+ tempStr = formatNumber(stylizeNoColor, parseInt(tempInteger));
}
break;
case 102: // 'f'
@@ -1589,7 +1586,7 @@ function formatWithOptions(inspectOptions, ...args) {
if (typeof tempFloat === 'symbol') {
tempStr = 'NaN';
} else {
- tempStr = `${parseFloat(tempFloat)}`;
+ tempStr = formatNumber(stylizeNoColor, parseFloat(tempFloat));
}
break;
case 37: // '%'