From ad9f70dff95769f71564c246c4193ad5f3dd79d0 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Thu, 6 Mar 2025 12:10:30 -0800 Subject: [PATCH] LibWeb: Clean up unused module script fetching algorithms This patch removes those unused 2 algorithms: 1. `fetch_internal_module_script_graph` 2. `fetch_descendants_of_a_module_script` Those 2 algorithms were removed in spec and are not used in our codebase. --- Libraries/LibWeb/HTML/Scripting/Fetching.cpp | 125 ------------------- Libraries/LibWeb/HTML/Scripting/Fetching.h | 2 - 2 files changed, 127 deletions(-) diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp index c1ce4bfda09..f19e34da093 100644 --- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp +++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp @@ -593,131 +593,6 @@ WebIDL::ExceptionOr fetch_worklet_module_worker_script_graph(URL::URL cons return {}; } -// https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure -void fetch_internal_module_script_graph(JS::Realm& realm, JS::ModuleRequest const& module_request, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination destination, ScriptFetchOptions const& options, Script& referring_script, HashTable const& visited_set, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete) -{ - // 1. Let url be the result of resolving a module specifier given referringScript and moduleRequest.[[Specifier]]. - auto url = MUST(resolve_module_specifier(referring_script, module_request.module_specifier)); - - // 2. Assert: the previous step never throws an exception, because resolving a module specifier must have been previously successful with these same two arguments. - // NOTE: Handled by MUST above. - - // 3. Let moduleType be the result of running the module type from module request steps given moduleRequest. - auto module_type = module_type_from_module_request(module_request); - - // 4. Assert: visited set contains (url, moduleType). - VERIFY(visited_set.contains({ url, module_type })); - - // onSingleFetchComplete given result is the following algorithm: - auto on_single_fetch_complete = create_on_fetch_script_complete(realm.heap(), [&realm, perform_fetch, on_complete, &fetch_client_settings_object, destination, visited_set](auto result) mutable { - // 1. If result is null, run onComplete with null, and abort these steps. - if (!result) { - on_complete->function()(nullptr); - return; - } - - // 2. Fetch the descendants of result given fetch client settings object, destination, visited set, and with onComplete. If performFetch was given, pass it along as well. - auto& module_script = as(*result); - fetch_descendants_of_a_module_script(realm, module_script, fetch_client_settings_object, destination, visited_set, perform_fetch, on_complete); - }); - - // 5. Fetch a single module script given url, fetch client settings object, destination, options, referringScript's settings object's realm, - // referringScript's base URL, moduleRequest, false, and onSingleFetchComplete as defined below. If performFetch was given, pass it along as well. - fetch_single_module_script(realm, url, fetch_client_settings_object, destination, options, referring_script.realm(), referring_script.base_url().value(), module_request, TopLevelModule::No, perform_fetch, on_single_fetch_complete); -} - -// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-a-module-script -void fetch_descendants_of_a_module_script(JS::Realm& realm, JavaScriptModuleScript& module_script, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination destination, HashTable visited_set, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete) -{ - // 1. If module script's record is null, run onComplete with module script and return. - if (!module_script.record()) { - on_complete->function()(&module_script); - return; - } - - // 2. Let record be module script's record. - auto const& record = module_script.record(); - - // 3. If record is not a Cyclic Module Record, or if record.[[RequestedModules]] is empty, run onComplete with module script and return. - // FIXME: Currently record is always a cyclic module. - if (record->requested_modules().is_empty()) { - on_complete->function()(&module_script); - return; - } - - // 4. Let moduleRequests be a new empty list. - Vector module_requests; - - // 5. For each ModuleRequest Record requested of record.[[RequestedModules]], - for (auto const& requested : record->requested_modules()) { - // 1. Let url be the result of resolving a module specifier given module script and requested.[[Specifier]]. - auto url = MUST(resolve_module_specifier(module_script, requested.module_specifier)); - - // 2. Assert: the previous step never throws an exception, because resolving a module specifier must have been previously successful with these same two arguments. - // NOTE: Handled by MUST above. - - // 3. Let moduleType be the result of running the module type from module request steps given requested. - auto module_type = module_type_from_module_request(requested); - - // 4. If visited set does not contain (url, moduleType), then: - if (!visited_set.contains({ url, module_type })) { - // 1. Append requested to moduleRequests. - module_requests.append(requested); - - // 2. Append (url, moduleType) to visited set. - visited_set.set({ url, module_type }); - } - } - - // FIXME: 6. Let options be the descendant script fetch options for module script's fetch options. - ScriptFetchOptions options; - - // FIXME: 7. Assert: options is not null, as module script is a JavaScript module script. - - // 8. Let pendingCount be the length of moduleRequests. - auto pending_count = module_requests.size(); - - // 9. If pendingCount is zero, run onComplete with module script. - if (pending_count == 0) { - on_complete->function()(&module_script); - return; - } - - // 10. Let failed be false. - bool failed = false; - - // 11. For each moduleRequest in moduleRequests, perform the internal module script graph fetching procedure given moduleRequest, - // fetch client settings object, destination, options, module script, visited set, and onInternalFetchingComplete as defined below. - // If performFetch was given, pass it along as well. - for (auto const& module_request : module_requests) { - // onInternalFetchingComplete given result is the following algorithm: - auto on_internal_fetching_complete = create_on_fetch_script_complete(realm.heap(), [failed, pending_count, &module_script, on_complete](auto result) mutable { - // 1. If failed is true, then abort these steps. - if (failed) - return; - - // 2. If result is null, then set failed to true, run onComplete with null, and abort these steps. - if (!result) { - failed = true; - on_complete->function()(nullptr); - return; - } - - // 3. Assert: pendingCount is greater than zero. - VERIFY(pending_count > 0); - - // 4. Decrement pendingCount by one. - --pending_count; - - // 5. If pendingCount is zero, run onComplete with module script. - if (pending_count == 0) - on_complete->function()(&module_script); - }); - - fetch_internal_module_script_graph(realm, module_request, fetch_client_settings_object, destination, options, module_script, visited_set, perform_fetch, on_internal_fetching_complete); - } -} - // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-destination-from-module-type Fetch::Infrastructure::Request::Destination fetch_destination_from_module_type(Fetch::Infrastructure::Request::Destination default_destination, ByteString const& module_type) { diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.h b/Libraries/LibWeb/HTML/Scripting/Fetching.h index d972ff3534d..6968d0e6efd 100644 --- a/Libraries/LibWeb/HTML/Scripting/Fetching.h +++ b/Libraries/LibWeb/HTML/Scripting/Fetching.h @@ -93,12 +93,10 @@ WebIDL::ExceptionOr fetch_classic_worker_script(URL::URL const&, Environme WebIDL::ExceptionOr> fetch_a_classic_worker_imported_script(URL::URL const&, HTML::EnvironmentSettingsObject&, PerformTheFetchHook = nullptr); WebIDL::ExceptionOr fetch_module_worker_script_graph(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete); WebIDL::ExceptionOr fetch_worklet_module_worker_script_graph(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete); -void fetch_internal_module_script_graph(JS::Realm&, JS::ModuleRequest const& module_request, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, Script& referring_script, HashTable const& visited_set, PerformTheFetchHook, OnFetchScriptComplete on_complete); void fetch_external_module_script_graph(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete); void fetch_inline_module_script_graph(JS::Realm&, ByteString const& filename, ByteString const& source_text, URL::URL const& base_url, EnvironmentSettingsObject& settings_object, OnFetchScriptComplete on_complete); void fetch_single_imported_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, JS::Realm& module_map_realm, Fetch::Infrastructure::Request::ReferrerType, JS::ModuleRequest const&, PerformTheFetchHook, OnFetchScriptComplete on_complete); -void fetch_descendants_of_a_module_script(JS::Realm&, JavaScriptModuleScript& module_script, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination, HashTable visited_set, PerformTheFetchHook, OnFetchScriptComplete callback); void fetch_descendants_of_and_link_a_module_script(JS::Realm&, JavaScriptModuleScript&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::Destination, PerformTheFetchHook, OnFetchScriptComplete on_complete); Fetch::Infrastructure::Request::Destination fetch_destination_from_module_type(Fetch::Infrastructure::Request::Destination, ByteString const&);