diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-03 14:54:01 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-03 16:42:34 +0200 |
commit | 6283c098ad16a7005fac53b6c1c983dbbd3776a9 (patch) | |
tree | daf930ad1cc4a9a528066927a7de1edefe5c1eec /Userland/Libraries/LibWeb/HTML/EventLoop | |
parent | 406d3199d02eed9f969f698d0f0f9ae07dba7253 (diff) | |
download | serenity-6283c098ad16a7005fac53b6c1c983dbbd3776a9.zip |
LibWeb: Improve HTML::EventLoop::spin_until()
This algorithm now saved and restores the JavaScript execution context
stack while performing a microtask checkpoint, as the spec mandates.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/EventLoop')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index dfe99831e1..a8eb9e4315 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -48,38 +48,38 @@ EventLoop& main_thread_event_loop() // https://html.spec.whatwg.org/multipage/webappapis.html#spin-the-event-loop void EventLoop::spin_until(Function<bool()> goal_condition) { - // FIXME: This is an ad-hoc hack until we implement the proper mechanism. - Core::EventLoop loop; - loop.spin_until([&]() -> bool { - if (goal_condition()) - return true; - perform_a_microtask_checkpoint(); - return goal_condition(); - }); - - // Real spec steps: - // FIXME: 1. Let task be the event loop's currently running task. // FIXME: 2. Let task source be task's source. - // FIXME: 3. Let old stack be a copy of the JavaScript execution context stack. - - // FIXME: 4. Empty the JavaScript execution context stack. + // 3. Let old stack be a copy of the JavaScript execution context stack. + // 4. Empty the JavaScript execution context stack. + auto& vm = Bindings::main_thread_vm(); + vm.save_execution_context_stack(); - // FIXME: 5. Perform a microtask checkpoint. - - // FIXME: 6. In parallel: + // 5. Perform a microtask checkpoint. + perform_a_microtask_checkpoint(); - // FIXME: 1. Wait until the condition goal is met. + // 6. In parallel: + // NOTE: We do these in reverse order here, but it shouldn't matter. - // FIXME: 2. Queue a task on task source to: + // 2. Queue a task on task source to: + // 1. Replace the JavaScript execution context stack with old stack. + vm.restore_execution_context_stack(); + // 2. Perform any steps that appear after this spin the event loop instance in the original algorithm. + // NOTE: This is achieved by returning from the function. - // FIXME: 1. Replace the JavaScript execution context stack with old stack. + // 1. Wait until the condition goal is met. + Core::EventLoop loop; + loop.spin_until([&]() -> bool { + if (goal_condition()) + return true; - // FIXME: 2. Perform any steps that appear after this spin the event loop instance in the original algorithm. + return goal_condition(); + }); - // FIXME: 7. Stop task, allowing whatever algorithm that invoked it to resume. + // 7. Stop task, allowing whatever algorithm that invoked it to resume. + // NOTE: This is achieved by returning from the function. } // https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model |