diff --git a/src/events.cc b/src/events.cc index d9daed37b5..004ff8b07e 100644 --- a/src/events.cc +++ b/src/events.cc @@ -23,21 +23,16 @@ using namespace node; Persistent EventEmitter::constructor_template; void -EventEmitter::Initialize (Handle target) +EventEmitter::Initialize (Local ctemplate) { HandleScope scope; - Local t = FunctionTemplate::New(); - - constructor_template = Persistent::New(t); + constructor_template = Persistent::New(ctemplate); Local __emit = FunctionTemplate::New(Emit); constructor_template->PrototypeTemplate()->Set(String::NewSymbol("emit"), __emit); // All other prototype methods are defined in events.js - - target->Set(String::NewSymbol("EventEmitter"), - constructor_template->GetFunction()); } static bool diff --git a/src/events.h b/src/events.h index 115717255b..b8e38e0287 100644 --- a/src/events.h +++ b/src/events.h @@ -8,7 +8,7 @@ namespace node { class EventEmitter : public ObjectWrap { public: - static void Initialize (v8::Handle target); + static void Initialize (v8::Local ctemplate); static v8::Persistent constructor_template; bool Emit (const char *event, int argc, v8::Handle argv[]); diff --git a/src/node.cc b/src/node.cc index be68ba1e82..b61578e0d4 100644 --- a/src/node.cc +++ b/src/node.cc @@ -207,7 +207,8 @@ Load (int argc, char *argv[]) NODE_SET_METHOD(node_obj, "compile", compile); NODE_SET_METHOD(node_obj, "reallyExit", node_exit); - EventEmitter::Initialize(node_obj); + node_obj->Set(String::NewSymbol("EventEmitter"), + EventEmitter::constructor_template->GetFunction()); Promise::Initialize(node_obj); Stdio::Initialize(node_obj); @@ -305,9 +306,20 @@ main (int argc, char *argv[]) } HandleScope handle_scope; - Persistent context = Context::New(NULL, ObjectTemplate::New()); + + Local process_template = FunctionTemplate::New(); + + // The global object / "process" is an instance of EventEmitter. For + // strange reasons we must initialize EventEmitter now! it will be assign + // to it's namespace node.EventEmitter in Load() bellow. + EventEmitter::Initialize(process_template); + + Persistent context = Context::New(NULL, + process_template->InstanceTemplate()); Context::Scope context_scope(context); + context->Global()->Set(String::NewSymbol("process"), context->Global()); + Local node_obj = Load(argc, argv); ev_loop(EV_DEFAULT_UC_ 0); // main event loop