Save the prototype of EventEmitter
This commit is contained in:
parent
892026458d
commit
895b8b47ee
3 changed files with 40 additions and 0 deletions
|
@ -10,10 +10,15 @@
|
|||
#include "native_mate/object_template_builder.h"
|
||||
#include "ui/events/event_constants.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
namespace {
|
||||
|
||||
// The prototype of Node's EventEmitter.
|
||||
v8::Persistent<v8::Object> g_event_emitter_prototype;
|
||||
|
||||
v8::Persistent<v8::ObjectTemplate> event_template;
|
||||
|
||||
void PreventDefault(mate::Arguments* args) {
|
||||
|
@ -75,6 +80,29 @@ v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags) {
|
|||
return obj.GetHandle();
|
||||
}
|
||||
|
||||
void InheritFromEventEmitter(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> constructor) {
|
||||
}
|
||||
|
||||
void SetEventEmitterPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> prototype) {
|
||||
g_event_emitter_prototype.Reset(isolate, prototype);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace mate
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
mate::Dictionary(context->GetIsolate(), exports)
|
||||
.SetMethod("setEventEmitterPrototype",
|
||||
&mate::internal::SetEventEmitterPrototype);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_event_emitter, Initialize)
|
||||
|
|
|
@ -32,6 +32,9 @@ v8::Local<v8::Object> CreateCustomEvent(
|
|||
v8::Local<v8::Object> event);
|
||||
v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags);
|
||||
|
||||
void InheritFromEventEmitter(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> constructor);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Provide helperers to emit event in JavaScript.
|
||||
|
@ -87,6 +90,11 @@ class EventEmitter : public Wrappable<T> {
|
|||
protected:
|
||||
EventEmitter() {}
|
||||
|
||||
static void InheritFromEventEmitter(
|
||||
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> constructor) {
|
||||
internal::InheritFromEventEmitter(isolate, constructor);
|
||||
}
|
||||
|
||||
private:
|
||||
// this.emit(name, event, args...);
|
||||
template<typename... Args>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue