summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.json2
-rw-r--r--platform/node/src/node_expression.cpp2
-rw-r--r--platform/node/src/node_map.cpp38
-rw-r--r--platform/node/src/node_map.hpp4
-rw-r--r--platform/node/src/node_request.cpp3
5 files changed, 34 insertions, 15 deletions
diff --git a/package.json b/package.json
index 977cd2b09c..c3f0d7b8ae 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
},
"license": "BSD-2-Clause",
"dependencies": {
- "nan": "~2.8",
+ "nan": "~2.10",
"node-pre-gyp": "^0.6.37",
"npm-run-all": "^4.0.2"
},
diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp
index 27866ccbed..9faa41d8b8 100644
--- a/platform/node/src/node_expression.cpp
+++ b/platform/node/src/node_expression.cpp
@@ -52,7 +52,7 @@ type::Type parseType(v8::Local<v8::Object> type) {
v8::Local<v8::String> Nkey = Nan::New("N").ToLocalChecked();
if (Nan::Has(type, Nkey).FromMaybe(false)) {
- N = Nan::Get(type, Nkey).ToLocalChecked()->ToInt32()->Value();
+ N = Nan::To<v8::Int32>(Nan::Get(type, Nkey).ToLocalChecked()).ToLocalChecked()->Value();
}
return type::Array(itemType, N);
}
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 521cca1a51..bc40d56f44 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -353,6 +353,18 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) {
return options;
}
+class RenderRequest : public Nan::AsyncResource {
+public:
+ RenderRequest(v8::Local<v8::Function> callback_) : AsyncResource("mbgl:RenderRequest") {
+ callback.Reset(callback_);
+ }
+ ~RenderRequest() {
+ callback.Reset();
+ }
+
+ Nan::Persistent<v8::Function> callback;
+};
+
/**
* Render an image from the currently-loaded style
*
@@ -385,15 +397,16 @@ void NodeMap::Render(const Nan::FunctionCallbackInfo<v8::Value>& info) {
return Nan::ThrowTypeError("Style is not loaded");
}
- if (nodeMap->callback) {
+ if (nodeMap->req) {
return Nan::ThrowError("Map is currently rendering an image");
}
try {
auto options = ParseOptions(Nan::To<v8::Object>(info[0]).ToLocalChecked());
- assert(!nodeMap->callback);
+ assert(!nodeMap->req);
assert(!nodeMap->image.data);
- nodeMap->callback = std::make_unique<Nan::Callback>(info[1].As<v8::Function>());
+ nodeMap->req = std::make_unique<RenderRequest>(Nan::To<v8::Function>(info[1]).ToLocalChecked());
+
nodeMap->startRender(std::move(options));
} catch (mbgl::style::conversion::Error& err) {
return Nan::ThrowTypeError(err.message.c_str());
@@ -463,14 +476,17 @@ void NodeMap::renderFinished() {
Unref();
// Move the callback and image out of the way so that the callback can start a new render call.
- auto cb = std::move(callback);
+ auto request = std::move(req);
auto img = std::move(image);
- assert(cb);
+ assert(request);
// These have to be empty to be prepared for the next render call.
- assert(!callback);
+ assert(!req);
assert(!image.data);
+ v8::Local<v8::Function> callback = Nan::New(request->callback);
+ v8::Local<v8::Object> target = Nan::New<v8::Object>();
+
if (error) {
std::string errorMessage;
@@ -488,7 +504,7 @@ void NodeMap::renderFinished() {
error = nullptr;
assert(!error);
- cb->Call(1, argv);
+ request->runInAsyncScope(target, callback, 1, argv);
} else if (img.data) {
v8::Local<v8::Object> pixels = Nan::NewBuffer(
reinterpret_cast<char *>(img.data.get()), img.bytes(),
@@ -504,12 +520,12 @@ void NodeMap::renderFinished() {
Nan::Null(),
pixels
};
- cb->Call(2, argv);
+ request->runInAsyncScope(target, callback, 2, argv);
} else {
v8::Local<v8::Value> argv[] = {
Nan::Error("Didn't get an image")
};
- cb->Call(1, argv);
+ request->runInAsyncScope(target, callback, 1, argv);
}
}
@@ -552,7 +568,7 @@ void NodeMap::Cancel(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
- if (!nodeMap->callback) return Nan::ThrowError("No render in progress");
+ if (!nodeMap->req) return Nan::ThrowError("No render in progress");
try {
nodeMap->cancel();
@@ -1198,7 +1214,7 @@ std::unique_ptr<mbgl::AsyncRequest> NodeMap::request(const mbgl::Resource& resou
Nan::New<v8::External>(&callback_)
};
- auto instance = Nan::New(NodeRequest::constructor)->NewInstance(2, argv);
+ auto instance = Nan::NewInstance(Nan::New(NodeRequest::constructor), 2, argv).ToLocalChecked();
Nan::Set(instance, Nan::New("url").ToLocalChecked(), Nan::New(resource.url).ToLocalChecked());
Nan::Set(instance, Nan::New("kind").ToLocalChecked(), Nan::New<v8::Integer>(resource.kind));
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index 7fe23ad86a..19df095481 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -25,6 +25,8 @@ class NodeMapObserver : public mbgl::MapObserver {
void onDidFailLoadingMap(std::exception_ptr) override;
};
+class RenderRequest;
+
class NodeMap : public Nan::ObjectWrap,
public mbgl::FileSource {
public:
@@ -84,7 +86,7 @@ public:
std::exception_ptr error;
mbgl::PremultipliedImage image;
- std::unique_ptr<Nan::Callback> callback;
+ std::unique_ptr<RenderRequest> req;
// Async for delivering the notifications of render completion.
uv_async_t *async;
diff --git a/platform/node/src/node_request.cpp b/platform/node/src/node_request.cpp
index de16710f78..8c26d44583 100644
--- a/platform/node/src/node_request.cpp
+++ b/platform/node/src/node_request.cpp
@@ -124,7 +124,8 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf
void NodeRequest::Execute() {
v8::Local<v8::Value> argv[] = { handle() };
- Nan::MakeCallback(Nan::To<v8::Object>(target->handle()->GetInternalField(1)).ToLocalChecked(), "request", 1, argv);
+ Nan::AsyncResource res("mbgl:execute");
+ res.runInAsyncScope(Nan::To<v8::Object>(target->handle()->GetInternalField(1)).ToLocalChecked(), "request", 1, argv);
}
NodeRequest::NodeAsyncRequest::NodeAsyncRequest(NodeRequest* request_) : request(request_) {