mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-25 11:48:06 +00:00
LibWeb: Make TemporaryExecutionContext take a Realm&
This commit is contained in:
parent
f7a4d94b24
commit
cc91473f4d
Notes:
github-actions[bot]
2024-11-02 00:56:36 +00:00
Author: https://github.com/shannonbooth
Commit: cc91473f4d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1955
Reviewed-by: https://github.com/ADKaster ✅
34 changed files with 106 additions and 107 deletions
|
@ -397,7 +397,7 @@ void EventLoop::update_the_rendering()
|
|||
|
||||
for (auto& document : docs) {
|
||||
if (document->readiness() == HTML::DocumentReadyState::Complete && document->style_computer().number_of_css_font_faces_with_loading_in_progress() == 0) {
|
||||
HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*document), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
|
||||
HTML::TemporaryExecutionContext context(document->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
|
||||
document->fonts()->resolve_ready_promise();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> HTMLImageElement::decode(
|
|||
return false;
|
||||
|
||||
auto exception = WebIDL::EncodingError::create(realm, "Node document not fully active"_string);
|
||||
HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*this));
|
||||
HTML::TemporaryExecutionContext context(realm);
|
||||
WebIDL::reject_promise(realm, promise, exception);
|
||||
return true;
|
||||
};
|
||||
|
@ -306,7 +306,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> HTMLImageElement::decode(
|
|||
return false;
|
||||
|
||||
auto exception = WebIDL::EncodingError::create(realm, "Current request state is broken"_string);
|
||||
HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*this));
|
||||
HTML::TemporaryExecutionContext context(realm);
|
||||
WebIDL::reject_promise(realm, promise, exception);
|
||||
return true;
|
||||
};
|
||||
|
@ -354,7 +354,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> HTMLImageElement::decode(
|
|||
// (Typically, this would only be violated in low-memory situations that require evicting decoded image data, or when the image is too large
|
||||
// to keep in decoded form for this period of time.)
|
||||
|
||||
HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*this));
|
||||
HTML::TemporaryExecutionContext context(realm);
|
||||
WebIDL::resolve_promise(realm, promise, JS::js_undefined());
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -375,7 +375,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::pause()
|
|||
WebIDL::ExceptionOr<void> HTMLMediaElement::toggle_playback()
|
||||
{
|
||||
// AD-HOC: An execution context is required for Promise creation hooks.
|
||||
TemporaryExecutionContext execution_context { document().relevant_settings_object() };
|
||||
TemporaryExecutionContext execution_context { realm() };
|
||||
|
||||
if (potentially_playing())
|
||||
TRY(pause());
|
||||
|
@ -1886,7 +1886,7 @@ void HTMLMediaElement::resolve_pending_play_promises(ReadonlySpan<JS::NonnullGCP
|
|||
auto& realm = this->realm();
|
||||
|
||||
// AD-HOC: An execution context is required for Promise resolving hooks.
|
||||
TemporaryExecutionContext execution_context { document().relevant_settings_object() };
|
||||
TemporaryExecutionContext execution_context { realm };
|
||||
|
||||
// To resolve pending play promises for a media element with a list of promises promises, the user agent
|
||||
// must resolve each promise in promises with undefined.
|
||||
|
@ -1900,7 +1900,7 @@ void HTMLMediaElement::reject_pending_play_promises(ReadonlySpan<JS::NonnullGCPt
|
|||
auto& realm = this->realm();
|
||||
|
||||
// AD-HOC: An execution context is required for Promise rejection hooks.
|
||||
TemporaryExecutionContext execution_context { document().relevant_settings_object() };
|
||||
TemporaryExecutionContext execution_context { realm };
|
||||
|
||||
// To reject pending play promises for a media element with a list of promise promises and an exception name
|
||||
// error, the user agent must reject each promise in promises with error.
|
||||
|
|
|
@ -380,7 +380,7 @@ void MessagePort::post_message_task_steps(SerializedTransferRecord& serialize_wi
|
|||
auto& target_vm = target_realm.vm();
|
||||
|
||||
// 3. Let deserializeRecord be StructuredDeserializeWithTransfer(serializeWithTransferResult, targetRealm).
|
||||
TemporaryExecutionContext context { relevant_settings_object(*final_target_port) };
|
||||
TemporaryExecutionContext context { relevant_realm(*final_target_port) };
|
||||
auto deserialize_record_or_error = structured_deserialize_with_transfer(target_vm, serialize_with_transfer_result);
|
||||
if (deserialize_record_or_error.is_error()) {
|
||||
// If this throws an exception, catch it, fire an event named messageerror at finalTargetPort, using MessageEvent, and then return.
|
||||
|
|
|
@ -680,7 +680,7 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
|
|||
// to reject the finished promise for apiMethodTracker with an "InvalidStateError" DOMException.
|
||||
queue_global_task(HTML::Task::Source::NavigationAndTraversal, relevant_global_object(*this), JS::create_heap_function(heap(), [this, api_method_tracker] {
|
||||
auto& reject_realm = relevant_realm(*this);
|
||||
TemporaryExecutionContext execution_context { relevant_settings_object(*this) };
|
||||
TemporaryExecutionContext execution_context { reject_realm };
|
||||
WebIDL::reject_promise(reject_realm, api_method_tracker->finished_promise,
|
||||
WebIDL::InvalidStateError::create(reject_realm, "Cannot traverse with stale session history entry"_string));
|
||||
}));
|
||||
|
@ -712,7 +712,7 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
|
|||
auto& global = relevant_global_object(*this);
|
||||
if (result == TraversableNavigable::HistoryStepResult::CanceledByBeforeUnload) {
|
||||
queue_global_task(Task::Source::NavigationAndTraversal, global, JS::create_heap_function(heap(), [this, api_method_tracker, &realm] {
|
||||
TemporaryExecutionContext execution_context { relevant_settings_object(*this) };
|
||||
TemporaryExecutionContext execution_context { realm };
|
||||
reject_the_finished_promise(api_method_tracker, WebIDL::AbortError::create(realm, "Navigation cancelled by beforeunload"_string));
|
||||
}));
|
||||
}
|
||||
|
@ -722,7 +722,7 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
|
|||
// new "SecurityError" DOMException created in navigation's relevant realm.
|
||||
if (result == TraversableNavigable::HistoryStepResult::InitiatorDisallowed) {
|
||||
queue_global_task(Task::Source::NavigationAndTraversal, global, JS::create_heap_function(heap(), [this, api_method_tracker, &realm] {
|
||||
TemporaryExecutionContext execution_context { relevant_settings_object(*this) };
|
||||
TemporaryExecutionContext execution_context { realm };
|
||||
reject_the_finished_promise(api_method_tracker, WebIDL::SecurityError::create(realm, "Navigation disallowed from this origin"_string));
|
||||
}));
|
||||
}
|
||||
|
@ -904,7 +904,7 @@ void Navigation::notify_about_the_committed_to_entry(JS::NonnullGCPtr<Navigation
|
|||
}
|
||||
|
||||
// 3. Resolve apiMethodTracker's committed promise with nhe.
|
||||
TemporaryExecutionContext execution_context { relevant_settings_object(*this) };
|
||||
TemporaryExecutionContext execution_context { realm };
|
||||
WebIDL::resolve_promise(realm, api_method_tracker->committed_promise, nhe);
|
||||
}
|
||||
|
||||
|
@ -1088,7 +1088,7 @@ bool Navigation::inner_navigate_event_firing_algorithm(
|
|||
|
||||
// 31. Prepare to run script given navigation's relevant settings object.
|
||||
// NOTE: There's a massive spec note here
|
||||
TemporaryExecutionContext execution_context { relevant_settings_object(*this), TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
TemporaryExecutionContext execution_context { realm, TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
|
||||
// 32. If event's interception state is not "none":
|
||||
if (event->interception_state() != NavigateEvent::InterceptionState::None) {
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Web::HTML {
|
|||
// https://html.spec.whatwg.org/multipage/webappapis.html#parse-an-import-map-string
|
||||
WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, ByteString const& input, URL::URL base_url)
|
||||
{
|
||||
HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) };
|
||||
HTML::TemporaryExecutionContext execution_context { realm };
|
||||
|
||||
// 1. Let parsed be the result of parsing a JSON string to an Infra value given input.
|
||||
auto parsed = TRY(Infra::parse_json_string_to_javascript_value(realm, input));
|
||||
|
|
|
@ -9,20 +9,20 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
TemporaryExecutionContext::TemporaryExecutionContext(EnvironmentSettingsObject& environment_settings, CallbacksEnabled callbacks_enabled)
|
||||
: m_environment_settings(environment_settings)
|
||||
TemporaryExecutionContext::TemporaryExecutionContext(JS::Realm& realm, CallbacksEnabled callbacks_enabled)
|
||||
: m_realm(realm)
|
||||
, m_callbacks_enabled(callbacks_enabled)
|
||||
{
|
||||
prepare_to_run_script(m_environment_settings->realm());
|
||||
prepare_to_run_script(m_realm);
|
||||
if (m_callbacks_enabled == CallbacksEnabled::Yes)
|
||||
prepare_to_run_callback(m_environment_settings->realm());
|
||||
prepare_to_run_callback(m_realm);
|
||||
}
|
||||
|
||||
TemporaryExecutionContext::~TemporaryExecutionContext()
|
||||
{
|
||||
clean_up_after_running_script(m_environment_settings->realm());
|
||||
clean_up_after_running_script(m_realm);
|
||||
if (m_callbacks_enabled == CallbacksEnabled::Yes)
|
||||
clean_up_after_running_callback(m_environment_settings->realm());
|
||||
clean_up_after_running_callback(m_realm);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ public:
|
|||
Yes,
|
||||
};
|
||||
|
||||
explicit TemporaryExecutionContext(EnvironmentSettingsObject&, CallbacksEnabled = CallbacksEnabled::No);
|
||||
explicit TemporaryExecutionContext(JS::Realm&, CallbacksEnabled = CallbacksEnabled::No);
|
||||
~TemporaryExecutionContext();
|
||||
|
||||
private:
|
||||
JS::NonnullGCPtr<EnvironmentSettingsObject> m_environment_settings;
|
||||
JS::NonnullGCPtr<JS::Realm> m_realm;
|
||||
CallbacksEnabled m_callbacks_enabled { CallbacksEnabled::No };
|
||||
};
|
||||
|
||||
|
|
|
@ -1126,8 +1126,7 @@ WebIDL::ExceptionOr<void> Window::window_post_message_steps(JS::Value message, W
|
|||
auto& source = verify_cast<WindowProxy>(incumbent_settings.realm().global_environment().global_this_value());
|
||||
|
||||
// 4. Let deserializeRecord be StructuredDeserializeWithTransfer(serializeWithTransferResult, targetRealm).
|
||||
auto& settings_object = Bindings::host_defined_environment_settings_object(target_realm);
|
||||
auto temporary_execution_context = TemporaryExecutionContext { settings_object };
|
||||
auto temporary_execution_context = TemporaryExecutionContext { target_realm };
|
||||
auto deserialize_record_or_error = structured_deserialize_with_transfer(vm(), serialize_with_transfer_result);
|
||||
|
||||
// If this throws an exception, catch it, fire an event named messageerror at targetWindow, using MessageEvent,
|
||||
|
|
|
@ -226,7 +226,7 @@ JS::NonnullGCPtr<WebIDL::Promise> WindowOrWorkerGlobalScopeMixin::create_image_b
|
|||
// (e.g., a vector graphic with no natural size), then reject p with an "InvalidStateError" DOMException
|
||||
// and abort these steps.
|
||||
auto& realm = relevant_realm(p->promise());
|
||||
TemporaryExecutionContext context { relevant_settings_object(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
TemporaryExecutionContext context { relevant_realm(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
WebIDL::reject_promise(realm, *p, WebIDL::InvalidStateError::create(realm, "image does not contain a supported image format"_string));
|
||||
};
|
||||
|
||||
|
@ -240,7 +240,7 @@ JS::NonnullGCPtr<WebIDL::Promise> WindowOrWorkerGlobalScopeMixin::create_image_b
|
|||
auto& realm = relevant_realm(p->promise());
|
||||
|
||||
// 5. Resolve p with imageBitmap.
|
||||
TemporaryExecutionContext context { relevant_settings_object(*image_bitmap), TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
TemporaryExecutionContext context { relevant_realm(*image_bitmap), TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
WebIDL::resolve_promise(realm, *p, image_bitmap);
|
||||
return {};
|
||||
};
|
||||
|
@ -253,7 +253,7 @@ JS::NonnullGCPtr<WebIDL::Promise> WindowOrWorkerGlobalScopeMixin::create_image_b
|
|||
(void)sx;
|
||||
(void)sy;
|
||||
auto error = JS::Error::create(realm, "Not Implemented: createImageBitmap() for non-blob types"sv);
|
||||
TemporaryExecutionContext context { relevant_settings_object(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
TemporaryExecutionContext context { relevant_realm(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
WebIDL::reject_promise(realm, *p, error);
|
||||
});
|
||||
|
||||
|
@ -416,7 +416,7 @@ i32 WindowOrWorkerGlobalScopeMixin::run_timer_initialization_steps(TimerHandler
|
|||
// 11. Let completionStep be an algorithm step which queues a global task on the timer task source given global to run task.
|
||||
Function<void()> completion_step = [this, task = move(task)]() mutable {
|
||||
queue_global_task(Task::Source::TimerTask, this_impl(), JS::create_heap_function(this_impl().heap(), [this, task] {
|
||||
HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(this_impl().realm()), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
HTML::TemporaryExecutionContext execution_context { this_impl().realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
task->function()();
|
||||
}));
|
||||
};
|
||||
|
@ -587,7 +587,7 @@ void WindowOrWorkerGlobalScopeMixin::queue_the_performance_observer_task()
|
|||
// timeline task source.
|
||||
queue_global_task(Task::Source::PerformanceTimeline, this_impl(), JS::create_heap_function(this_impl().heap(), [this]() {
|
||||
auto& realm = this_impl().realm();
|
||||
HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
|
||||
// 1. Unset performance observer task queued flag of relevantGlobal.
|
||||
m_performance_observer_task_queued = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue