diff options
author | Ryan <ry@tinyclouds.org> | 2009-08-26 21:33:57 +0200 |
---|---|---|
committer | Ryan <ry@tinyclouds.org> | 2009-08-26 22:14:44 +0200 |
commit | 6025da215351d43c711af56dcc2ef5b78b85618f (patch) | |
tree | 1c5a871d8b3d04d104ce3e9d3b6c23b4efbd252a | |
parent | 31265be4a6584ff1b9a1ed0dedb5bc6c2f1c2e56 (diff) | |
download | node-new-6025da215351d43c711af56dcc2ef5b78b85618f.tar.gz |
Introduce 'process' object. Also is the global object.
-rw-r--r-- | src/events.cc | 9 | ||||
-rw-r--r-- | src/events.h | 2 | ||||
-rw-r--r-- | src/node.cc | 16 |
3 files changed, 17 insertions, 10 deletions
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<FunctionTemplate> EventEmitter::constructor_template; void -EventEmitter::Initialize (Handle<Object> target) +EventEmitter::Initialize (Local<FunctionTemplate> ctemplate) { HandleScope scope; - Local<FunctionTemplate> t = FunctionTemplate::New(); - - constructor_template = Persistent<FunctionTemplate>::New(t); + constructor_template = Persistent<FunctionTemplate>::New(ctemplate); Local<FunctionTemplate> __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<v8::Object> target); + static void Initialize (v8::Local<v8::FunctionTemplate> ctemplate); static v8::Persistent<v8::FunctionTemplate> constructor_template; bool Emit (const char *event, int argc, v8::Handle<v8::Value> 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 = Context::New(NULL, ObjectTemplate::New()); + + Local<FunctionTemplate> 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 = Context::New(NULL, + process_template->InstanceTemplate()); Context::Scope context_scope(context); + context->Global()->Set(String::NewSymbol("process"), context->Global()); + Local<Object> node_obj = Load(argc, argv); ev_loop(EV_DEFAULT_UC_ 0); // main event loop |