Skip to content

Commit e5c6df2

Browse files
util: Add format for SharedArrayBuffer
1 parent 84afdc3 commit e5c6df2

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/util.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,10 @@ function formatValue(ctx, value, recurseTimes) {
447447
formatted = formatPrimitiveNoColor(ctx, raw);
448448
return ctx.stylize('[Boolean: ' + formatted + ']', 'boolean');
449449
}
450-
// Fast path for ArrayBuffer. Can't do the same for DataView because it
451-
// has a non-primitive .buffer property that we need to recurse for.
452-
if (binding.isArrayBuffer(value)) {
450+
// Fast path for ArrayBuffer and SharedArrayBuffer.
451+
// Can't do the same for DataView because it has a non-primitive
452+
// .buffer property that we need to recurse for.
453+
if (binding.isArrayBuffer(value) || binding.isSharedArrayBuffer(value)) {
453454
return `${getConstructorOf(value).name}` +
454455
` { byteLength: ${formatNumber(ctx, value.byteLength)} }`;
455456
}
@@ -487,7 +488,8 @@ function formatValue(ctx, value, recurseTimes) {
487488
keys.unshift('size');
488489
empty = value.size === 0;
489490
formatter = formatMap;
490-
} else if (binding.isArrayBuffer(value)) {
491+
} else if (binding.isArrayBuffer(value) ||
492+
binding.isSharedArrayBuffer(value)) {
491493
braces = ['{', '}'];
492494
keys.unshift('byteLength');
493495
visibleKeys.byteLength = true;

src/node_util.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ using v8::Value;
2020

2121
#define VALUE_METHOD_MAP(V) \
2222
V(isArrayBuffer, IsArrayBuffer) \
23-
V(isSharedArrayBuffer, IsSharedArrayBuffer) \
2423
V(isDataView, IsDataView) \
2524
V(isDate, IsDate) \
2625
V(isMap, IsMap) \
@@ -29,6 +28,7 @@ using v8::Value;
2928
V(isRegExp, IsRegExp) \
3029
V(isSet, IsSet) \
3130
V(isSetIterator, IsSetIterator) \
31+
V(isSharedArrayBuffer, IsSharedArrayBuffer) \
3232
V(isTypedArray, IsTypedArray)
3333

3434

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Flags: --harmony_sharedarraybuffer
2+
3+
'use strict';
4+
require('../common');
5+
const assert = require('assert');
6+
const util = require('util');
7+
8+
/* global SharedArrayBuffer */
9+
const sab = new SharedArrayBuffer(4);
10+
assert.strictEqual(util.format(sab), 'SharedArrayBuffer { byteLength: 4 }');

0 commit comments

Comments
 (0)