Permalink
Browse files

Fix process.nextTick throw call sites

So instead of:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^

You will now see:

path/to/foo.js:1
throw new Error('bar');
      ^

This is a manual port of 8140333 and
bf9d8e9 from the v0.6 branch to master branch.
  • Loading branch information...
1 parent 68f63fe commit 224720fb3ab3b3161ffb66992243167e91f9e251 @TooTallNate committed May 10, 2012
View
@@ -305,11 +305,16 @@ Module._load = function(request, parent, isMain) {
}
Module._cache[filename] = module;
+
+ var hadException = true;
+
try {
module.load(filename);
- } catch (err) {
- delete Module._cache[filename];
- throw err;
+ hadException = false;
+ } finally {
+ if (hadException) {
+ delete Module._cache[filename];
+ }
}
return module.exports;
View
@@ -257,8 +257,7 @@ static void Spin(uv_idle_t* handle, int status) {
}
-static Handle<Value> NeedTickCallback(const Arguments& args) {
- HandleScope scope;
+static void StartTickSpinner() {
need_tick_cb = true;
// TODO: this tick_spinner shouldn't be necessary. An ev_prepare should be
// sufficent, the problem is only in the case of the very last "tick" -
@@ -269,9 +268,12 @@ static Handle<Value> NeedTickCallback(const Arguments& args) {
uv_idle_start(&tick_spinner, Spin);
uv_ref(uv_default_loop());
}
- return Undefined();
}
+static Handle<Value> NeedTickCallback(const Arguments& args) {
+ StartTickSpinner();
+ return Undefined();
+}
static void PrepareTick(uv_prepare_t* handle, int status) {
assert(handle == &prepare_tick_watcher);
@@ -1839,6 +1841,9 @@ void FatalException(TryCatch &try_catch) {
ReportException(event_try_catch, true);
exit(1);
}
+
+ // This makes sure uncaught exceptions don't interfere with process.nextTick
+ StartTickSpinner();
}
View
@@ -219,35 +219,25 @@
startup.processNextTick = function() {
var nextTickQueue = [];
+ var nextTickIndex = 0;
process._tickCallback = function() {
- var l = nextTickQueue.length;
- if (l === 0) return;
+ var nextTickLength = nextTickQueue.length;
+ if (nextTickLength === 0) return;
- var q = nextTickQueue;
- nextTickQueue = [];
-
- try {
- for (var i = 0; i < l; i++) {
- var tock = q[i];
+ while (nextTickIndex < nextTickLength) {
+ var tock = nextTickQueue[nextTickIndex++];
var callback = tock.callback;
if (tock.domain) {
if (tock.domain._disposed) continue;
tock.domain.enter();
}
callback();
if (tock.domain) tock.domain.exit();
- }
- }
- catch (e) {
- if (i + 1 < l) {
- nextTickQueue = q.slice(i + 1).concat(nextTickQueue);
- }
- if (nextTickQueue.length) {
- process._needTickCallback();
- }
- throw e; // process.nextTick error, or 'error' event on first tick
}
+
+ nextTickQueue.splice(0, nextTickIndex);
+ nextTickIndex = 0;
};
process.nextTick = function(callback) {
@@ -1,6 +1,6 @@
before
-node.js:*
- throw e; // process.nextTick error, or 'error' event on first tick
- ^
+*test*message*stack_overflow.js:31
+function stackOverflow() {
+ ^
RangeError: Maximum call stack size exceeded
@@ -1,6 +1,6 @@
before
-node.js:*
- throw e; // process.nextTick error, or 'error' event on first tick
- ^
+*test*message*throw_custom_error.js:31
+throw ({ name: 'MyCustomError', message: 'This is a custom message' });
+^
MyCustomError: This is a custom message
@@ -1,6 +1,6 @@
before
-node.js:*
- throw e; // process.nextTick error, or 'error' event on first tick
- ^
+*/test/message/throw_non_error.js:31
+throw ({ foo: 'bar' });
+^
[object Object]
@@ -1,8 +1,8 @@
before
-node.js:*
- throw e; // process.nextTick error, or 'error' event on first tick
- ^
+*test*message*undefined_reference_in_new_context.js:34
+script.runInNewContext();
+ ^
ReferenceError: foo is not defined
at evalmachine.<anonymous>:*
at Object.<anonymous> (*test*message*undefined_reference_in_new_context.js:*)

0 comments on commit 224720f

Please sign in to comment.