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