mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
31 lines
805 B
JavaScript
31 lines
805 B
JavaScript
/*global core,runtime */
|
|
/**
|
|
* An iterator that iterators through positions in a DOM tree.
|
|
* @constructor
|
|
* @param {!number} timeout
|
|
* @param {!number=} maxChecks
|
|
*/
|
|
core.LoopWatchDog = function LoopWatchDog(timeout, maxChecks) {
|
|
"use strict";
|
|
var startTime = Date.now(),
|
|
checks = 0;
|
|
function check() {
|
|
var t;
|
|
if (timeout) {
|
|
t = Date.now();
|
|
if (t - startTime > timeout) {
|
|
runtime.log("alert", "watchdog timeout");
|
|
throw "timeout!";
|
|
}
|
|
}
|
|
if (maxChecks > 0) {
|
|
checks += 1;
|
|
if (checks > maxChecks) {
|
|
runtime.log("alert", "watchdog loop overflow");
|
|
throw "loop overflow";
|
|
}
|
|
}
|
|
}
|
|
this.check = check;
|
|
};
|