فهرست منبع

LibWeb: Remove now-unnecessary JS::Handles in HTML task capture lists

JS::SafeFunction will protect anything captures for HTML tasks now.
Andreas Kling 2 سال پیش
والد
کامیت
2ccb9bef49

+ 6 - 6
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,
                 // 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.
                 //    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.
                     // FIXME: This currently assumes that global is a WindowObject.
-                    auto& window = verify_cast<HTML::Window>(*global.cell());
+                    auto& window = verify_cast<HTML::Window>(global);
 
 
                     HTML::PromiseRejectionEventInit event_init {
                     HTML::PromiseRejectionEventInit event_init {
                         {}, // Initialize the inherited DOM::EventInit
                         {}, // Initialize the inherited DOM::EventInit
                         /* .promise = */ promise,
                         /* .promise = */ promise,
-                        /* .reason = */ promise.cell()->result(),
+                        /* .reason = */ promise.result(),
                     };
                     };
                     auto promise_rejection_event = HTML::PromiseRejectionEvent::create(window, HTML::EventNames::rejectionhandled, event_init);
                     auto promise_rejection_event = HTML::PromiseRejectionEvent::create(window, HTML::EventNames::rejectionhandled, event_init);
                     window.dispatch_event(*promise_rejection_event);
                     window.dispatch_event(*promise_rejection_event);
@@ -179,9 +179,9 @@ JS::VM& main_thread_vm()
             auto& global = finalization_registry.realm().global_object();
             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:
             // 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.
                 // 1. Let entry be finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s environment settings object.
-                auto& entry = verify_cast<HTML::EnvironmentSettingsObject>(*finalization_registry.cell()->cleanup_callback().callback.cell()->realm()->host_defined());
+                auto& entry = verify_cast<HTML::EnvironmentSettingsObject>(*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.
                 // 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)
                 if (entry.can_run_script() == HTML::RunScriptDecision::DoNotRun)
@@ -191,7 +191,7 @@ JS::VM& main_thread_vm()
                 entry.prepare_to_run_script();
                 entry.prepare_to_run_script();
 
 
                 // 4. Let result be the result of performing CleanupFinalizationRegistry(finalizationRegistry).
                 // 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.
                 // 5. Clean up after running script with entry.
                 entry.clean_up_after_running_script();
                 entry.clean_up_after_running_script();

+ 2 - 2
Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp

@@ -1105,7 +1105,7 @@ DOM::ExceptionOr<void> BrowsingContext::traverse_the_history(size_t entry_index,
     if (new_document->ready_state() == "complete"sv) {
     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:
         // 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.
             // 1. If newDocument's page showing flag is true, then abort these steps.
             if (new_document->page_showing())
             if (new_document->page_showing())
                 return;
                 return;
@@ -1174,7 +1174,7 @@ DOM::ExceptionOr<void> BrowsingContext::traverse_the_history(size_t entry_index,
     // 20. If hashChanged is true,
     // 20. If hashChanged is true,
     if (hash_changed) {
     if (hash_changed) {
         // then queue a global task on the DOM manipulation task source given newDocument's relevant global object
         // 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,
             // to fire an event named hashchange at newDocument's relevant global object,
             // using HashChangeEvent, with the oldURL attribute initialized to oldURL
             // using HashChangeEvent, with the oldURL attribute initialized to oldURL
             // and the newURL attribute initialized to newURL.
             // and the newURL attribute initialized to newURL.

+ 3 - 3
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
     // FIXME: This is an ad-hoc hack implementation instead, since we don't currently
     //        have serialization and deserialization of messages.
     //        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 {};
         MessageEventInit event_init {};
-        event_init.data = strong_message.value();
+        event_init.data = message;
         event_init.origin = "<origin>";
         event_init.origin = "<origin>";
-        strong_port->dispatch_event(*MessageEvent::create(verify_cast<HTML::Window>(strong_port->realm().global_object()), HTML::EventNames::message, event_init));
+        target_port->dispatch_event(*MessageEvent::create(verify_cast<HTML::Window>(target_port->realm().global_object()), HTML::EventNames::message, event_init));
     }));
     }));
 }
 }
 
 

+ 2 - 2
Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp

@@ -195,7 +195,7 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge<EventLoop>)
     auto& global = global_object();
     auto& global = global_object();
 
 
     // 5. Queue a global task on the DOM manipulation task source given global to run the following substep:
     // 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:
         // 1. For each promise p in list:
         for (auto promise_handle : list) {
         for (auto promise_handle : list) {
             auto& promise = *promise_handle.cell();
             auto& promise = *promise_handle.cell();
@@ -217,7 +217,7 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge<EventLoop>)
                 /* .reason = */ promise.result(),
                 /* .reason = */ promise.result(),
             };
             };
             // FIXME: This currently assumes that global is a WindowObject.
             // FIXME: This currently assumes that global is a WindowObject.
-            auto& window = verify_cast<HTML::Window>(*global.cell());
+            auto& window = verify_cast<HTML::Window>(global);
 
 
             auto promise_rejection_event = PromiseRejectionEvent::create(window, HTML::EventNames::unhandledrejection, event_init);
             auto promise_rejection_event = PromiseRejectionEvent::create(window, HTML::EventNames::unhandledrejection, event_init);
 
 

+ 7 - 7
Userland/Libraries/LibWeb/HTML/Window.cpp

@@ -600,11 +600,11 @@ DOM::ExceptionOr<void> Window::post_message_impl(JS::Value message, String const
 {
 {
     // FIXME: This is an ad-hoc hack implementation instead, since we don't currently
     // FIXME: This is an ad-hoc hack implementation instead, since we don't currently
     //        have serialization and deserialization of messages.
     //        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 {};
         HTML::MessageEventInit event_init {};
-        event_init.data = strong_message.value();
+        event_init.data = message;
         event_init.origin = "<origin>";
         event_init.origin = "<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 {};
     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,
     // 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.
     //    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);
             HTML::report_exception(result);
         // 4. If window's list of runnable idle callbacks is not empty, queue a task which performs the steps
         // 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
         //    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();
         });
         });
     }
     }
 }
 }

+ 2 - 2
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();
         (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:
     // 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.
         // 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();
         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:
     // 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".
         // Update the current document readiness to "complete".
         document->update_readiness(HTML::DocumentReadyState::Complete);
         document->update_readiness(HTML::DocumentReadyState::Complete);