Skip to content

Commit b0f6baa

Browse files
committed
fixup! util: print External address from inspect
1 parent 9d071d9 commit b0f6baa

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

lib/internal/util/inspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
979979
} else {
980980
if (keys.length === 0 && protoProps === undefined) {
981981
if (isExternal(value)) {
982-
const address = getExternalValue(value);
982+
const address = getExternalValue(value).toString(16);
983983
return ctx.stylize(`[External: ${address}]`, 'special');
984984
}
985985
return `${getCtxStyle(value, constructor, tag)}{}`;

src/node_util.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace util {
99
using v8::ALL_PROPERTIES;
1010
using v8::Array;
1111
using v8::ArrayBufferView;
12+
using v8::BigInt;
1213
using v8::Boolean;
1314
using v8::Context;
1415
using v8::External;
@@ -73,15 +74,13 @@ static void GetConstructorName(
7374
static void GetExternalValue(
7475
const FunctionCallbackInfo<Value>& args) {
7576
CHECK(args[0]->IsExternal());
76-
auto isolate = args.GetIsolate();
77+
Isolate* isolate = args.GetIsolate();
7778
Local<External> external = args[0].As<External>();
7879

7980
void* ptr = external->Value();
80-
char val[20];
81-
snprintf(val, sizeof(val), "%p", ptr);
82-
83-
MaybeLocal<String> ret = String::NewFromUtf8(isolate, val);
84-
args.GetReturnValue().Set(ret.ToLocalChecked());
81+
uint64_t value = reinterpret_cast<uint64_t>(ptr);
82+
Local<BigInt> ret = BigInt::NewFromUnsigned(isolate, value);
83+
args.GetReturnValue().Set(ret);
8584
}
8685

8786
static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) {

test/parallel/test-util-inspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ assert.strictEqual(
148148
);
149149

150150
assert.match(util.inspect((new JSStream())._externalStream),
151-
/^\[External: .*?\]$/);
151+
/^\[External: [0-9a-f]+\]$/);
152152

153153
{
154154
const regexp = /regexp/;

0 commit comments

Comments
 (0)