core: Remove the nextTick for running the main file

Not necessary, since we can handle the error properly on the first tick
now, even if there are event listeners, etc.

Additionally, this removes the unnecessary "_needTickCallback" from
startup, since Module.loadMain() will kick off a nextTick callback right
after it runs the main module.

Fix #4856
This commit is contained in:
isaacs 2013-02-27 11:24:02 -08:00
parent 95862b2380
commit 875e4a0c59
8 changed files with 43 additions and 22 deletions

View File

@ -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() {

View File

@ -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() {

View File

@ -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:*:*

View File

@ -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

View File

@ -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

View File

@ -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:*:*

View File

@ -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:*:*

View File

@ -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