mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
LibWeb: Use JS::SafeFunction in the HTML task queues
This means that HTML tasks automatically protect anything in their capture lists, and we no longer need to jump through hoops with JS::Handle etc.
This commit is contained in:
parent
131c3f50de
commit
d505192014
4 changed files with 13 additions and 11 deletions
|
@ -231,13 +231,13 @@ void EventLoop::process()
|
||||||
|
|
||||||
// FIXME: This is here to paper over an issue in the HTML parser where it'll create new interpreters (and thus ESOs) on temporary documents created for innerHTML if it uses Document::realm() to get the global object.
|
// FIXME: This is here to paper over an issue in the HTML parser where it'll create new interpreters (and thus ESOs) on temporary documents created for innerHTML if it uses Document::realm() to get the global object.
|
||||||
// Use queue_global_task instead.
|
// Use queue_global_task instead.
|
||||||
void old_queue_global_task_with_document(HTML::Task::Source source, DOM::Document& document, Function<void()> steps)
|
void old_queue_global_task_with_document(HTML::Task::Source source, DOM::Document& document, JS::SafeFunction<void()> steps)
|
||||||
{
|
{
|
||||||
main_thread_event_loop().task_queue().add(HTML::Task::create(source, &document, move(steps)));
|
main_thread_event_loop().task_queue().add(HTML::Task::create(source, &document, move(steps)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-global-task
|
// https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-global-task
|
||||||
void queue_global_task(HTML::Task::Source source, JS::Object& global_object, Function<void()> steps)
|
void queue_global_task(HTML::Task::Source source, JS::Object& global_object, JS::SafeFunction<void()> steps)
|
||||||
{
|
{
|
||||||
// 1. Let event loop be global's relevant agent's event loop.
|
// 1. Let event loop be global's relevant agent's event loop.
|
||||||
auto& global_custom_data = verify_cast<Bindings::WebEngineCustomData>(*global_object.vm().custom_data());
|
auto& global_custom_data = verify_cast<Bindings::WebEngineCustomData>(*global_object.vm().custom_data());
|
||||||
|
@ -255,7 +255,7 @@ void queue_global_task(HTML::Task::Source source, JS::Object& global_object, Fun
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/#queue-a-microtask
|
// https://html.spec.whatwg.org/#queue-a-microtask
|
||||||
void queue_a_microtask(DOM::Document* document, Function<void()> steps)
|
void queue_a_microtask(DOM::Document* document, JS::SafeFunction<void()> steps)
|
||||||
{
|
{
|
||||||
// 1. If event loop was not given, set event loop to the implied event loop.
|
// 1. If event loop was not given, set event loop to the implied event loop.
|
||||||
auto& event_loop = HTML::main_thread_event_loop();
|
auto& event_loop = HTML::main_thread_event_loop();
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <LibCore/Forward.h>
|
#include <LibCore/Forward.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
|
#include <LibJS/SafeFunction.h>
|
||||||
#include <LibWeb/HTML/EventLoop/TaskQueue.h>
|
#include <LibWeb/HTML/EventLoop/TaskQueue.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -107,9 +108,9 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
EventLoop& main_thread_event_loop();
|
EventLoop& main_thread_event_loop();
|
||||||
void old_queue_global_task_with_document(HTML::Task::Source, DOM::Document&, Function<void()> steps);
|
void old_queue_global_task_with_document(HTML::Task::Source, DOM::Document&, JS::SafeFunction<void()> steps);
|
||||||
void queue_global_task(HTML::Task::Source, JS::Object&, Function<void()> steps);
|
void queue_global_task(HTML::Task::Source, JS::Object&, JS::SafeFunction<void()> steps);
|
||||||
void queue_a_microtask(DOM::Document*, Function<void()> steps);
|
void queue_a_microtask(DOM::Document*, JS::SafeFunction<void()> steps);
|
||||||
void perform_a_microtask_checkpoint();
|
void perform_a_microtask_checkpoint();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
Task::Task(Source source, DOM::Document* document, Function<void()> steps)
|
Task::Task(Source source, DOM::Document* document, JS::SafeFunction<void()> steps)
|
||||||
: m_source(source)
|
: m_source(source)
|
||||||
, m_steps(move(steps))
|
, m_steps(move(steps))
|
||||||
, m_document(JS::make_handle(document))
|
, m_document(JS::make_handle(document))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/NonnullOwnPtr.h>
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <LibJS/Heap/Handle.h>
|
#include <LibJS/Heap/Handle.h>
|
||||||
|
#include <LibJS/SafeFunction.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -30,7 +31,7 @@ public:
|
||||||
JavaScriptEngine,
|
JavaScriptEngine,
|
||||||
};
|
};
|
||||||
|
|
||||||
static NonnullOwnPtr<Task> create(Source source, DOM::Document* document, Function<void()> steps)
|
static NonnullOwnPtr<Task> create(Source source, DOM::Document* document, JS::SafeFunction<void()> steps)
|
||||||
{
|
{
|
||||||
return adopt_own(*new Task(source, document, move(steps)));
|
return adopt_own(*new Task(source, document, move(steps)));
|
||||||
}
|
}
|
||||||
|
@ -45,10 +46,10 @@ public:
|
||||||
bool is_runnable() const;
|
bool is_runnable() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Task(Source, DOM::Document*, Function<void()> steps);
|
Task(Source, DOM::Document*, JS::SafeFunction<void()> steps);
|
||||||
|
|
||||||
Source m_source { Source::Unspecified };
|
Source m_source { Source::Unspecified };
|
||||||
Function<void()> m_steps;
|
JS::SafeFunction<void()> m_steps;
|
||||||
JS::Handle<DOM::Document> m_document;
|
JS::Handle<DOM::Document> m_document;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue