Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,10 @@ function formatValue(ctx, value, recurseTimes) {
formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[Boolean: ' + formatted + ']', 'boolean');
}
// Fast path for ArrayBuffer. Can't do the same for DataView because it
// has a non-primitive .buffer property that we need to recurse for.
if (binding.isArrayBuffer(value)) {
// Fast path for ArrayBuffer and SharedArrayBuffer.
// Can't do the same for DataView because it has a non-primitive .buffer
// property that we need to recurse for.
if (binding.isArrayBuffer(value) || binding.isSharedArrayBuffer(value)) {
return `${getConstructorOf(value).name}` +
` { byteLength: ${formatNumber(ctx, value.byteLength)} }`;
}
Expand Down Expand Up @@ -487,7 +488,8 @@ function formatValue(ctx, value, recurseTimes) {
keys.unshift('size');
empty = value.size === 0;
formatter = formatMap;
} else if (binding.isArrayBuffer(value)) {
} else if (binding.isArrayBuffer(value) ||
binding.isSharedArrayBuffer(value)) {
braces = ['{', '}'];
keys.unshift('byteLength');
visibleKeys.byteLength = true;
Expand Down
1 change: 1 addition & 0 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using v8::Value;

#define VALUE_METHOD_MAP(V) \
V(isArrayBuffer, IsArrayBuffer) \
V(isSharedArrayBuffer, IsSharedArrayBuffer) \
V(isDataView, IsDataView) \
V(isDate, IsDate) \
V(isMap, IsMap) \
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-util-inspect-sharedarraybuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Flags: --harmony_sharedarraybuffer
/* global SharedArrayBuffer */
'use strict';

require('../common');
const assert = require('assert');
const inspect = require('util').inspect;

assert.strictEqual(inspect(new SharedArrayBuffer(4)),
'SharedArrayBuffer { byteLength: 4 }');
2 changes: 1 addition & 1 deletion test/parallel/test-util-inspect-simd.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if (typeof SIMD.Uint8x16 === 'function') {
'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.
// Tests from test-util-inspect.js that should not fail with --harmony_simd.
assert.strictEqual(inspect([]), '[]');
assert.strictEqual(inspect([0]), '[ 0 ]');
assert.strictEqual(inspect({}), '{}');
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const util = require('util');
Expand Down Expand Up @@ -42,6 +43,8 @@ assert.strictEqual(util.inspect(Object.create({},
{visible: {value: 1, enumerable: true}, hidden: {value: 2}})),
'{ visible: 1 }'
);
assert.strictEqual(util.inspect(new ArrayBuffer(4)),
'ArrayBuffer { byteLength: 4 }');

assert(/Object/.test(
util.inspect({a: {a: {a: {a: {}}}}}, undefined, undefined, true)
Expand Down