mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:55:08 +00:00
LibWeb: Pass around JS::HeapFunctions when fetching scripts
This patch replaces the use of JS::SafeFunction for the OnFetchScriptComplete in various script fetching functions with JS::HeapFunction. The same applies for callbacks in ModuleMap. This also removes DescendantFetchingContext, which stashed the on complete function in fetch_descendants_of_a_module_script for multiple calls to fetch_internal_module_script_graph previously.
This commit is contained in:
parent
33b40eaeed
commit
5aa7c51956
5 changed files with 83 additions and 87 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
||||
* Copyright (c) 2022-2023, networkException <networkexception@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -15,7 +15,9 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
using OnFetchScriptComplete = JS::SafeFunction<void(JS::GCPtr<Script>)>;
|
||||
using OnFetchScriptComplete = JS::NonnullGCPtr<JS::HeapFunction<void(JS::GCPtr<Script>)>>;
|
||||
|
||||
OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<void(JS::GCPtr<Script>)> function);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#script-fetch-options
|
||||
struct ScriptFetchOptions {
|
||||
|
@ -41,31 +43,6 @@ struct ScriptFetchOptions {
|
|||
Fetch::Infrastructure::Request::Priority fetch_priority {};
|
||||
};
|
||||
|
||||
class DescendantFetchingContext : public RefCounted<DescendantFetchingContext> {
|
||||
public:
|
||||
static NonnullRefPtr<DescendantFetchingContext> create() { return adopt_ref(*new DescendantFetchingContext); }
|
||||
|
||||
~DescendantFetchingContext() = default;
|
||||
|
||||
size_t pending_count() const { return m_pending_count; }
|
||||
void set_pending_count(size_t count) { m_pending_count = count; }
|
||||
void decrement_pending_count() { --m_pending_count; }
|
||||
|
||||
bool failed() const { return m_failed; }
|
||||
void set_failed(bool failed) { m_failed = failed; }
|
||||
|
||||
void on_complete(JavaScriptModuleScript* module_script) { m_on_complete(module_script); }
|
||||
void set_on_complete(OnFetchScriptComplete on_complete) { m_on_complete = move(on_complete); }
|
||||
|
||||
private:
|
||||
DescendantFetchingContext() = default;
|
||||
|
||||
size_t m_pending_count { 0 };
|
||||
bool m_failed { false };
|
||||
|
||||
OnFetchScriptComplete m_on_complete;
|
||||
};
|
||||
|
||||
DeprecatedString module_type_from_module_request(JS::ModuleRequest const&);
|
||||
WebIDL::ExceptionOr<AK::URL> resolve_module_specifier(Optional<Script&> referring_script, DeprecatedString const& specifier);
|
||||
WebIDL::ExceptionOr<Optional<AK::URL>> resolve_imports_match(DeprecatedString const& normalized_specifier, Optional<AK::URL> as_url, ModuleSpecifierMap const&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue