Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Introduce 'process' object. Also is the global object.

  • Loading branch information...
commit 6025da215351d43c711af56dcc2ef5b78b85618f 1 parent 31265be
@ry ry authored
Showing with 17 additions and 10 deletions.
  1. +2 −7 src/events.cc
  2. +1 −1  src/events.h
  3. +14 −2 src/node.cc
View
9 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
View
2  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[]);
View
16 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
Please sign in to comment.
Something went wrong with that request. Please try again.