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.

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

mercurial