js/xpconnect/tests/unit/test_bug641378.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 const Cc = Components.classes;
     2 const Ci = Components.interfaces;
     4 var timer;
     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!",
    18   tries: 0,
    19   get result() {
    20     ++this.tries;
    21     return 3;
    22   }
    23 };
    25 var callback = {
    26   tries: 0,
    27   notify: function (timer) {
    28     if (++this.tries === 1)
    29       throw exception;
    31     try {
    32         do_check_true(exception.tries >= 1);
    33     } finally {
    34         timer.cancel();
    35         timer = null;
    36         do_test_finished();
    37     }
    38   }
    39 };
    41 function run_test() {
    42   do_test_pending();
    44   timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
    45   timer.initWithCallback(callback, 0, timer.TYPE_REPEATING_SLACK);
    46 }

mercurial