Slight refactoring of clearing timeouts when an exception is thrown
This commit is contained in:
@@ -41,7 +41,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
};
|
||||
|
||||
Spec.prototype.execute = function(onComplete) {
|
||||
var self = this;
|
||||
var self = this,
|
||||
timeout;
|
||||
|
||||
this.onStart(this);
|
||||
|
||||
@@ -52,26 +53,25 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
|
||||
function timeoutable(fn) {
|
||||
return function(done) {
|
||||
var timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
||||
timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
||||
onException(new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'));
|
||||
done();
|
||||
}, j$.DEFAULT_TIMEOUT_INTERVAL]]);
|
||||
|
||||
var callDone = function() {
|
||||
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]);
|
||||
clearTimeoutable();
|
||||
done();
|
||||
};
|
||||
|
||||
try {
|
||||
fn.call(this, callDone); //TODO: do we care about more than 1 arg?
|
||||
}
|
||||
catch (e) {
|
||||
onException(e);
|
||||
callDone();
|
||||
}
|
||||
fn.call(this, callDone); //TODO: do we care about more than 1 arg?
|
||||
};
|
||||
}
|
||||
|
||||
function clearTimeoutable() {
|
||||
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]);
|
||||
timeout = void 0;
|
||||
}
|
||||
|
||||
var befores = this.beforeFns() || [],
|
||||
afters = this.afterFns() || [],
|
||||
thisOne = (this.fn.length) ? timeoutable(this.fn) : this.fn;
|
||||
@@ -84,6 +84,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
});
|
||||
|
||||
function onException(e) {
|
||||
clearTimeoutable();
|
||||
if (Spec.isPendingSpecException(e)) {
|
||||
self.pend();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user