mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Do not run microtasks when the event loop is paused
For example, running `alert(1)` will pause the event loop, during which time no JavaScript should execute. This patch extends this disruption to microtasks. This avoids a crash inside the microtask executor, which asserts the JS execution context stack is empty. This makes us behave the same as Firefox in the following page: <script> queueMicrotask(() => { console.log("inside microtask"); }); alert("hi"); </script> Before the aforementioned assertion was added, we would execute that microtask before showing the alert. Firefox does not do this, and now we don't either.
This commit is contained in:
parent
34bf833a0a
commit
43dc0f52a6
Notes:
github-actions[bot]
2025-01-19 20:48:47 +00:00
Author: https://github.com/trflynn89
Commit: 43dc0f52a6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3309
Reviewed-by: https://github.com/tcl3 ✅
4 changed files with 42 additions and 21 deletions
|
@ -379,6 +379,30 @@ static void run_test(HeadlessWebView& view, Test& test, Application& app)
|
|||
|
||||
view.on_text_test_finish = {};
|
||||
|
||||
promise->when_resolved([&view, &test, &app](auto) {
|
||||
auto url = URL::create_with_file_scheme(MUST(FileSystem::real_path(test.input_path)));
|
||||
|
||||
switch (test.mode) {
|
||||
case TestMode::Text:
|
||||
case TestMode::Layout:
|
||||
run_dump_test(view, test, url, app.per_test_timeout_in_seconds * 1000);
|
||||
return;
|
||||
case TestMode::Ref:
|
||||
run_ref_test(view, test, url, app.per_test_timeout_in_seconds * 1000);
|
||||
return;
|
||||
case TestMode::Crash:
|
||||
run_dump_test(view, test, url, app.per_test_timeout_in_seconds * 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
});
|
||||
|
||||
view.load("about:blank"sv);
|
||||
}
|
||||
|
||||
static void set_ui_callbacks_for_tests(HeadlessWebView& view)
|
||||
{
|
||||
view.on_request_file_picker = [&](auto const& accepted_file_types, auto allow_multiple_files) {
|
||||
// Create some dummy files for tests.
|
||||
Vector<Web::HTML::SelectedFile> selected_files;
|
||||
|
@ -420,26 +444,10 @@ static void run_test(HeadlessWebView& view, Test& test, Application& app)
|
|||
view.file_picker_closed(move(selected_files));
|
||||
};
|
||||
|
||||
promise->when_resolved([&view, &test, &app](auto) {
|
||||
auto url = URL::create_with_file_scheme(MUST(FileSystem::real_path(test.input_path)));
|
||||
|
||||
switch (test.mode) {
|
||||
case TestMode::Text:
|
||||
case TestMode::Layout:
|
||||
run_dump_test(view, test, url, app.per_test_timeout_in_seconds * 1000);
|
||||
return;
|
||||
case TestMode::Ref:
|
||||
run_ref_test(view, test, url, app.per_test_timeout_in_seconds * 1000);
|
||||
return;
|
||||
case TestMode::Crash:
|
||||
run_dump_test(view, test, url, app.per_test_timeout_in_seconds * 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
});
|
||||
|
||||
view.load("about:blank"sv);
|
||||
view.on_request_alert = [&](auto const&) {
|
||||
// For tests, just close the alert right away to unblock JS execution.
|
||||
view.alert_closed();
|
||||
};
|
||||
}
|
||||
|
||||
ErrorOr<void> run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize window_size)
|
||||
|
@ -516,6 +524,7 @@ ErrorOr<void> run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize
|
|||
Vector<TestCompletion> non_passing_tests;
|
||||
|
||||
app.for_each_web_view([&](auto& view) {
|
||||
set_ui_callbacks_for_tests(view);
|
||||
view.clear_content_filters();
|
||||
|
||||
auto run_next_test = [&]() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue