Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[node] Properly inherit from EventEmitter
Browse files Browse the repository at this point in the history
`process.EventEmitter` is deprecated, so we should use
`require('events')` instead.
  • Loading branch information
vkurchatkin authored and mikemorris committed Apr 5, 2016
1 parent 81261ca commit e886eb9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions platform/node/src/node_mapbox_gl_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()));
}
Expand Down

0 comments on commit e886eb9

Please sign in to comment.