Skip to content

Commit e97fe46

Browse files
yosuke-furukawajasnell
authored andcommitted
util: Add format for SharedArrayBuffer
PR-URL: #8587 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent b397c16 commit e97fe46

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
@@ -435,9 +435,10 @@ function formatValue(ctx, value, recurseTimes) {
435435
formatted = formatPrimitiveNoColor(ctx, raw);
436436
return ctx.stylize('[Boolean: ' + formatted + ']', 'boolean');
437437
}
438-
// Fast path for ArrayBuffer. Can't do the same for DataView because it
439-
// has a non-primitive .buffer property that we need to recurse for.
440-
if (binding.isArrayBuffer(value)) {
438+
// Fast path for ArrayBuffer and SharedArrayBuffer.
439+
// Can't do the same for DataView because it has a non-primitive
440+
// .buffer property that we need to recurse for.
441+
if (binding.isArrayBuffer(value) || binding.isSharedArrayBuffer(value)) {
441442
return `${getConstructorOf(value).name}` +
442443
` { byteLength: ${formatNumber(ctx, value.byteLength)} }`;
443444
}
@@ -475,7 +476,8 @@ function formatValue(ctx, value, recurseTimes) {
475476
keys.unshift('size');
476477
empty = value.size === 0;
477478
formatter = formatMap;
478-
} else if (binding.isArrayBuffer(value)) {
479+
} else if (binding.isArrayBuffer(value) ||
480+
binding.isSharedArrayBuffer(value)) {
479481
braces = ['{', '}'];
480482
keys.unshift('byteLength');
481483
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)