From add69978e09653808aedec43ed551df22818ee30 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Wed, 22 Jul 2009 01:05:11 +0200 Subject: [PATCH] Fix a ridiculous yet harmless typo in a previous commit. Add more tests for PeriodicalExecuter. --- src/lang/periodical_executer.js | 26 ++++++++++++-------------- test/unit/periodical_executer_test.js | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/lang/periodical_executer.js b/src/lang/periodical_executer.js index e521bbf..c423262 100644 --- a/src/lang/periodical_executer.js +++ b/src/lang/periodical_executer.js @@ -49,20 +49,18 @@ var PeriodicalExecuter = Class.create({ onTimerEvent: function() { if (!this.currentlyExecuting) { - if (!this.currentlyExecuting) { - // IE doesn't support `finally` statements unless all errors are caught. - // We mimic the behaviour of `finally` statements by duplicating code - // that would belong in it. First at the bottom of the `try` statement - // (for errorless cases). Secondly, inside a `catch` statement which - // rethrows any caught errors. - try { - this.currentlyExecuting = true; - this.execute(); - this.currentlyExecuting = false; - } catch(e) { - this.currentlyExecuting = false; - throw e; - } + // IE doesn't support `finally` statements unless all errors are caught. + // We mimic the behaviour of `finally` statements by duplicating code + // that would belong in it. First at the bottom of the `try` statement + // (for errorless cases). Secondly, inside a `catch` statement which + // rethrows any caught errors. + try { + this.currentlyExecuting = true; + this.execute(); + this.currentlyExecuting = false; + } catch(e) { + this.currentlyExecuting = false; + throw e; } } } diff --git a/test/unit/periodical_executer_test.js b/test/unit/periodical_executer_test.js index 9640b33..4fa1909 100644 --- a/test/unit/periodical_executer_test.js +++ b/test/unit/periodical_executer_test.js @@ -11,5 +11,25 @@ new Test.Unit.Runner({ this.wait(600, function() { this.assertEqual(3, peEventCount); }); + }, + + testOnTimerEventMethod: function() { + var testcase = this, + pe = { + onTimerEvent: PeriodicalExecuter.prototype.onTimerEvent, + execute: function() { + testcase.assert(pe.currentlyExecuting); + } + }; + + pe.onTimerEvent(); + this.assert(!pe.currentlyExecuting); + + pe.execute = function() { + testcase.assert(pe.currentlyExecuting); + throw new Error() + } + this.assertRaise('Error', pe.onTimerEvent.bind(pe)); + this.assert(!pe.currentlyExecuting); } }); \ No newline at end of file