diff --git a/src/node.cc b/src/node.cc index 89b930aa39..a9590f6512 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2644,32 +2644,38 @@ int Start(int argc, char *argv[]) { // This needs to run *before* V8::Initialize() argv = Init(argc, argv); - v8::V8::Initialize(); - v8::HandleScope handle_scope; - - // Create the one and only Context. - Persistent context = v8::Context::New(); - v8::Context::Scope context_scope(context); - - Handle process_l = SetupProcessObject(argc, argv); - v8_typed_array::AttachBindings(context->Global()); - - // Create all the objects, load modules, do everything. - // so your next reading stop should be node::Load()! - Load(process_l); - - // All our arguments are loaded. We've evaluated all of the scripts. We - // might even have created TCP servers. Now we enter the main eventloop. If - // there are no watchers on the loop (except for the ones that were - // uv_unref'd) then this function exits. As long as there are active - // watchers, it blocks. - uv_run(uv_default_loop()); - - EmitExit(process_l); + V8::Initialize(); + Persistent context; + { + Locker locker; + HandleScope handle_scope; + + // Create the one and only Context. + Persistent context = Context::New(); + Context::Scope context_scope(context); + + Handle process_l = SetupProcessObject(argc, argv); + v8_typed_array::AttachBindings(context->Global()); + + // Create all the objects, load modules, do everything. + // so your next reading stop should be node::Load()! + Load(process_l); + + // All our arguments are loaded. We've evaluated all of the scripts. We + // might even have created TCP servers. Now we enter the main eventloop. If + // there are no watchers on the loop (except for the ones that were + // uv_unref'd) then this function exits. As long as there are active + // watchers, it blocks. + uv_run(uv_default_loop()); + + EmitExit(process_l); +#ifndef NDEBUG + context.Dispose(); +#endif + } #ifndef NDEBUG // Clean up. - context.Dispose(); V8::Dispose(); #endif // NDEBUG