|
1 const Cc = Components.classes; |
|
2 const Ci = Components.interfaces; |
|
3 |
|
4 var timer; |
|
5 |
|
6 // This test XPConnect's ability to deal with a certain type of exception. In |
|
7 // particular, bug 641378 meant that if an exception had both 'message' and |
|
8 // 'result' properties, then it wouldn't successfully read the 'result' field |
|
9 // out of the exception (and sometimes crash). |
|
10 // |
|
11 // In order to make the test not fail completely on a negative result, we use |
|
12 // a timer. The first time through the timer, we throw our special exception. |
|
13 // Then, the second time through, we can test to see if XPConnect properly |
|
14 // dealt with our exception. |
|
15 var exception = { |
|
16 message: "oops, something failed!", |
|
17 |
|
18 tries: 0, |
|
19 get result() { |
|
20 ++this.tries; |
|
21 return 3; |
|
22 } |
|
23 }; |
|
24 |
|
25 var callback = { |
|
26 tries: 0, |
|
27 notify: function (timer) { |
|
28 if (++this.tries === 1) |
|
29 throw exception; |
|
30 |
|
31 try { |
|
32 do_check_true(exception.tries >= 1); |
|
33 } finally { |
|
34 timer.cancel(); |
|
35 timer = null; |
|
36 do_test_finished(); |
|
37 } |
|
38 } |
|
39 }; |
|
40 |
|
41 function run_test() { |
|
42 do_test_pending(); |
|
43 |
|
44 timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
|
45 timer.initWithCallback(callback, 0, timer.TYPE_REPEATING_SLACK); |
|
46 } |