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-09-26 15:11:53 -0400 |
commit | dc232467e620c3d018f5a0fb03093dfff5aac767 (patch) | |
tree | 1c283d23c9014603acc135821ca22ea8f6b2c0fe | |
parent | f30765254807bedab0873a289a118906ef74b754 (diff) | |
download | qtlocation-mapboxgl-dc232467e620c3d018f5a0fb03093dfff5aac767.tar.gz |
[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 607e6e8b03..b7ba6e2719 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); } |