summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMike Morris <mikemorris@users.noreply.github.com>2016-07-12 23:58:19 -0400
committerMike Morris <mikemorris@users.noreply.github.com>2016-07-13 00:02:14 -0400
commit5b9959736dcbf7952f2ad8478dd1c0ab22eab688 (patch)
tree79d97d39d0ddd8e81052215c7555e2c3d70cb513 /platform
parent42907b3d8a5a549c6f490a873afac4e2f7a10cf8 (diff)
downloadqtlocation-mapboxgl-5b9959736dcbf7952f2ad8478dd1c0ab22eab688.tar.gz
[node] modern NAN style updates
Diffstat (limited to 'platform')
-rw-r--r--platform/node/src/node_conversion.hpp8
-rw-r--r--platform/node/src/node_log.cpp2
-rw-r--r--platform/node/src/node_map.cpp53
-rw-r--r--platform/node/src/node_map.hpp26
-rw-r--r--platform/node/src/node_mapbox_gl_native.cpp12
-rw-r--r--platform/node/src/node_request.cpp12
-rw-r--r--platform/node/src/node_request.hpp3
7 files changed, 59 insertions, 57 deletions
diff --git a/platform/node/src/node_conversion.hpp b/platform/node/src/node_conversion.hpp
index 2418a7a6e4..4a385f5619 100644
--- a/platform/node/src/node_conversion.hpp
+++ b/platform/node/src/node_conversion.hpp
@@ -41,10 +41,10 @@ inline bool isObject(v8::Local<v8::Value> value) {
inline optional<v8::Local<v8::Value>> objectMember(v8::Local<v8::Value> value, const char * name) {
Nan::EscapableHandleScope scope;
- if (!Nan::Has(value->ToObject(), Nan::New(name).ToLocalChecked()).FromJust()) {
+ if (!Nan::Has(Nan::To<v8::Object>(value).ToLocalChecked(), Nan::New(name).ToLocalChecked()).IsJust()) {
return {};
}
- Nan::MaybeLocal<v8::Value> result = Nan::Get(value->ToObject(), Nan::New(name).ToLocalChecked());
+ Nan::MaybeLocal<v8::Value> result = Nan::Get(Nan::To<v8::Object>(value).ToLocalChecked(), Nan::New(name).ToLocalChecked());
if (result.IsEmpty()) {
return {};
}
@@ -54,10 +54,10 @@ inline optional<v8::Local<v8::Value>> objectMember(v8::Local<v8::Value> value, c
template <class Fn>
optional<Error> eachMember(v8::Local<v8::Value> value, Fn&& fn) {
Nan::HandleScope scope;
- v8::Local<v8::Array> names = value->ToObject()->GetOwnPropertyNames();
+ v8::Local<v8::Array> names = Nan::GetOwnPropertyNames(Nan::To<v8::Object>(value).ToLocalChecked()).ToLocalChecked();
for (uint32_t i = 0; i < names->Length(); ++i) {
v8::Local<v8::Value> k = Nan::Get(names, i).ToLocalChecked();
- v8::Local<v8::Value> v = Nan::Get(value->ToObject(), k).ToLocalChecked();
+ v8::Local<v8::Value> v = Nan::Get(Nan::To<v8::Object>(value).ToLocalChecked(), k).ToLocalChecked();
optional<Error> result = fn(*Nan::Utf8String(k), v);
if (result) {
return result;
diff --git a/platform/node/src/node_log.cpp b/platform/node/src/node_log.cpp
index 21eaa55bca..9872376904 100644
--- a/platform/node/src/node_log.cpp
+++ b/platform/node/src/node_log.cpp
@@ -42,7 +42,7 @@ NodeLogObserver::NodeLogObserver(v8::Local<v8::Object> target)
v8::Local<v8::Value> argv[] = { Nan::New("message").ToLocalChecked(), msg };
auto handle = Nan::New<v8::Object>(module);
- auto emit = Nan::Get(handle, Nan::New("emit").ToLocalChecked()).ToLocalChecked()->ToObject();
+ auto emit = Nan::To<v8::Object>(Nan::Get(handle, Nan::New("emit").ToLocalChecked()).ToLocalChecked()).ToLocalChecked();
Nan::CallAsFunction(emit, handle, 2, argv);
})) {
Nan::HandleScope scope;
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index eb2ad64700..dba161035a 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -32,9 +32,6 @@ struct NodeMap::RenderOptions {
mbgl::MapDebugOptions debugOptions = mbgl::MapDebugOptions::NoDebug;
};
-////////////////////////////////////////////////////////////////////////////////////////////////
-// Static Node Methods
-
Nan::Persistent<v8::Function> NodeMap::constructor;
static std::shared_ptr<mbgl::HeadlessDisplay> sharedDisplay() {
@@ -113,7 +110,7 @@ NAN_MODULE_INIT(NodeMap::Init) {
* fs.writeFileSync('image.png', image);
* });
*/
-NAN_METHOD(NodeMap::New) {
+void NodeMap::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (!info.IsConstructCall()) {
return Nan::ThrowTypeError("Use the new operator to create new Map objects");
}
@@ -122,7 +119,7 @@ NAN_METHOD(NodeMap::New) {
return Nan::ThrowTypeError("Requires an options object as first argument");
}
- auto options = info[0]->ToObject();
+ auto options = Nan::To<v8::Object>(info[0]).ToLocalChecked();
// Check that 'request' is set. If 'cancel' is set it must be a
// function and if 'ratio' is set it must be a number.
@@ -156,9 +153,12 @@ NAN_METHOD(NodeMap::New) {
std::string StringifyStyle(v8::Local<v8::Value> styleHandle) {
Nan::HandleScope scope;
- v8::Local<v8::Object> JSON = Nan::Get(
- Nan::GetCurrentContext()->Global(),
- Nan::New("JSON").ToLocalChecked()).ToLocalChecked()->ToObject();
+ v8::Local<v8::Object> JSON = Nan::To<v8::Object>(
+ Nan::Get(
+ Nan::GetCurrentContext()->Global(),
+ Nan::New("JSON").ToLocalChecked()
+ ).ToLocalChecked()
+ ).ToLocalChecked();
return *Nan::Utf8String(Nan::MakeCallback(JSON, "stringify", 1, &styleHandle));
}
@@ -178,7 +178,7 @@ std::string StringifyStyle(v8::Local<v8::Value> styleHandle) {
* // providing a string
* map.load(fs.readFileSync('./test/fixtures/style.json', 'utf8'));
*/
-NAN_METHOD(NodeMap::Load) {
+void NodeMap::Load(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
@@ -211,7 +211,7 @@ NAN_METHOD(NodeMap::Load) {
info.GetReturnValue().SetUndefined();
}
-NAN_METHOD(NodeMap::Loaded) {
+void NodeMap::Loaded(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
@@ -261,16 +261,16 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) {
}
if (Nan::Has(obj, Nan::New("classes").ToLocalChecked()).FromJust()) {
- auto classes = Nan::Get(obj, Nan::New("classes").ToLocalChecked()).ToLocalChecked()->ToObject().As<v8::Array>();
+ auto classes = Nan::To<v8::Object>(Nan::Get(obj, Nan::New("classes").ToLocalChecked()).ToLocalChecked()).ToLocalChecked().As<v8::Array>();
const int length = classes->Length();
options.classes.reserve(length);
for (int i = 0; i < length; i++) {
- options.classes.push_back(std::string { *Nan::Utf8String(Nan::Get(classes, i).ToLocalChecked()->ToString()) });
+ options.classes.push_back(std::string { *Nan::Utf8String(Nan::To<v8::String>(Nan::Get(classes, i).ToLocalChecked()).ToLocalChecked()) });
}
}
if (Nan::Has(obj, Nan::New("debug").ToLocalChecked()).FromJust()) {
- auto debug = Nan::Get(obj, Nan::New("debug").ToLocalChecked()).ToLocalChecked()->ToObject().As<v8::Object>();
+ auto debug = Nan::To<v8::Object>(Nan::Get(obj, Nan::New("debug").ToLocalChecked()).ToLocalChecked()).ToLocalChecked();
if (Nan::Has(debug, Nan::New("tileBorders").ToLocalChecked()).FromJust()) {
if (Nan::Get(debug, Nan::New("tileBorders").ToLocalChecked()).ToLocalChecked()->BooleanValue()) {
options.debugOptions = options.debugOptions | mbgl::MapDebugOptions::TileBorders;
@@ -317,7 +317,7 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) {
* @returns {undefined} calls callback
* @throws {Error} if stylesheet is not loaded or if map is already rendering
*/
-NAN_METHOD(NodeMap::Render) {
+void NodeMap::Render(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
@@ -337,7 +337,7 @@ NAN_METHOD(NodeMap::Render) {
return Nan::ThrowError("Map is currently rendering an image");
}
- auto options = ParseOptions(info[0]->ToObject());
+ auto options = ParseOptions(Nan::To<v8::Object>(info[0]).ToLocalChecked());
assert(!nodeMap->callback);
assert(!nodeMap->image.data);
@@ -447,7 +447,7 @@ void NodeMap::renderFinished() {
* @name release
* @returns {undefined}
*/
-NAN_METHOD(NodeMap::Release) {
+void NodeMap::Release(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
@@ -470,7 +470,7 @@ void NodeMap::release() {
map.reset();
}
-NAN_METHOD(NodeMap::AddClass) {
+void NodeMap::AddClass(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
@@ -487,7 +487,7 @@ NAN_METHOD(NodeMap::AddClass) {
info.GetReturnValue().SetUndefined();
}
-NAN_METHOD(NodeMap::AddSource) {
+void NodeMap::AddSource(const Nan::FunctionCallbackInfo<v8::Value>& info) {
using namespace mbgl::style;
using namespace mbgl::style::conversion;
@@ -511,7 +511,7 @@ NAN_METHOD(NodeMap::AddSource) {
nodeMap->map->addSource(std::move(*source));
}
-NAN_METHOD(NodeMap::AddLayer) {
+void NodeMap::AddLayer(const Nan::FunctionCallbackInfo<v8::Value>& info) {
using namespace mbgl::style;
using namespace mbgl::style::conversion;
@@ -531,7 +531,7 @@ NAN_METHOD(NodeMap::AddLayer) {
nodeMap->map->addLayer(std::move(*layer));
}
-NAN_METHOD(NodeMap::SetLayoutProperty) {
+void NodeMap::SetLayoutProperty(const Nan::FunctionCallbackInfo<v8::Value>& info) {
using namespace mbgl::style;
using namespace mbgl::style::conversion;
@@ -564,7 +564,7 @@ NAN_METHOD(NodeMap::SetLayoutProperty) {
info.GetReturnValue().SetUndefined();
}
-NAN_METHOD(NodeMap::SetPaintProperty) {
+void NodeMap::SetPaintProperty(const Nan::FunctionCallbackInfo<v8::Value>& info) {
using namespace mbgl::style;
using namespace mbgl::style::conversion;
@@ -602,7 +602,7 @@ NAN_METHOD(NodeMap::SetPaintProperty) {
info.GetReturnValue().SetUndefined();
}
-NAN_METHOD(NodeMap::SetFilter) {
+void NodeMap::SetFilter(const Nan::FunctionCallbackInfo<v8::Value>& info) {
using namespace mbgl::style;
using namespace mbgl::style::conversion;
@@ -657,7 +657,7 @@ NAN_METHOD(NodeMap::SetFilter) {
Nan::ThrowTypeError("layer doesn't support filters");
}
-NAN_METHOD(NodeMap::DumpDebugLogs) {
+void NodeMap::DumpDebugLogs(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
@@ -665,7 +665,7 @@ NAN_METHOD(NodeMap::DumpDebugLogs) {
info.GetReturnValue().SetUndefined();
}
-NAN_METHOD(NodeMap::QueryRenderedFeatures) {
+void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
@@ -713,9 +713,6 @@ NAN_METHOD(NodeMap::QueryRenderedFeatures) {
}
}
-////////////////////////////////////////////////////////////////////////////////////////////////
-// Instance
-
NodeMap::NodeMap(v8::Local<v8::Object> options) :
view(sharedDisplay(), [&] {
Nan::HandleScope scope;
@@ -756,4 +753,4 @@ std::unique_ptr<mbgl::AsyncRequest> NodeMap::request(const mbgl::Resource& resou
return std::make_unique<NodeRequest::NodeAsyncRequest>(request);
}
-} // namespace node_mbgl
+}
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index ac793c8178..f61949de62 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -20,19 +20,19 @@ public:
static NAN_MODULE_INIT(Init);
- static NAN_METHOD(New);
- static NAN_METHOD(Load);
- static NAN_METHOD(Loaded);
- static NAN_METHOD(Render);
- static NAN_METHOD(Release);
- static NAN_METHOD(AddClass);
- static NAN_METHOD(AddSource);
- static NAN_METHOD(AddLayer);
- static NAN_METHOD(SetLayoutProperty);
- static NAN_METHOD(SetPaintProperty);
- static NAN_METHOD(SetFilter);
- static NAN_METHOD(DumpDebugLogs);
- static NAN_METHOD(QueryRenderedFeatures);
+ static void New(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void Load(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void Loaded(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void Render(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void Release(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void AddClass(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void AddSource(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void AddLayer(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void SetLayoutProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void SetPaintProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void SetFilter(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void DumpDebugLogs(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&);
void startRender(RenderOptions options);
void renderFinished();
diff --git a/platform/node/src/node_mapbox_gl_native.cpp b/platform/node/src/node_mapbox_gl_native.cpp
index a743ed9aa5..042def9fdd 100644
--- a/platform/node/src/node_mapbox_gl_native.cpp
+++ b/platform/node/src/node_mapbox_gl_native.cpp
@@ -61,10 +61,14 @@ void RegisterModule(v8::Local<v8::Object> target, v8::Local<v8::Object> module)
Nan::New("require").ToLocalChecked()).ToLocalChecked().As<v8::Function>();
v8::Local<v8::Value> eventsString = Nan::New("events").ToLocalChecked();
- v8::Local<v8::Object> events = Nan::Call(require, module, 1, &eventsString).ToLocalChecked()->ToObject();
-
- v8::Local<v8::Object> EventEmitter = Nan::Get(events,
- Nan::New("EventEmitter").ToLocalChecked()).ToLocalChecked()->ToObject();
+ v8::Local<v8::Object> events = Nan::To<v8::Object>(Nan::Call(require, module, 1, &eventsString).ToLocalChecked()).ToLocalChecked();
+
+ v8::Local<v8::Object> EventEmitter = Nan::To<v8::Object>(
+ Nan::Get(
+ events,
+ Nan::New("EventEmitter").ToLocalChecked()
+ ).ToLocalChecked()
+ ).ToLocalChecked();
Nan::SetPrototype(target,
Nan::Get(EventEmitter, Nan::New("prototype").ToLocalChecked()).ToLocalChecked());
diff --git a/platform/node/src/node_request.cpp b/platform/node/src/node_request.cpp
index b4016eabad..b9a6779a8f 100644
--- a/platform/node/src/node_request.cpp
+++ b/platform/node/src/node_request.cpp
@@ -69,10 +69,10 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf
if (info.Length() < 1) {
response.noContent = true;
} else if (info[0]->IsObject()) {
- auto err = info[0]->ToObject();
+ auto err = Nan::To<v8::Object>(info[0]).ToLocalChecked();
auto msg = Nan::New("message").ToLocalChecked();
- if (Nan::Has(err, msg).IsJust()) {
+ if (Nan::Has(err, msg).FromJust()) {
request->SetErrorMessage(*Nan::Utf8String(
Nan::Get(err, msg).ToLocalChecked()));
}
@@ -83,7 +83,7 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf
} else {
auto res = Nan::To<v8::Object>(info[1]).ToLocalChecked();
- if (Nan::Has(res, Nan::New("modified").ToLocalChecked()).IsJust()) {
+ if (Nan::Has(res, Nan::New("modified").ToLocalChecked()).FromJust()) {
const double modified = Nan::To<double>(Nan::Get(res, Nan::New("modified").ToLocalChecked()).ToLocalChecked()).FromJust();
if (!std::isnan(modified)) {
response.modified = mbgl::Timestamp{ mbgl::Seconds(
@@ -91,7 +91,7 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf
}
}
- if (Nan::Has(res, Nan::New("expires").ToLocalChecked()).IsJust()) {
+ if (Nan::Has(res, Nan::New("expires").ToLocalChecked()).FromJust()) {
const double expires = Nan::To<double>(Nan::Get(res, Nan::New("expires").ToLocalChecked()).ToLocalChecked()).FromJust();
if (!std::isnan(expires)) {
response.expires = mbgl::Timestamp{ mbgl::Seconds(
@@ -99,12 +99,12 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf
}
}
- if (Nan::Has(res, Nan::New("etag").ToLocalChecked()).IsJust()) {
+ if (Nan::Has(res, Nan::New("etag").ToLocalChecked()).FromJust()) {
const Nan::Utf8String etag(Nan::Get(res, Nan::New("etag").ToLocalChecked()).ToLocalChecked());
response.etag = std::string { *etag, size_t(etag.length()) };
}
- if (Nan::Has(res, Nan::New("data").ToLocalChecked()).IsJust()) {
+ if (Nan::Has(res, Nan::New("data").ToLocalChecked()).FromJust()) {
auto data = Nan::Get(res, Nan::New("data").ToLocalChecked()).ToLocalChecked();
if (node::Buffer::HasInstance(data)) {
response.data = std::make_shared<std::string>(
diff --git a/platform/node/src/node_request.hpp b/platform/node/src/node_request.hpp
index 27b7716481..da6149be2d 100644
--- a/platform/node/src/node_request.hpp
+++ b/platform/node/src/node_request.hpp
@@ -13,7 +13,8 @@ namespace node_mbgl {
class NodeMap;
-class NodeRequest : public Nan::ObjectWrap, public Nan::AsyncWorker {
+class NodeRequest : public Nan::ObjectWrap,
+ public Nan::AsyncWorker {
public:
NodeRequest(NodeMap*, mbgl::FileSource::Callback);
~NodeRequest();