diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 7568b6ab..96f4a799 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -275,12 +275,16 @@ getJasmineRequireObj().Spec = function() { } var befores = this.beforeFns() || [], - afters = this.afterFns() || []; + afters = this.afterFns() || []; var allFns = befores.concat(this.fn).concat(afters); this.queueRunner({ fns: allFns, - onException: function(e) { + onException: onException, + onComplete: complete + }); + + function onException(e) { if (Spec.isPendingSpecException(e)) { self.pend(); return; @@ -293,9 +297,7 @@ getJasmineRequireObj().Spec = function() { actual: "", error: e }); - }, - onComplete: complete - }); + } function complete() { self.result.status = self.status(); @@ -1424,15 +1426,9 @@ getJasmineRequireObj().QueueRunner = function() { for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { var fn = fns[iterativeIndex]; if (fn.length > 0) { - var attemptSuccessful = attempt(function() { - fn.call(self, function() { self.run(fns, iterativeIndex + 1); }); - }); - - if(attemptSuccessful) { - return; - } + return attemptAsync(fn); } else { - attempt(function() { fn.call(self); }); + attemptSync(fn); } } @@ -1442,18 +1438,31 @@ getJasmineRequireObj().QueueRunner = function() { this.clearStack(this.onComplete); } - function attempt(fn) { + function attemptSync(fn) { try { - fn(); - return true; + fn.call(self); } catch (e) { - self.onException(e); - if (!self.catchException(e)) { - //TODO: set a var when we catch an exception and - //use a finally block to close the loop in a nice way.. - throw e; - } - return false; + handleException(e); + } + } + + function attemptAsync(fn) { + var next = function () { self.run(fns, iterativeIndex + 1); }; + + try { + fn.call(self, next); + } catch (e) { + handleException(e); + next(); + } + } + + function handleException(e) { + self.onException(e); + if (!self.catchException(e)) { + //TODO: set a var when we catch an exception and + //use a finally block to close the loop in a nice way.. + throw e; } } }; diff --git a/src/core/QueueRunner.js b/src/core/QueueRunner.js index ac615053..fcb75ea3 100644 --- a/src/core/QueueRunner.js +++ b/src/core/QueueRunner.js @@ -20,15 +20,9 @@ getJasmineRequireObj().QueueRunner = function() { for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { var fn = fns[iterativeIndex]; if (fn.length > 0) { - var attemptSuccessful = attempt(function() { - fn.call(self, function() { self.run(fns, iterativeIndex + 1); }); - }); - - if(attemptSuccessful) { - return; - } + return attemptAsync(fn); } else { - attempt(function() { fn.call(self); }); + attemptSync(fn); } } @@ -38,18 +32,31 @@ getJasmineRequireObj().QueueRunner = function() { this.clearStack(this.onComplete); } - function attempt(fn) { + function attemptSync(fn) { try { - fn(); - return true; + fn.call(self); } catch (e) { - self.onException(e); - if (!self.catchException(e)) { - //TODO: set a var when we catch an exception and - //use a finally block to close the loop in a nice way.. - throw e; - } - return false; + handleException(e); + } + } + + function attemptAsync(fn) { + var next = function () { self.run(fns, iterativeIndex + 1); }; + + try { + fn.call(self, next); + } catch (e) { + handleException(e); + next(); + } + } + + function handleException(e) { + self.onException(e); + if (!self.catchException(e)) { + //TODO: set a var when we catch an exception and + //use a finally block to close the loop in a nice way.. + throw e; } } }; diff --git a/src/core/Spec.js b/src/core/Spec.js index 6f051a68..d5c539de 100644 --- a/src/core/Spec.js +++ b/src/core/Spec.js @@ -52,12 +52,16 @@ getJasmineRequireObj().Spec = function() { } var befores = this.beforeFns() || [], - afters = this.afterFns() || []; + afters = this.afterFns() || []; var allFns = befores.concat(this.fn).concat(afters); this.queueRunner({ fns: allFns, - onException: function(e) { + onException: onException, + onComplete: complete + }); + + function onException(e) { if (Spec.isPendingSpecException(e)) { self.pend(); return; @@ -70,9 +74,7 @@ getJasmineRequireObj().Spec = function() { actual: "", error: e }); - }, - onComplete: complete - }); + } function complete() { self.result.status = self.status();