summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-10-17 09:45:11 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-12-03 12:34:42 +0100
commit1fe824bcbb0267265a8ccdb7301b7b8e3e8779f3 (patch)
treefbd81738dce5338f0ef863bc34e5cb08df9f3449 /test/parallel
parentf8f96017e82abe4e965251b2f6072bdb6bea9d51 (diff)
downloadandroid-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 'test/parallel')
-rw-r--r--test/parallel/test-util-format.js16
1 files changed, 4 insertions, 12 deletions
diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js
index 2ca8e0857f..066b4de58c 100644
--- a/test/parallel/test-util-format.js
+++ b/test/parallel/test-util-format.js
@@ -44,18 +44,6 @@ assert.strictEqual(util.format(symbol), 'Symbol(foo)');
assert.strictEqual(util.format('foo', symbol), 'foo Symbol(foo)');
assert.strictEqual(util.format('%s', symbol), 'Symbol(foo)');
assert.strictEqual(util.format('%j', symbol), 'undefined');
-assert.throws(
- () => { util.format('%d', symbol); },
- (e) => {
- // The error should be a TypeError.
- if (!(e instanceof TypeError))
- return false;
-
- // The error should be from the JS engine and not from Node.js.
- // JS engine errors do not have the `code` property.
- return e.code === undefined;
- }
-);
// Number format specifier
assert.strictEqual(util.format('%d'), '%d');
@@ -66,6 +54,7 @@ assert.strictEqual(util.format('%d', '42.0'), '42');
assert.strictEqual(util.format('%d', 1.5), '1.5');
assert.strictEqual(util.format('%d', -0.5), '-0.5');
assert.strictEqual(util.format('%d', ''), '0');
+assert.strictEqual(util.format('%d', Symbol()), 'NaN');
assert.strictEqual(util.format('%d %d', 42, 43), '42 43');
assert.strictEqual(util.format('%d %d', 42), '42 %d');
assert.strictEqual(
@@ -90,6 +79,7 @@ assert.strictEqual(util.format('%i', '42.0'), '42');
assert.strictEqual(util.format('%i', 1.5), '1');
assert.strictEqual(util.format('%i', -0.5), '0');
assert.strictEqual(util.format('%i', ''), 'NaN');
+assert.strictEqual(util.format('%i', Symbol()), 'NaN');
assert.strictEqual(util.format('%i %i', 42, 43), '42 43');
assert.strictEqual(util.format('%i %i', 42), '42 %i');
assert.strictEqual(
@@ -125,6 +115,8 @@ assert.strictEqual(util.format('%f', 1.5), '1.5');
assert.strictEqual(util.format('%f', -0.5), '-0.5');
assert.strictEqual(util.format('%f', Math.PI), '3.141592653589793');
assert.strictEqual(util.format('%f', ''), 'NaN');
+assert.strictEqual(util.format('%f', Symbol('foo')), 'NaN');
+assert.strictEqual(util.format('%f', 5n), '5');
assert.strictEqual(util.format('%f %f', 42, 43), '42 43');
assert.strictEqual(util.format('%f %f', 42), '42 %f');