diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-10-17 09:45:11 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-12-03 12:34:42 +0100 |
commit | 1fe824bcbb0267265a8ccdb7301b7b8e3e8779f3 (patch) | |
tree | fbd81738dce5338f0ef863bc34e5cb08df9f3449 /lib | |
parent | f8f96017e82abe4e965251b2f6072bdb6bea9d51 (diff) | |
download | android-node-v8-1fe824bcbb0267265a8ccdb7301b7b8e3e8779f3.tar.gz android-node-v8-1fe824bcbb0267265a8ccdb7301b7b8e3e8779f3.tar.bz2 android-node-v8-1fe824bcbb0267265a8ccdb7301b7b8e3e8779f3.zip |
util,console: handle symbols as defined in the spec
The `console` functions rely on the `util.format()` behavior. It
did not follow the whatwg spec when it comes to symbols in combination
with the %d, %i and %f format specifiers. Using a symbol argument in
combination with one of these specifiers resulted in an error instead
of returning `'NaN'`. This is now fixed by this patch.
PR-URL: https://github.com/nodejs/node/pull/23708
Refs: https://console.spec.whatwg.org/#formatter
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/util.js b/lib/util.js index 22c2b260da..63b34f48bf 100644 --- a/lib/util.js +++ b/lib/util.js @@ -114,6 +114,8 @@ function formatWithOptions(inspectOptions, ...args) { // eslint-disable-next-line valid-typeof if (typeof tempNum === 'bigint') { tempStr = `${tempNum}n`; + } else if (typeof tempNum === 'symbol') { + tempStr = 'NaN'; } else { tempStr = `${Number(tempNum)}`; } @@ -136,12 +138,19 @@ function formatWithOptions(inspectOptions, ...args) { // eslint-disable-next-line valid-typeof if (typeof tempInteger === 'bigint') { tempStr = `${tempInteger}n`; + } else if (typeof tempInteger === 'symbol') { + tempStr = 'NaN'; } else { tempStr = `${parseInt(tempInteger)}`; } break; case 102: // 'f' - tempStr = `${parseFloat(args[a++])}`; + const tempFloat = args[a++]; + if (typeof tempFloat === 'symbol') { + tempStr = 'NaN'; + } else { + tempStr = `${parseFloat(tempFloat)}`; + } break; case 37: // '%' str += first.slice(lastPos, i); |