mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-24 03:52:58 +00:00
LibWeb: Implement the timeout step of execute_async_script
This commit is contained in:
parent
23b378822b
commit
b0adf96eff
Notes:
sideshowbarker
2024-07-17 06:45:52 +09:00
Author: https://github.com/stelar7
Commit: b0adf96eff
Pull-request: https://github.com/SerenityOS/serenity/pull/20694
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 17 additions and 3 deletions
|
@ -331,6 +331,10 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
|
|||
auto& vm = window->vm();
|
||||
auto start = MonotonicTime::now();
|
||||
|
||||
auto has_timed_out = [&] {
|
||||
return timeout.has_value() && (MonotonicTime::now() - start) > Duration::from_seconds(static_cast<i64>(*timeout));
|
||||
};
|
||||
|
||||
// AD-HOC: An execution context is required for Promise creation hooks.
|
||||
HTML::TemporaryExecutionContext execution_context { document->relevant_settings_object() };
|
||||
|
||||
|
@ -381,7 +385,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
|
|||
vm.custom_data()->spin_event_loop_until([&] {
|
||||
if (script_promise.state() != JS::Promise::State::Pending)
|
||||
return true;
|
||||
if (timeout.has_value() && (MonotonicTime::now() - start) > Duration::from_seconds(static_cast<i64>(*timeout)))
|
||||
if (has_timed_out())
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
|
@ -395,12 +399,22 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
|
|||
WebIDL::reject_promise(realm, promise_capability, script_promise.result());
|
||||
}();
|
||||
|
||||
// FIXME: 6. If promise is still pending and session script timeout milliseconds is reached, return error with error code script timeout.
|
||||
|
||||
// 6. If promise is still pending and session script timeout milliseconds is reached, return error with error code script timeout.
|
||||
vm.custom_data()->spin_event_loop_until([&] {
|
||||
if (has_timed_out()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return promise->state() != JS::Promise::State::Pending;
|
||||
});
|
||||
|
||||
if (has_timed_out()) {
|
||||
auto error_object = JsonObject {};
|
||||
error_object.set("name", "Error");
|
||||
error_object.set("message", "script timeout");
|
||||
return { ExecuteScriptResultType::Timeout, move(error_object) };
|
||||
}
|
||||
|
||||
auto json_value_or_error = json_clone(realm, promise->result());
|
||||
if (json_value_or_error.is_error()) {
|
||||
auto error_object = JsonObject {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue