Browse Source

Clean up context creation

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
48452838b3
  1. 15
      src/node.cc

15
src/node.cc

@ -734,13 +734,17 @@ static void ExecuteNativeJS(const char *filename, const char *data) {
static Local<Object> Load(int argc, char *argv[]) { static Local<Object> Load(int argc, char *argv[]) {
HandleScope scope; HandleScope scope;
Local<Object> global = Context::GetCurrent()->Global();
// Assign the global object to it's place as 'GLOBAL'
global->Set(String::NewSymbol("GLOBAL"), global);
Local<FunctionTemplate> process_template = FunctionTemplate::New(); Local<FunctionTemplate> process_template = FunctionTemplate::New();
node::EventEmitter::Initialize(process_template); node::EventEmitter::Initialize(process_template);
process = Persistent<Object>::New(process_template->GetFunction()->NewInstance()); process = Persistent<Object>::New(process_template->GetFunction()->NewInstance());
// Assign the process object to its place. // Assign the process object to its place.
Local<Object> global = Context::GetCurrent()->Global();
global->Set(String::NewSymbol("process"), process); global->Set(String::NewSymbol("process"), process);
// process.version // process.version
@ -949,17 +953,10 @@ int main(int argc, char *argv[]) {
"Use 'd8 --remote_debugger' to access it.\n"); "Use 'd8 --remote_debugger' to access it.\n");
} }
// Create the 'GLOBAL' object's FunctionTemplate.
Local<FunctionTemplate> global_template = FunctionTemplate::New();
// Create the one and only Context. // Create the one and only Context.
Persistent<Context> context = Context::New(NULL, Persistent<Context> context = Context::New();
global_template->InstanceTemplate());
Context::Scope context_scope(context); Context::Scope context_scope(context);
// Actually assign the global object to it's place as 'GLOBAL'
context->Global()->Set(String::NewSymbol("GLOBAL"), context->Global());
// Create all the objects, load modules, do everything. // Create all the objects, load modules, do everything.
// so your next reading stop should be node::Load()! // so your next reading stop should be node::Load()!
node::Load(argc, argv); node::Load(argc, argv);

Loading…
Cancel
Save