Bug 846988 - Handle additional arguments to setTimeout in Timer.jsm [r=neil]

This commit is contained in:
Matt Brubeck 2013-03-02 06:46:40 -08:00
parent ddac28cf16
commit 247810ac19
2 changed files with 6 additions and 3 deletions

View File

@ -23,10 +23,11 @@ let gTimeoutTable = new Map(); // int -> nsITimer
this.setTimeout = function setTimeout(aCallback, aMilliseconds) {
let id = gNextTimeoutId++;
let args = Array.slice(arguments, 2);
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(function setTimeout_timer() {
gTimeoutTable.delete(id);
aCallback();
aCallback.apply(null, args);
}, aMilliseconds, timer.TYPE_ONE_SHOT);
gTimeoutTable.set(id, timer);

View File

@ -15,10 +15,12 @@ function run_test(browser, tab, document) {
do_check_eq(typeof timeout1, "number", "setTimeout returns a number");
do_check_true(timeout1 > 0, "setTimeout returns a positive number");
let timeout2 = imported.setTimeout(function() {
let timeout2 = imported.setTimeout(function(param1, param2) {
do_check_true(true, "Should be called");
do_check_eq(param1, 5, "first parameter is correct");
do_check_eq(param2, "test", "second parameter is correct");
do_test_finished();
}, 100);
}, 100, 5, "test");
do_check_eq(typeof timeout2, "number", "setTimeout returns a number");
do_check_true(timeout2 > 0, "setTimeout returns a positive number");