diff --git a/lib/module.js b/lib/module.js index a7c7115566..27bba73acc 100644 --- a/lib/module.js +++ b/lib/module.js @@ -495,6 +495,8 @@ Module._extensions['.node'] = process.dlopen; Module.runMain = function() { // Load the main module--the command line argument. Module._load(process.argv[1], null, true); + // Handle any nextTicks added in the first tick of the program + process._tickCallback(); }; Module._initPaths = function() { diff --git a/src/node.js b/src/node.js index 5ef6e3c478..acb2840e7c 100644 --- a/src/node.js +++ b/src/node.js @@ -114,10 +114,8 @@ setTimeout(Module.runMain, debugTimeout); } else { - // REMOVEME: nextTick should not be necessary. This hack to get - // test/simple/test-exception-handler2.js working. // Main entry point into most programs: - process.nextTick(Module.runMain); + Module.runMain(); } } else { @@ -156,8 +154,6 @@ }); } } - - process._needTickCallback(); } startup.globalVariables = function() { diff --git a/test/message/error_exit.out b/test/message/error_exit.out index acdd424ca9..11ea76fd72 100644 --- a/test/message/error_exit.out +++ b/test/message/error_exit.out @@ -9,6 +9,6 @@ AssertionError: 1 == 2 at Object.Module._extensions..js (module.js:*:*) at Module.load (module.js:*:*) at Function.Module._load (module.js:*:*) - at Module.runMain (module.js:*:*) - at _tickCallback (node.js:*:*) - at process._tickFromSpinner (node.js:*:*) + at Function.Module.runMain (module.js:*:*) + at startup (node.js:*:*) + at node.js:*:* diff --git a/test/message/max_tick_depth.out b/test/message/max_tick_depth.out index aa9876b2be..f285484508 100644 --- a/test/message/max_tick_depth.out +++ b/test/message/max_tick_depth.out @@ -7,8 +7,8 @@ tick 15 tick 14 tick 13 tick 12 -(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. tick 11 +(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. tick 10 tick 9 tick 8 @@ -18,6 +18,6 @@ tick 5 tick 4 tick 3 tick 2 -(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. tick 1 +(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. tick 0 diff --git a/test/message/max_tick_depth_trace.out b/test/message/max_tick_depth_trace.out index 180e5c90f4..8671a8aac3 100644 --- a/test/message/max_tick_depth_trace.out +++ b/test/message/max_tick_depth_trace.out @@ -7,13 +7,15 @@ tick 15 tick 14 tick 13 tick 12 +tick 11 Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. at maxTickWarn (node.js:*:*) - at process.nextTick (node.js:*:* + at process.nextTick (node.js:*:*) at f (*test*message*max_tick_depth_trace.js:*:*) - at _tickCallback (node.js:*:*) - at process._tickFromSpinner (node.js:*:*) -tick 11 + at process._tickCallback (node.js:*:*) + at Function.Module.runMain (module.js:*:*) + at startup (node.js:*:*) + at node.js:*:* tick 10 tick 9 tick 8 @@ -23,11 +25,11 @@ tick 5 tick 4 tick 3 tick 2 +tick 1 Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. at maxTickWarn (node.js:*:*) - at process.nextTick (node.js:*:* + at process.nextTick (node.js:*:*) at f (*test*message*max_tick_depth_trace.js:*:*) at _tickCallback (node.js:*:*) at process._tickFromSpinner (node.js:*:*) -tick 1 tick 0 diff --git a/test/message/nexttick_throw.out b/test/message/nexttick_throw.out index 7f9d4e2bab..baced2ce87 100644 --- a/test/message/nexttick_throw.out +++ b/test/message/nexttick_throw.out @@ -1,7 +1,10 @@ + *test*message*nexttick_throw.js:* undefined_reference_error_maker; ^ ReferenceError: undefined_reference_error_maker is not defined at *test*message*nexttick_throw.js:*:* - at _tickCallback (node.js:*:*) - at process._tickFromSpinner (node.js:*:*) + at process._tickCallback (node.js:*:*) + at Function.Module.runMain (module.js:*:*) + at startup (node.js:*:*) + at node.js:*:* diff --git a/test/message/undefined_reference_in_new_context.out b/test/message/undefined_reference_in_new_context.out index 983023b407..f8095ce337 100644 --- a/test/message/undefined_reference_in_new_context.out +++ b/test/message/undefined_reference_in_new_context.out @@ -9,7 +9,7 @@ ReferenceError: foo is not defined at Module._compile (module.js:*) at *..js (module.js:*) at Module.load (module.js:*) - at *._load (module.js:*) - at Module.runMain (module.js:*) - at _tickCallback (node.js:*) - at *._tickFromSpinner (node.js:*) + at Function.Module._load (module.js:*:*) + at Function.Module.runMain (module.js:*:*) + at startup (node.js:*:*) + at node.js:*:* diff --git a/test/simple/test-domain.js b/test/simple/test-domain.js index c47e2d7352..f77217e4a3 100644 --- a/test/simple/test-domain.js +++ b/test/simple/test-domain.js @@ -110,6 +110,12 @@ d.on('error', function(er) { assert.ok(!er.domainBound); break; + case 'nextTick execution loop': + assert.equal(er.domain, d); + assert.ok(!er.domainEmitter); + assert.ok(!er.domainBound); + break; + default: console.error('unexpected error, throwing %j', er.message, er); throw er; @@ -127,6 +133,18 @@ process.on('exit', function() { }); + +// revert to using the domain when a callback is passed to nextTick in +// the middle of a tickCallback loop +d.run(function() { + process.nextTick(function() { + throw new Error('nextTick execution loop'); + }); +}); +expectCaught++; + + + // catch thrown errors no matter how many times we enter the event loop // this only uses implicit binding, except for the first function // passed to d.run(). The rest are implicitly bound by virtue of being