-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
util: print External address from inspect #34398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Fixes: #28250
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ using v8::Array; | |
| using v8::ArrayBufferView; | ||
| using v8::Boolean; | ||
| using v8::Context; | ||
| using v8::External; | ||
| using v8::FunctionCallbackInfo; | ||
| using v8::FunctionTemplate; | ||
| using v8::Global; | ||
|
|
@@ -19,6 +20,7 @@ using v8::Integer; | |
| using v8::Isolate; | ||
| using v8::KeyCollectionMode; | ||
| using v8::Local; | ||
| using v8::MaybeLocal; | ||
| using v8::Object; | ||
| using v8::ONLY_CONFIGURABLE; | ||
| using v8::ONLY_ENUMERABLE; | ||
|
|
@@ -68,6 +70,20 @@ static void GetConstructorName( | |
| args.GetReturnValue().Set(name); | ||
| } | ||
|
|
||
| static void GetExternalValue( | ||
| const FunctionCallbackInfo<Value>& args) { | ||
| CHECK(args[0]->IsExternal()); | ||
| auto isolate = args.GetIsolate(); | ||
| Local<External> external = args[0].As<External>(); | ||
|
|
||
| void* ptr = external->Value(); | ||
| char val[20]; | ||
| snprintf(val, sizeof(val), "%p", ptr); | ||
|
||
|
|
||
| MaybeLocal<String> ret = String::NewFromUtf8(isolate, val); | ||
| args.GetReturnValue().Set(ret.ToLocalChecked()); | ||
| } | ||
|
|
||
| static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) { | ||
| // Return undefined if it's not a Promise. | ||
| if (!args[0]->IsPromise()) | ||
|
|
@@ -314,6 +330,7 @@ void Initialize(Local<Object> target, | |
| env->SetMethodNoSideEffect(target, "getOwnNonIndexProperties", | ||
| GetOwnNonIndexProperties); | ||
| env->SetMethodNoSideEffect(target, "getConstructorName", GetConstructorName); | ||
| env->SetMethodNoSideEffect(target, "getExternalValue", GetExternalValue); | ||
| env->SetMethod(target, "sleep", Sleep); | ||
|
|
||
| env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -147,8 +147,8 @@ assert.strictEqual( | |||||
| "[String: 'hello'] { [length]: 5, [Symbol(foo)]: 123 }" | ||||||
| ); | ||||||
|
|
||||||
| assert.strictEqual(util.inspect((new JSStream())._externalStream), | ||||||
| '[External]'); | ||||||
| assert.match(util.inspect((new JSStream())._externalStream), | ||||||
| /^\[External: .*?\]$/); | ||||||
|
||||||
| /^\[External: .*?\]$/); | |
| /^\[External: [0-9a-f]+\]$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice! Thank you!
This is not a blocker at all, but I'd prefer specify the type
Just a sugestion, not a blocker.