Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0a07201

Browse filesBrowse files
addaleaxcjihrig
authored andcommitted
util: fix formatting of objects with SIMD enabled
When SIMD is enabled, `util.format` couldn’t display objects (with at least 1 key) because the formatter function got overridden. PR-URL: #7864 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
1 parent a4f0b13 commit 0a07201
Copy full SHA for 0a07201

File tree

Expand file treeCollapse file tree

3 files changed

+17
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-4
lines changed
Open diff view settings
Collapse file

‎lib/util.js‎

Copy file name to clipboardExpand all lines: lib/util.js
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,16 +487,13 @@ function formatValue(ctx, value, recurseTimes) {
487487
'byteOffset',
488488
'buffer');
489489
}
490-
} else if (simdFormatters &&
491-
typeof value.constructor === 'function' &&
492-
(formatter = simdFormatters.get(value.constructor))) {
493-
braces = ['[', ']'];
494490
} else {
495491
var promiseInternals = inspectPromise(value);
496492
if (promiseInternals) {
497493
braces = ['{', '}'];
498494
formatter = formatPromise;
499495
} else {
496+
let maybeSimdFormatter;
500497
if (binding.isMapIterator(value)) {
501498
constructor = { name: 'MapIterator' };
502499
braces = ['{', '}'];
@@ -507,6 +504,11 @@ function formatValue(ctx, value, recurseTimes) {
507504
braces = ['{', '}'];
508505
empty = false;
509506
formatter = formatCollectionIterator;
507+
} else if (simdFormatters &&
508+
typeof constructor === 'function' &&
509+
(maybeSimdFormatter = simdFormatters.get(constructor))) {
510+
braces = ['[', ']'];
511+
formatter = maybeSimdFormatter;
510512
} else {
511513
// Unset the constructor to prevent "Object {...}" for ordinary objects.
512514
if (constructor && constructor.name === 'Object')
Collapse file

‎test/parallel/test-util-format.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-format.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const symbol = Symbol('foo');
77
assert.equal(util.format(), '');
88
assert.equal(util.format(''), '');
99
assert.equal(util.format([]), '[]');
10+
assert.equal(util.format([0]), '[ 0 ]');
1011
assert.equal(util.format({}), '{}');
12+
assert.equal(util.format({foo: 42}), '{ foo: 42 }');
1113
assert.equal(util.format(null), 'null');
1214
assert.equal(util.format(true), 'true');
1315
assert.equal(util.format(false), 'false');
Collapse file

‎test/parallel/test-util-inspect-simd.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect-simd.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,12 @@ if (typeof SIMD.Uint8x16 === 'function') {
5959
inspect(SIMD.Uint8x16()),
6060
'Uint8x16 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]');
6161
}
62+
63+
// Tests from test-inspect.js that should not fail with --harmony_simd.
64+
assert.strictEqual(inspect([]), '[]');
65+
assert.strictEqual(inspect([0]), '[ 0 ]');
66+
assert.strictEqual(inspect({}), '{}');
67+
assert.strictEqual(inspect({foo: 42}), '{ foo: 42 }');
68+
assert.strictEqual(inspect(null), 'null');
69+
assert.strictEqual(inspect(true), 'true');
70+
assert.strictEqual(inspect(false), 'false');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.