Introduce 'process' object. Also is the global object.
This commit is contained in:
parent
31265be4a6
commit
6025da2153
@ -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
|
||||
|
@ -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[]);
|
||||
|
16
src/node.cc
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user