From 2ccb9bef497dbc0f68b39a4a94ff7e43061a0ceb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 24 Sep 2022 12:12:42 +0200 Subject: [PATCH] LibWeb: Remove now-unnecessary JS::Handles in HTML task capture lists JS::SafeFunction will protect anything captures for HTML tasks now. --- .../Libraries/LibWeb/Bindings/MainThreadVM.cpp | 12 ++++++------ Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/MessagePort.cpp | 6 +++--- .../LibWeb/HTML/Scripting/Environments.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/Window.cpp | 14 +++++++------- .../Libraries/LibWeb/XML/XMLDocumentBuilder.cpp | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index d74438acbf..85f9cd88bd 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -124,14 +124,14 @@ JS::VM& main_thread_vm() // 5. Queue a global task on the DOM manipulation task source given global to fire an event named rejectionhandled at global, using PromiseRejectionEvent, // with the promise attribute initialized to promise, and the reason attribute initialized to the value of promise's [[PromiseResult]] internal slot. - HTML::queue_global_task(HTML::Task::Source::DOMManipulation, global, [global = JS::make_handle(&global), promise = JS::make_handle(&promise)]() mutable { + HTML::queue_global_task(HTML::Task::Source::DOMManipulation, global, [&global, &promise]() mutable { // FIXME: This currently assumes that global is a WindowObject. - auto& window = verify_cast(*global.cell()); + auto& window = verify_cast(global); HTML::PromiseRejectionEventInit event_init { {}, // Initialize the inherited DOM::EventInit /* .promise = */ promise, - /* .reason = */ promise.cell()->result(), + /* .reason = */ promise.result(), }; auto promise_rejection_event = HTML::PromiseRejectionEvent::create(window, HTML::EventNames::rejectionhandled, event_init); window.dispatch_event(*promise_rejection_event); @@ -179,9 +179,9 @@ JS::VM& main_thread_vm() auto& global = finalization_registry.realm().global_object(); // 2. Queue a global task on the JavaScript engine task source given global to perform the following steps: - HTML::queue_global_task(HTML::Task::Source::JavaScriptEngine, global, [finalization_registry = JS::make_handle(&finalization_registry)]() mutable { + HTML::queue_global_task(HTML::Task::Source::JavaScriptEngine, global, [&finalization_registry]() mutable { // 1. Let entry be finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s environment settings object. - auto& entry = verify_cast(*finalization_registry.cell()->cleanup_callback().callback.cell()->realm()->host_defined()); + auto& entry = verify_cast(*finalization_registry.cleanup_callback().callback.cell()->realm()->host_defined()); // 2. Check if we can run script with entry. If this returns "do not run", then return. if (entry.can_run_script() == HTML::RunScriptDecision::DoNotRun) @@ -191,7 +191,7 @@ JS::VM& main_thread_vm() entry.prepare_to_run_script(); // 4. Let result be the result of performing CleanupFinalizationRegistry(finalizationRegistry). - auto result = finalization_registry.cell()->cleanup(); + auto result = finalization_registry.cleanup(); // 5. Clean up after running script with entry. entry.clean_up_after_running_script(); diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 726354d98b..5e2e9da965 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -1105,7 +1105,7 @@ DOM::ExceptionOr BrowsingContext::traverse_the_history(size_t entry_index, if (new_document->ready_state() == "complete"sv) { // then queue a global task on the DOM manipulation task source given newDocument's relevant global object to run the following steps: - queue_global_task(Task::Source::DOMManipulation, relevant_global_object(*new_document), [new_document = JS::make_handle(*new_document)]() mutable { + queue_global_task(Task::Source::DOMManipulation, relevant_global_object(*new_document), [new_document]() mutable { // 1. If newDocument's page showing flag is true, then abort these steps. if (new_document->page_showing()) return; @@ -1174,7 +1174,7 @@ DOM::ExceptionOr BrowsingContext::traverse_the_history(size_t entry_index, // 20. If hashChanged is true, if (hash_changed) { // then queue a global task on the DOM manipulation task source given newDocument's relevant global object - queue_global_task(Task::Source::DOMManipulation, relevant_global_object(*new_document), [new_document = JS::make_handle(*new_document)]() mutable { + queue_global_task(Task::Source::DOMManipulation, relevant_global_object(*new_document), [new_document]() mutable { // to fire an event named hashchange at newDocument's relevant global object, // using HashChangeEvent, with the oldURL attribute initialized to oldURL // and the newURL attribute initialized to newURL. diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp index a7c4a982cd..aceb172125 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp @@ -87,11 +87,11 @@ void MessagePort::post_message(JS::Value message) // FIXME: This is an ad-hoc hack implementation instead, since we don't currently // have serialization and deserialization of messages. - main_thread_event_loop().task_queue().add(HTML::Task::create(HTML::Task::Source::PostedMessage, nullptr, [strong_port = JS::make_handle(*target_port), strong_message = JS::make_handle(message)]() mutable { + main_thread_event_loop().task_queue().add(HTML::Task::create(HTML::Task::Source::PostedMessage, nullptr, [target_port, message]() mutable { MessageEventInit event_init {}; - event_init.data = strong_message.value(); + event_init.data = message; event_init.origin = ""; - strong_port->dispatch_event(*MessageEvent::create(verify_cast(strong_port->realm().global_object()), HTML::EventNames::message, event_init)); + target_port->dispatch_event(*MessageEvent::create(verify_cast(target_port->realm().global_object()), HTML::EventNames::message, event_init)); })); } diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index 3d34ee10df..b35390f70d 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -195,7 +195,7 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge) auto& global = global_object(); // 5. Queue a global task on the DOM manipulation task source given global to run the following substep: - queue_global_task(Task::Source::DOMManipulation, global, [this, global = JS::make_handle(&global), list = move(list)]() mutable { + queue_global_task(Task::Source::DOMManipulation, global, [this, &global, list = move(list)]() mutable { // 1. For each promise p in list: for (auto promise_handle : list) { auto& promise = *promise_handle.cell(); @@ -217,7 +217,7 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge) /* .reason = */ promise.result(), }; // FIXME: This currently assumes that global is a WindowObject. - auto& window = verify_cast(*global.cell()); + auto& window = verify_cast(global); auto promise_rejection_event = PromiseRejectionEvent::create(window, HTML::EventNames::unhandledrejection, event_init); diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 061fae02f1..8eb5070b98 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -600,11 +600,11 @@ DOM::ExceptionOr Window::post_message_impl(JS::Value message, String const { // FIXME: This is an ad-hoc hack implementation instead, since we don't currently // have serialization and deserialization of messages. - HTML::queue_global_task(HTML::Task::Source::PostedMessage, *this, [strong_this = JS::make_handle(*this), strong_message = JS::make_handle(message)]() mutable { + HTML::queue_global_task(HTML::Task::Source::PostedMessage, *this, [this, message]() mutable { HTML::MessageEventInit event_init {}; - event_init.data = strong_message.value(); + event_init.data = message; event_init.origin = ""; - strong_this->dispatch_event(*HTML::MessageEvent::create(*strong_this, HTML::EventNames::message, event_init)); + dispatch_event(*HTML::MessageEvent::create(*this, HTML::EventNames::message, event_init)); }); return {}; } @@ -655,8 +655,8 @@ void Window::start_an_idle_period() // 5. Queue a task on the queue associated with the idle-task task source, // which performs the steps defined in the invoke idle callbacks algorithm with window and getDeadline as parameters. - HTML::queue_global_task(HTML::Task::Source::IdleTask, *this, [window = JS::make_handle(*this)]() mutable { - window->invoke_idle_callbacks(); + HTML::queue_global_task(HTML::Task::Source::IdleTask, *this, [this]() mutable { + invoke_idle_callbacks(); }); } @@ -679,8 +679,8 @@ void Window::invoke_idle_callbacks() HTML::report_exception(result); // 4. If window's list of runnable idle callbacks is not empty, queue a task which performs the steps // in the invoke idle callbacks algorithm with getDeadline and window as a parameters and return from this algorithm - HTML::queue_global_task(HTML::Task::Source::IdleTask, *this, [window = JS::make_handle(*this)]() mutable { - window->invoke_idle_callbacks(); + HTML::queue_global_task(HTML::Task::Source::IdleTask, *this, [this]() mutable { + invoke_idle_callbacks(); }); } } diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index 48b30178dc..d23574b212 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -172,7 +172,7 @@ void XMLDocumentBuilder::document_end() (void)m_document.scripts_to_execute_when_parsing_has_finished().take_first(); } // Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following substeps: - old_queue_global_task_with_document(HTML::Task::Source::DOMManipulation, m_document, [document = JS::make_handle(m_document)]() mutable { + old_queue_global_task_with_document(HTML::Task::Source::DOMManipulation, m_document, [document = &m_document]() mutable { // Set the Document's load timing info's DOM content loaded event start time to the current high resolution time given the Document's relevant global object. document->load_timing_info().dom_content_loaded_event_start_time = HTML::main_thread_event_loop().unsafe_shared_current_time(); @@ -200,7 +200,7 @@ void XMLDocumentBuilder::document_end() }); // Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following steps: - old_queue_global_task_with_document(HTML::Task::Source::DOMManipulation, m_document, [document = JS::make_handle(m_document)]() mutable { + old_queue_global_task_with_document(HTML::Task::Source::DOMManipulation, m_document, [document = &m_document]() mutable { // Update the current document readiness to "complete". document->update_readiness(HTML::DocumentReadyState::Complete);