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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
80b10b4fe2
commit
1b24b37299
10
lib/util.js
10
lib/util.js
@ -487,16 +487,13 @@ function formatValue(ctx, value, recurseTimes) {
|
||||
'byteOffset',
|
||||
'buffer');
|
||||
}
|
||||
} else if (simdFormatters &&
|
||||
typeof value.constructor === 'function' &&
|
||||
(formatter = simdFormatters.get(value.constructor))) {
|
||||
braces = ['[', ']'];
|
||||
} else {
|
||||
var promiseInternals = inspectPromise(value);
|
||||
if (promiseInternals) {
|
||||
braces = ['{', '}'];
|
||||
formatter = formatPromise;
|
||||
} else {
|
||||
let maybeSimdFormatter;
|
||||
if (binding.isMapIterator(value)) {
|
||||
constructor = { name: 'MapIterator' };
|
||||
braces = ['{', '}'];
|
||||
@ -507,6 +504,11 @@ function formatValue(ctx, value, recurseTimes) {
|
||||
braces = ['{', '}'];
|
||||
empty = false;
|
||||
formatter = formatCollectionIterator;
|
||||
} else if (simdFormatters &&
|
||||
typeof constructor === 'function' &&
|
||||
(maybeSimdFormatter = simdFormatters.get(constructor))) {
|
||||
braces = ['[', ']'];
|
||||
formatter = maybeSimdFormatter;
|
||||
} else {
|
||||
// Unset the constructor to prevent "Object {...}" for ordinary objects.
|
||||
if (constructor && constructor.name === 'Object')
|
||||
|
@ -7,7 +7,9 @@ const symbol = Symbol('foo');
|
||||
assert.equal(util.format(), '');
|
||||
assert.equal(util.format(''), '');
|
||||
assert.equal(util.format([]), '[]');
|
||||
assert.equal(util.format([0]), '[ 0 ]');
|
||||
assert.equal(util.format({}), '{}');
|
||||
assert.equal(util.format({foo: 42}), '{ foo: 42 }');
|
||||
assert.equal(util.format(null), 'null');
|
||||
assert.equal(util.format(true), 'true');
|
||||
assert.equal(util.format(false), 'false');
|
||||
|
@ -59,3 +59,12 @@ if (typeof SIMD.Uint8x16 === 'function') {
|
||||
inspect(SIMD.Uint8x16()),
|
||||
'Uint8x16 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]');
|
||||
}
|
||||
|
||||
// Tests from test-inspect.js that should not fail with --harmony_simd.
|
||||
assert.strictEqual(inspect([]), '[]');
|
||||
assert.strictEqual(inspect([0]), '[ 0 ]');
|
||||
assert.strictEqual(inspect({}), '{}');
|
||||
assert.strictEqual(inspect({foo: 42}), '{ foo: 42 }');
|
||||
assert.strictEqual(inspect(null), 'null');
|
||||
assert.strictEqual(inspect(true), 'true');
|
||||
assert.strictEqual(inspect(false), 'false');
|
||||
|
Loading…
x
Reference in New Issue
Block a user