michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: var timer; michael@0: michael@0: // This test XPConnect's ability to deal with a certain type of exception. In michael@0: // particular, bug 641378 meant that if an exception had both 'message' and michael@0: // 'result' properties, then it wouldn't successfully read the 'result' field michael@0: // out of the exception (and sometimes crash). michael@0: // michael@0: // In order to make the test not fail completely on a negative result, we use michael@0: // a timer. The first time through the timer, we throw our special exception. michael@0: // Then, the second time through, we can test to see if XPConnect properly michael@0: // dealt with our exception. michael@0: var exception = { michael@0: message: "oops, something failed!", michael@0: michael@0: tries: 0, michael@0: get result() { michael@0: ++this.tries; michael@0: return 3; michael@0: } michael@0: }; michael@0: michael@0: var callback = { michael@0: tries: 0, michael@0: notify: function (timer) { michael@0: if (++this.tries === 1) michael@0: throw exception; michael@0: michael@0: try { michael@0: do_check_true(exception.tries >= 1); michael@0: } finally { michael@0: timer.cancel(); michael@0: timer = null; michael@0: do_test_finished(); michael@0: } michael@0: } michael@0: }; michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); michael@0: timer.initWithCallback(callback, 0, timer.TYPE_REPEATING_SLACK); michael@0: }