summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Kurchatkin <vladimir.kurchatkin@gmail.com>2016-04-02 00:19:18 +0300
committerMike Morris <mikemorris@users.noreply.github.com>2016-04-05 16:00:59 -0400
commite886eb95455335818972cafd65923a7fe8d83e49 (patch)
tree06d16e1b6b3f1b306bfde168d5f5d0525947cafe
parent81261cafaba781293d8359fa609373afab3c6337 (diff)
downloadqtlocation-mapboxgl-e886eb95455335818972cafd65923a7fe8d83e49.tar.gz
[node] Properly inherit from EventEmitter
`process.EventEmitter` is deprecated, so we should use `require('events')` instead.
-rw-r--r--platform/node/src/node_mapbox_gl_native.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/platform/node/src/node_mapbox_gl_native.cpp b/platform/node/src/node_mapbox_gl_native.cpp
index e0b094d570..2a9e9fb6c3 100644
--- a/platform/node/src/node_mapbox_gl_native.cpp
+++ b/platform/node/src/node_mapbox_gl_native.cpp
@@ -19,7 +19,7 @@ mbgl::util::RunLoop& NodeRunLoop() {
}
-NAN_MODULE_INIT(RegisterModule) {
+void RegisterModule(v8::Local<v8::Object> target, v8::Local<v8::Object> module) {
// This has the effect of:
// a) Ensuring that the static local variable is initialized before any thread contention.
// b) unreffing an async handle, which otherwise would keep the default loop running.
@@ -63,16 +63,19 @@ NAN_MODULE_INIT(RegisterModule) {
Nan::New("Resource").ToLocalChecked(),
resource);
- // Make the exported object inherit from process.EventEmitter
- v8::Local<v8::Object> process = Nan::Get(
- Nan::GetCurrentContext()->Global(),
- Nan::New("process").ToLocalChecked()).ToLocalChecked()->ToObject();
+ // Make the exported object inherit from EventEmitter
+ v8::Local<v8::Function> require = Nan::Get(module,
+ Nan::New("require").ToLocalChecked()).ToLocalChecked().As<v8::Function>();
- v8::Local<v8::Object> EventEmitter = Nan::Get(process,
+ 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();
Nan::SetPrototype(target,
Nan::Get(EventEmitter, Nan::New("prototype").ToLocalChecked()).ToLocalChecked());
+ Nan::CallAsFunction(EventEmitter, target, 0, nullptr);
mbgl::Log::setObserver(std::make_unique<node_mbgl::NodeLogObserver>(target->ToObject()));
}