File tree Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -734,6 +734,27 @@ std::string AsyncWrap::diagnostic_name() const {
734
734
std::to_string (static_cast <int64_t >(async_id_)) + " )" ;
735
735
}
736
736
737
+ Local<Object> AsyncWrap::GetOwner () {
738
+ return GetOwner (env (), object ());
739
+ }
740
+
741
+ Local<Object> AsyncWrap::GetOwner (Environment* env, Local<Object> obj) {
742
+ v8::EscapableHandleScope handle_scope (env->isolate ());
743
+ CHECK (!obj.IsEmpty ());
744
+
745
+ v8::TryCatch ignore_exceptions (env->isolate ());
746
+ while (true ) {
747
+ Local<Value> owner;
748
+ if (!obj->Get (env->context (),
749
+ env->owner_symbol ()).ToLocal (&owner) ||
750
+ !owner->IsObject ()) {
751
+ return handle_scope.Escape (obj);
752
+ }
753
+
754
+ obj = owner.As <Object>();
755
+ }
756
+ }
757
+
737
758
} // namespace node
738
759
739
760
NODE_BUILTIN_MODULE_CONTEXT_AWARE (async_wrap, node::AsyncWrap::Initialize)
Original file line number Diff line number Diff line change @@ -178,6 +178,12 @@ class AsyncWrap : public BaseObject {
178
178
179
179
static void WeakCallback (const v8::WeakCallbackInfo<DestroyParam> &info);
180
180
181
+ // Returns the object that 'owns' an async wrap. For example, for a
182
+ // TCP connection handle, this is the corresponding net.Socket.
183
+ v8::Local<v8::Object> GetOwner ();
184
+ static v8::Local<v8::Object> GetOwner (Environment* env,
185
+ v8::Local<v8::Object> obj);
186
+
181
187
// This is a simplified version of InternalCallbackScope that only runs
182
188
// the `before` and `after` hooks. Only use it when not actually calling
183
189
// back into JS; otherwise, use InternalCallbackScope.
Original file line number Diff line number Diff line change @@ -1138,7 +1138,7 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
1138
1138
for (auto w : *env->req_wrap_queue ()) {
1139
1139
if (w->persistent ().IsEmpty ())
1140
1140
continue ;
1141
- argv[idx] = w->object ();
1141
+ argv[idx] = w->GetOwner ();
1142
1142
if (++idx >= arraysize (argv)) {
1143
1143
fn->Call (ctx, ary, idx, argv).ToLocalChecked ();
1144
1144
idx = 0 ;
@@ -1164,16 +1164,10 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
1164
1164
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1165
1165
size_t idx = 0 ;
1166
1166
1167
- Local<String> owner_sym = env->owner_string ();
1168
-
1169
1167
for (auto w : *env->handle_wrap_queue ()) {
1170
- if (w-> persistent (). IsEmpty () || !HandleWrap::HasRef (w))
1168
+ if (!HandleWrap::HasRef (w))
1171
1169
continue ;
1172
- Local<Object> object = w->object ();
1173
- Local<Value> owner = object->Get (owner_sym);
1174
- if (owner->IsUndefined ())
1175
- owner = object;
1176
- argv[idx] = owner;
1170
+ argv[idx] = w->GetOwner ();
1177
1171
if (++idx >= arraysize (argv)) {
1178
1172
fn->Call (ctx, ary, idx, argv).ToLocalChecked ();
1179
1173
idx = 0 ;
You can’t perform that action at this time.
0 commit comments