diff --git a/lib/util.js b/lib/util.js index 245b19639324df..37c3c2171ec1cc 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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)} }`; } @@ -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; diff --git a/src/node_util.cc b/src/node_util.cc index cfbd2501706173..b228af005077a4 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -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) \ diff --git a/test/parallel/test-util-inspect-sharedarraybuffer.js b/test/parallel/test-util-inspect-sharedarraybuffer.js new file mode 100644 index 00000000000000..938a3293cd199a --- /dev/null +++ b/test/parallel/test-util-inspect-sharedarraybuffer.js @@ -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 }'); diff --git a/test/parallel/test-util-inspect-simd.js b/test/parallel/test-util-inspect-simd.js index ec4ccc1875a817..3d705c488e2328 100644 --- a/test/parallel/test-util-inspect-simd.js +++ b/test/parallel/test-util-inspect-simd.js @@ -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({}), '{}'); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 3becf5b318d0a9..617843fafa7c90 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1,4 +1,5 @@ 'use strict'; + const common = require('../common'); const assert = require('assert'); const util = require('util'); @@ -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)