From c7b24efd21f5c02a519c429180245ed8c3c320f1 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 11 Nov 2010 16:33:21 -0800 Subject: [PATCH] Move ev_loop out of javascript --- src/node.cc | 38 ++++++++++++------- src/node.js | 9 ----- .../undefined_reference_in_new_context.out | 1 - 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/node.cc b/src/node.cc index d0931a7777..eddd78619d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1030,19 +1030,6 @@ Local ExecuteString(Local source, Local filename) { } -static Handle Loop(const Arguments& args) { - HandleScope scope; - assert(args.Length() == 0); - - // TODO Probably don't need to start this each time. - // Avoids failing on test/simple/test-eio-race3.js though - ev_idle_start(EV_DEFAULT_UC_ &eio_poller); - - ev_loop(EV_DEFAULT_UC_ 0); - return Undefined(); -} - - static Handle Chdir(const Arguments& args) { HandleScope scope; @@ -1666,7 +1653,6 @@ static void Load(int argc, char *argv[]) { // define various internal methods - NODE_SET_METHOD(process, "loop", Loop); NODE_SET_METHOD(process, "compile", Compile); NODE_SET_METHOD(process, "_needTickCallback", NeedTickCallback); NODE_SET_METHOD(process, "reallyExit", Exit); @@ -1982,6 +1968,30 @@ int Start(int argc, char *argv[]) { // so your next reading stop should be node::Load()! node::Load(argc, argv); + // TODO Probably don't need to start this each time. + // Avoids failing on test/simple/test-eio-race3.js though + ev_idle_start(EV_DEFAULT_UC_ &eio_poller); + + // 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 + // ev_unref'd) then this function exits. As long as there are active + // watchers, it blocks. + ev_loop(EV_DEFAULT_UC_ 0); + + + // process.emit('exit') + Local emit_v = process->Get(String::New("emit")); + assert(emit_v->IsFunction()); + Local emit = Local::Cast(emit_v); + Local args[] = { String::New("exit") }; + TryCatch try_catch; + emit->Call(process, 1, args); + if (try_catch.HasCaught()) { + FatalException(try_catch); + } + + #ifndef NDEBUG // Clean up. context.Dispose(); diff --git a/src/node.js b/src/node.js index f0c8c3042a..04ad4b9e3d 100644 --- a/src/node.js +++ b/src/node.js @@ -608,13 +608,4 @@ if (process.argv[1]) { module.requireNative('repl').start(); } -// 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 -// ev_unref'd) then this function exits. As long as there are active -// watchers, it blocks. -process.loop(); - -process.emit("exit"); - }); diff --git a/test/message/undefined_reference_in_new_context.out b/test/message/undefined_reference_in_new_context.out index bf5d8945ed..09bf7754b0 100644 --- a/test/message/undefined_reference_in_new_context.out +++ b/test/message/undefined_reference_in_new_context.out @@ -11,4 +11,3 @@ ReferenceError: foo is not defined at Module.load (node.js:*) at Array. (node.js:*) at EventEmitter._tickCallback (node.js:*) - at node.js:*