Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9027a87

Browse filesBrowse files
rosaxxnyaddaleax
authored andcommitted
util: print External address from inspect
Fixes: #28250 PR-URL: #34398 Backport-PR-URL: #34583 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent e7252df commit 9027a87
Copy full SHA for 9027a87

File tree

Expand file treeCollapse file tree

3 files changed

+23
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-4
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const {
6060
kRejected,
6161
previewEntries,
6262
getConstructorName: internalGetConstructorName,
63+
getExternalValue,
6364
propertyFilter: {
6465
ALL_PROPERTIES,
6566
ONLY_ENUMERABLE
@@ -938,8 +939,10 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
938939
}
939940
} else {
940941
if (keys.length === 0 && protoProps === undefined) {
941-
if (isExternal(value))
942-
return ctx.stylize('[External]', 'special');
942+
if (isExternal(value)) {
943+
const address = getExternalValue(value).toString(16);
944+
return ctx.stylize(`[External: ${address}]`, 'special');
945+
}
943946
return `${getCtxStyle(value, constructor, tag)}{}`;
944947
}
945948
braces[0] = `${getCtxStyle(value, constructor, tag)}{`;
Collapse file

‎src/node_util.cc‎

Copy file name to clipboardExpand all lines: src/node_util.cc
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ namespace util {
88
using v8::ALL_PROPERTIES;
99
using v8::Array;
1010
using v8::ArrayBufferView;
11+
using v8::BigInt;
1112
using v8::Boolean;
1213
using v8::Context;
14+
using v8::External;
1315
using v8::FunctionCallbackInfo;
1416
using v8::FunctionTemplate;
1517
using v8::Global;
@@ -18,6 +20,7 @@ using v8::Integer;
1820
using v8::Isolate;
1921
using v8::KeyCollectionMode;
2022
using v8::Local;
23+
using v8::MaybeLocal;
2124
using v8::Object;
2225
using v8::ONLY_CONFIGURABLE;
2326
using v8::ONLY_ENUMERABLE;
@@ -67,6 +70,18 @@ static void GetConstructorName(
6770
args.GetReturnValue().Set(name);
6871
}
6972

73+
static void GetExternalValue(
74+
const FunctionCallbackInfo<Value>& args) {
75+
CHECK(args[0]->IsExternal());
76+
Isolate* isolate = args.GetIsolate();
77+
Local<External> external = args[0].As<External>();
78+
79+
void* ptr = external->Value();
80+
uint64_t value = reinterpret_cast<uint64_t>(ptr);
81+
Local<BigInt> ret = BigInt::NewFromUnsigned(isolate, value);
82+
args.GetReturnValue().Set(ret);
83+
}
84+
7085
static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) {
7186
// Return undefined if it's not a Promise.
7287
if (!args[0]->IsPromise())
@@ -296,6 +311,7 @@ void Initialize(Local<Object> target,
296311
env->SetMethodNoSideEffect(target, "getOwnNonIndexProperties",
297312
GetOwnNonIndexProperties);
298313
env->SetMethodNoSideEffect(target, "getConstructorName", GetConstructorName);
314+
env->SetMethodNoSideEffect(target, "getExternalValue", GetExternalValue);
299315
env->SetMethod(target, "sleep", Sleep);
300316

301317
env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer);
Collapse file

‎test/parallel/test-util-inspect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ assert.strictEqual(
146146
"[String: 'hello'] { [length]: 5, [Symbol(foo)]: 123 }"
147147
);
148148

149-
assert.strictEqual(util.inspect((new JSStream())._externalStream),
150-
'[External]');
149+
assert.match(util.inspect((new JSStream())._externalStream),
150+
/^\[External: [0-9a-f]+\]$/);
151151

152152
{
153153
const regexp = /regexp/;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.