diff options
author | Mike Morris <mikemorris@users.noreply.github.com> | 2016-09-26 13:47:01 -0400 |
---|---|---|
committer | Mike Morris <mikemorris@users.noreply.github.com> | 2016-10-03 10:31:06 -0400 |
commit | a4da948b8cb3dabeac32a54b20741807dc691e5d (patch) | |
tree | 1143200e24d6177c9179a07cf97387c53588d625 | |
parent | 132954b56340ff6d883a325c0f64ed7ce1aa3072 (diff) |
[node] ref NodeRequest during garbage collection window
-rw-r--r-- | platform/node/src/node_request.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/platform/node/src/node_request.cpp b/platform/node/src/node_request.cpp index 607e6e8b0..b7ba6e271 100644 --- a/platform/node/src/node_request.cpp +++ b/platform/node/src/node_request.cpp @@ -53,8 +53,12 @@ void NodeRequest::New(const Nan::FunctionCallbackInfo<v8::Value>& info) { void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& info) { auto request = Nan::ObjectWrap::Unwrap<NodeRequest>(info.Holder()); + // Survived the garbage collection window + request->Unref(); + // Move out of the object so callback() can only be fired once. auto callback = std::move(request->callback); + if (!callback) { return info.GetReturnValue().SetUndefined(); } @@ -127,6 +131,9 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf void NodeRequest::Execute() { v8::Local<v8::Value> argv[] = { handle() }; + // Prevent losing the NodeRequest to garbage collection + Ref(); + Nan::MakeCallback(Nan::To<v8::Object>(target->handle()->GetInternalField(1)).ToLocalChecked(), "request", 1, argv); } |