Fix for AVATAR_JS-149, IdleHandle to process ticks in case of fatal error.

Reviewed-by: asquare
This commit is contained in:
Jean-Francois 2014-01-10 09:15:16 +01:00
parent 0dbecd53e6
commit dc6cfa955f
3 changed files with 35 additions and 3 deletions

View File

@ -72,7 +72,7 @@ public final class EventLoop {
private Callback isHandlerRegistered = null;
private Callback uncaughtExceptionHandler = null;
private Exception pendingException = null;
private boolean syncEventsProcessing = true;
private ScriptObjectMirror domain;
public static final class Handle implements AutoCloseable {
@ -164,10 +164,19 @@ public final class EventLoop {
} else {
processEvent(event);
}
if (!syncEventsProcessing) {
// Will be handled in an IdleHandle
break;
}
}
}
}
public void enableSyncEventsProcessing(boolean enable) {
syncEventsProcessing = enable;
}
private void processEvent(final Event event) throws Exception {
processEvent(event.getName(), event.getCallback(), event.getContext(), event.getArgs());
}

View File

@ -248,8 +248,11 @@ var gc = global.gc;
// exit is handled in the class that is catching the rethrown er
if (!caught) {
throw er;
} else {
// if we handled an error, then make sure any ticks get processed
process._needTickCallback();
}
return caught;
};

View File

@ -643,7 +643,7 @@ exports._usingDomains = function() {
}, process.domain)
}
});
}
}
Object.defineProperty(exports, 'domain', {
enumerable : true,
@ -670,6 +670,26 @@ checkHandle.unref();
var idleHandle = new IdleHandle(eventloop.loop());
idleHandle.setIdleCallback(IdleCallbackHandler);
// Handle the nextTick in a UV callback
var spinnerHandle = new IdleHandle(eventloop.loop());
spinnerHandle.setIdleCallback(spin);
var need_tick_cb = false;
function spin() {
if (!need_tick_cb) {
return;
}
need_tick_cb = false;
eventloop.enableSyncEventsProcessing(true);
spinnerHandle.stop();
exports._tickCallback();
}
exports._needTickCallback = function() {
need_tick_cb = true;
eventloop.enableSyncEventsProcessing(false);
spinnerHandle.start();
}
function checkImmediate() {
// This needs to be treated as a callback, all ticked events need to be handled.
if (exports._immediateCallback) {