1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibJS: Add VM::on_call_stack_emptied callback

Instead of having to run queued promise jobs in LibWeb in various
places, this allows us to consolidate that into one function - this is
very close to how the spec describes it as well ("at some future point
in time, when there is no running execution context and the execution
context stack is empty, the implementation must [...]").

Eventually this will also be used to log unhandled exceptions, and
possibly other actions that require JS execution to have ended.
This commit is contained in:
Linus Groh 2021-04-24 18:21:02 +02:00 committed by Andreas Kling
parent 97d49cb92b
commit 08373090ae
5 changed files with 19 additions and 9 deletions

View file

@ -54,11 +54,17 @@ void Interpreter::run(GlobalObject& global_object, const Program& program)
vm.push_call_frame(global_call_frame, global_object);
VERIFY(!vm.exception());
program.execute(*this, global_object);
// Whatever the promise jobs or on_call_stack_emptied do should not affect the effective
// 'last value'.
auto last_value = vm.last_value();
vm.pop_call_frame();
// Whatever the promise jobs do should not affect the effective 'last value'.
auto last_value = vm.last_value();
// At this point we may have already run any queued promise jobs via on_call_stack_emptied,
// in which case this is a no-op.
vm.run_queued_promise_jobs();
vm.set_last_value({}, last_value.value_or(js_undefined()));
}