From 66af549bca865872f4bf399315758559f0bc5d0b Mon Sep 17 00:00:00 2001
From: Domenic Denicola If all of the following are true
Objects that implement the Objects that implement the For entries put in the map of active timers by the timer
+ initialization steps, i.e., by Set task's timer nesting level to nesting level. Let completionStep be an algorithm step which queues a global task on the timer task source given
+ global to run task. Wait for a timeout given global, " Once the task has been processed, if repeat is false, it is safe to
+ remove the entry for handle from the map of active timers (there is no
+ way for the entry's existence to be detected past this point, so it does not technically matter
+ one way or the other). Return id. Argument conversion as defined by Web IDL (for example, invoking So for example, the following rather silly code will result in the log containing " To wait for a timeout, given a Assert: if timerKey is given, then the caller of this algorithm is the
+ timer initialization steps. (Other specifications must not pass
+ timerKey.) If timerKey is not given, set it to a new unique non-numeric value. Let startTime be the current high resolution time. Set global's map of active
- timers[id] to startTime plus timeout. Run the following steps in parallel: If global is a Otherwise, global is a Otherwise, global is a Wait until any invocations of this algorithm that had the same global, that
- started before this one, and whose timeout is equal to or less than this one's,
- have completed. Wait until any invocations of this algorithm that had the same global and
+ orderingIdentifier, that started before this one, and whose milliseconds
+ is equal to or less than this one's, have completed. Optionally, wait a further implementation-defined length of time. Queue a global task on the timer task source given
- global to run task. Once the task has been processed, if repeat is false, it is safe
- to remove the entry for id from the map of active timers (there is no
- way for the entry's existence to be detected past this point, so it does not technically
- matter one way or the other). Perform completionSteps. Return id. Argument conversion as defined by Web IDL (for example, invoking So for example, the following rather silly code will result in the log containing " Wait for a timeout is meant to be used by other specifications that
+ want to wait on developer-supplied timeouts, in a similar manner to For entries put in the map of active timers by the timer
initialization steps, i.e., by If previousId was given, let id be previousId;
otherwise, let id be an implementation-defined integer that is greater
- than zero that will identify the timeout to be set by this call in global's map
- of active timers. If the surrounding agent's event
@@ -96594,14 +96594,14 @@ enum DOMParserSupportedType {
global to run task. Wait for a timeout given global, "
@@ -96426,12 +96426,21 @@ enum DOMParserSupportedType {
WindowOrWorkerGlobalScope mixin have a map of active timers, which is a map, initially empty. Each
- key in this map is identified by a number, which must be unique
- within the list for the lifetime of the object that implements the
- WindowOrWorkerGlobalScope mixin, and each value is a
- DOMHighResTimeStamp, representing the expiry time for that timer.WindowOrWorkerGlobalScope mixin have a map
+ of active timers, which is a map, initially empty. Each key in this map is an identifier for a timer, and each value is a DOMHighResTimeStamp, representing the expiry time for that
+ timer.setTimeout() and setInterval(), the keys are numbers. For other specifications
+ that use the wait for a timeout algorithm, the identifier is a unique non-numeric
+ value. Only the numeric-keyed timers are affected by clearTimeout() and clearInterval(), but all timers contribute to idle deadline computation, and are cleared when the
+ relevant global is destroyed.
@@ -96580,10 +96589,57 @@ enum DOMParserSupportedType {
setTimeout/setInterval", timeout, completionStep, and
+ handle.toString() methods on objects passed as the first argument) happens in the
+ algorithms defined in Web IDL, before this algorithm is invoked.ONE TWO ":
+ var log = '';
+function logger(s) { log += s + ' '; }
+
+setTimeout({ toString: function () {
+ setTimeout("logger('ONE')", 100);
+ return "logger('TWO')";
+} }, 100);WindowOrWorkerGlobalScope
+ global, a string orderingIdentifier, a number milliseconds, a
+ set of steps completionSteps, and an optional value timerKey:
+
-
- Window object, wait until global's associated Document has been fully
- active for a further timeout milliseconds (not necessarily
+ active for a further milliseconds milliseconds (not necessarily
consecutively).WorkerGlobalScope object; wait
- until timeout milliseconds have passed with the worker not suspended (not
+ WorkerGlobalScope object; wait until
+ milliseconds milliseconds have passed with the worker not suspended (not
necessarily consecutively).toString() methods on objects passed as the first argument) happens in the
- algorithms defined in Web IDL, before this algorithm is invoked.ONE TWO ":
- var log = '';
-function logger(s) { log += s + ' '; }
-
-setTimeout({ toString: function () {
- setTimeout("logger('ONE')", 100);
- return "logger('TWO')";
-} }, 100);setTimeout(). (Note, however, it does not have the nesting and
+ clamping behavior of setTimeout().) Such specifications can
+ choose an orderingIdentifier to ensure ordering within their specification's timeouts,
+ while not constraining ordering with respect to other specification's timeouts.setTimeout() and setInterval(), the keys are numbers. For other specifications
- that use the wait for a timeout algorithm, the identifier is a unique non-numeric
- value. Only the numeric-keyed timers are affected by run steps after a timeout algorithm, the identifier is a unique
+ non-numeric value. Only the numeric-keyed timers are affected by clearTimeout() and clearInterval(), but all timers contribute to idle deadline computation, and are cleared when the
@@ -96483,8 +96483,8 @@ enum DOMParserSupportedType {
Run steps after a timeout given global, "setTimeout/setInterval", timeout, completionStep, and
- handle.
Once the task has been processed, if repeat is false, it is safe to - remove the entry for handle from the map of active timers (there is no - way for the entry's existence to be detected past this point, so it does not technically matter - one way or the other).
+ remove the entry for id from the map of active timers (there is no way + for the entry's existence to be detected past this point, so it does not technically matter one + way or the other).Return id.
To wait for a timeout, given a WindowOrWorkerGlobalScope
+
+
+
To run tasks of several milliseconds back to back without any delay, while still yielding back + to the browser to avoid starving the user interface (and to avoid the browser killing the script + for hogging the CPU), simply queue the next timer before performing work:
+ +function doExpensiveWork() {
+ var done = false;
+ // ...
+ // this part of the function takes up to five milliseconds
+ // set done to true if we're done
+ // ...
+ return done;
+}
+
+function rescheduleWork() {
+ var id = setTimeout(rescheduleWork, 0); // preschedule next iteration
+ if (doExpensiveWork())
+ clearTimeout(id); // clear the timeout if we don't need it
+}
+
+function scheduleWork() {
+ setTimeout(rescheduleWork, 0);
+}
+
+scheduleWork(); // queues a task to do lots of work
+ To run steps after a timeout, given a WindowOrWorkerGlobalScope
global, a string orderingIdentifier, a number milliseconds, a
set of steps completionSteps, and an optional value timerKey:
If timerKey is not given, set it to a new unique non-numeric value.
If timerKey is not given, then set it to a new unique non-numeric + value.
Let startTime be the current high resolution time.
Wait for a timeout is meant to be used by other specifications that
- want to wait on developer-supplied timeouts, in a similar manner to setTimeout(). (Note, however, it does not have the nesting and
- clamping behavior of setTimeout().) Such specifications can
- choose an orderingIdentifier to ensure ordering within their specification's timeouts,
- while not constraining ordering with respect to other specification's timeouts.
To run tasks of several milliseconds back to back without any delay, while still yielding back - to the browser to avoid starving the user interface (and to avoid the browser killing the script - for hogging the CPU), simply queue the next timer before performing work:
- -function doExpensiveWork() {
- var done = false;
- // ...
- // this part of the function takes up to five milliseconds
- // set done to true if we're done
- // ...
- return done;
-}
-
-function rescheduleWork() {
- var id = setTimeout(rescheduleWork, 0); // preschedule next iteration
- if (doExpensiveWork())
- clearTimeout(id); // clear the timeout if we don't need it
-}
+ Run steps after a timeout is meant to be used by other
+ specifications that want to execute developer-supplied code after a developer-supplied timeout,
+ in a similar manner to setTimeout(). (Note, however, it does
+ not have the nesting and clamping behavior of setTimeout().)
+ Such specifications can choose an orderingIdentifier to ensure ordering within their
+ specification's timeouts, while not constraining ordering with respect to other specification's
+ timeouts.
-function scheduleWork() {
- setTimeout(rescheduleWork, 0);
-}
-
-scheduleWork(); // queues a task to do lots of work
Objects that implement the WindowOrWorkerGlobalScope mixin have a map
- of active timers, which is a map, initially empty. Each key in this map is an identifier for a timer, and each value is a DOMHighResTimeStamp, representing the expiry time for that
timer.