1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/unit/test_bug641378.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +const Cc = Components.classes; 1.5 +const Ci = Components.interfaces; 1.6 + 1.7 +var timer; 1.8 + 1.9 +// This test XPConnect's ability to deal with a certain type of exception. In 1.10 +// particular, bug 641378 meant that if an exception had both 'message' and 1.11 +// 'result' properties, then it wouldn't successfully read the 'result' field 1.12 +// out of the exception (and sometimes crash). 1.13 +// 1.14 +// In order to make the test not fail completely on a negative result, we use 1.15 +// a timer. The first time through the timer, we throw our special exception. 1.16 +// Then, the second time through, we can test to see if XPConnect properly 1.17 +// dealt with our exception. 1.18 +var exception = { 1.19 + message: "oops, something failed!", 1.20 + 1.21 + tries: 0, 1.22 + get result() { 1.23 + ++this.tries; 1.24 + return 3; 1.25 + } 1.26 +}; 1.27 + 1.28 +var callback = { 1.29 + tries: 0, 1.30 + notify: function (timer) { 1.31 + if (++this.tries === 1) 1.32 + throw exception; 1.33 + 1.34 + try { 1.35 + do_check_true(exception.tries >= 1); 1.36 + } finally { 1.37 + timer.cancel(); 1.38 + timer = null; 1.39 + do_test_finished(); 1.40 + } 1.41 + } 1.42 +}; 1.43 + 1.44 +function run_test() { 1.45 + do_test_pending(); 1.46 + 1.47 + timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 1.48 + timer.initWithCallback(callback, 0, timer.TYPE_REPEATING_SLACK); 1.49 +}