mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 23:12:08 +00:00
LibWeb: Extract run_steps_after_a_timeout()
into a separate function
This commit is contained in:
parent
aca32e298d
commit
3c288c96e6
2 changed files with 37 additions and 3 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||
#include <LibWeb/WebIDL/DOMException.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
#include <LibWeb/WebIDL/Types.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -309,9 +310,7 @@ i32 WindowOrWorkerGlobalScopeMixin::run_timer_initialization_steps(TimerHandler
|
|||
};
|
||||
|
||||
// 12. Run steps after a timeout given global, "setTimeout/setInterval", timeout, completionStep, and id.
|
||||
auto timer = Timer::create(this_impl(), timeout, move(completion_step), id);
|
||||
m_timers.set(id, timer);
|
||||
timer->start();
|
||||
run_steps_after_a_timeout_impl(timeout, move(completion_step), id);
|
||||
|
||||
// 13. Return id.
|
||||
return id;
|
||||
|
@ -554,4 +553,36 @@ void WindowOrWorkerGlobalScopeMixin::queue_the_performance_observer_task()
|
|||
});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#run-steps-after-a-timeout
|
||||
void WindowOrWorkerGlobalScopeMixin::run_steps_after_a_timeout(i32 timeout, Function<void()> completion_step)
|
||||
{
|
||||
return run_steps_after_a_timeout_impl(timeout, move(completion_step));
|
||||
}
|
||||
|
||||
void WindowOrWorkerGlobalScopeMixin::run_steps_after_a_timeout_impl(i32 timeout, Function<void()> completion_step, Optional<i32> timer_key)
|
||||
{
|
||||
// 1. Assert: if timerKey is given, then the caller of this algorithm is the timer initialization steps. (Other specifications must not pass timerKey.)
|
||||
// Note: This is enforced by the caller.
|
||||
|
||||
// 2. If timerKey is not given, then set it to a new unique non-numeric value.
|
||||
if (!timer_key.has_value())
|
||||
timer_key = m_timer_id_allocator.allocate();
|
||||
|
||||
// FIXME: 3. Let startTime be the current high resolution time given global.
|
||||
auto timer = Timer::create(this_impl(), timeout, move(completion_step), timer_key.value());
|
||||
|
||||
// FIXME: 4. Set global's map of active timers[timerKey] to startTime plus milliseconds.
|
||||
m_timers.set(timer_key.value(), timer);
|
||||
|
||||
// FIXME: 5. Run the following steps in parallel:
|
||||
// FIXME: 1. If global is a Window object, wait until global's associated Document has been fully active for a further milliseconds milliseconds (not necessarily consecutively).
|
||||
// Otherwise, global is a WorkerGlobalScope object; wait until milliseconds milliseconds have passed with the worker not suspended (not necessarily consecutively).
|
||||
// FIXME: 2. 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.
|
||||
// FIXME: 3. Optionally, wait a further implementation-defined length of time.
|
||||
// FIXME: 4. Perform completionSteps.
|
||||
// FIXME: 5. If timerKey is a non-numeric value, remove global's map of active timers[timerKey].
|
||||
|
||||
timer->start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue