Files
palemoon27/toolkit/modules/Timer.jsm
T
roytam1 dd3d18022d import changes from `dev' branch of rmottola/Arctic-Fox:
- include limits for  numeric_limits in gcc 11 (e46f1407b)
- Bug 1201057 - Move AutoEnterOOMUnsafeRegion to Utility.h with the other OOM simulation infrastructure r=terrence (ba11ded16)
- Bug 1189490 - Part 0: Add a FIFO queue container type to js/public. r=terrence (97bd6e58d)
- Bug 1189490 - Part 1: Add a JS::Traceable version of the FIFO queue for use with GC things. r=terrence (0e397ee31)
- Bug 1144797 - Add setInterval and clearInterval to Timer.jsm. r=smacleod. (8aee45f35)
- Bug 1182316: Part 3 - Add assertions to most other WebIDL entry points, clean up nsIDOMJSWindow cruft. r=peterv (d2af349b5)
- Bug 1181762. Remove uses of mozRequestAnimationFrame from toolkit code. r=gijs (c5d4fe108)
- Bug 1181765. Remove uses of mozRequestAnimationFrame from layout tests. r=bkelly (bd0b1300b)
- Bug 1181966. Remove uses of mozRequestAnimationFrame from browser code. r=gijs,paul (64ce1b945)
- Bug 909154. Remove the prefixed mozRequestAnimationFrame and its accoutrements. r=bkelly (0257521ce)
- Bug 1185028. Fix GCJsonifierMethod to correctly handle worker descriptors. r=nsm (32c80ced6)
- Bug 1181678 - Expose an attribute on DOMWindowUtils to see if APZ is enabled. r=botond (842c775c7)
2021-07-13 16:16:10 +08:00

55 lines
1.7 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* JS module implementation of setTimeout and clearTimeout.
*/
this.EXPORTED_SYMBOLS = ["setTimeout", "clearTimeout", "setInterval", "clearInterval"];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
// This gives us >=2^30 unique timer IDs, enough for 1 per ms for 12.4 days.
let gNextId = 1; // setTimeout and setInterval must return a positive integer
let gTimerTable = new Map(); // int -> nsITimer
this.setTimeout = function setTimeout(aCallback, aMilliseconds) {
let id = gNextId++;
let args = Array.slice(arguments, 2);
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(function setTimeout_timer() {
gTimerTable.delete(id);
aCallback.apply(null, args);
}, aMilliseconds, timer.TYPE_ONE_SHOT);
gTimerTable.set(id, timer);
return id;
}
this.setInterval = function setInterval(aCallback, aMilliseconds) {
let id = gNextId++;
let args = Array.slice(arguments, 2);
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(function setInterval_timer() {
aCallback.apply(null, args);
}, aMilliseconds, timer.TYPE_REPEATING_SLACK);
gTimerTable.set(id, timer);
return id;
}
this.clearInterval = this.clearTimeout = function clearTimeout(aId) {
if (gTimerTable.has(aId)) {
gTimerTable.get(aId).cancel();
gTimerTable.delete(aId);
}
}