mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:42:45 +00:00 
			
		
		
		
	LibWeb: Implement and use the fetch a module worker script graph AO
This involves plumbing the perform the fetch hook argument throughout all of the module fetch implementation AOs, where it was left as a FIXME before. With this change we can load module scripts in DedicatedWorkers.
This commit is contained in:
		
							parent
							
								
									b5acc5f2df
								
							
						
					
					
						commit
						f67bc591a0
					
				
					 4 changed files with 105 additions and 48 deletions
				
			
		|  | @ -465,6 +465,7 @@ ErrorOr<void> initialize_main_thread_vm() | |||
|         JS::NonnullGCPtr fetch_client { *settings_object }; | ||||
| 
 | ||||
|         // 12. If loadState is not undefined, then:
 | ||||
|         HTML::PerformTheFetchHook perform_fetch; | ||||
|         if (load_state) { | ||||
|             auto& fetch_context = static_cast<HTML::FetchContext&>(*load_state); | ||||
| 
 | ||||
|  | @ -473,6 +474,9 @@ ErrorOr<void> initialize_main_thread_vm() | |||
| 
 | ||||
|             // 2. Set fetchClient loadState.[[FetchClient]].
 | ||||
|             fetch_client = fetch_context.fetch_client; | ||||
| 
 | ||||
|             // For step 13
 | ||||
|             perform_fetch = fetch_context.perform_fetch; | ||||
|         } | ||||
| 
 | ||||
|         auto on_single_fetch_complete = HTML::create_on_fetch_script_complete(realm.heap(), [referrer, &realm, load_state, module_request, payload](JS::GCPtr<HTML::Script> const& module_script) -> void { | ||||
|  | @ -530,8 +534,8 @@ ErrorOr<void> initialize_main_thread_vm() | |||
| 
 | ||||
|         // 13. Fetch a single imported module script given url, fetchClient, destination, fetchOptions, settingsObject, fetchReferrer,
 | ||||
|         //     moduleRequest, and onSingleFetchComplete as defined below.
 | ||||
|         //     If loadState is not undefined and loadState.[[PerformFetch]] is not null, pass loadState.[[PerformFetch]] along as well.#
 | ||||
|         HTML::fetch_single_imported_module_script(realm, url.release_value(), *fetch_client, destination, fetch_options, *settings_object, fetch_referrer, module_request, on_single_fetch_complete); | ||||
|         //     If loadState is not undefined and loadState.[[PerformFetch]] is not null, pass loadState.[[PerformFetch]] along as well.
 | ||||
|         HTML::fetch_single_imported_module_script(realm, url.release_value(), *fetch_client, destination, fetch_options, *settings_object, fetch_referrer, module_request, perform_fetch, on_single_fetch_complete); | ||||
|     }; | ||||
| 
 | ||||
|     return {}; | ||||
|  |  | |||
|  | @ -33,7 +33,7 @@ OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<v | |||
|     return JS::create_heap_function(heap, move(function)); | ||||
| } | ||||
| 
 | ||||
| PerformTheFetchHook create_perform_the_fetch_hook(JS::Heap& heap, Function<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, IsTopLevel, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function) | ||||
| PerformTheFetchHook create_perform_the_fetch_hook(JS::Heap& heap, Function<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function) | ||||
| { | ||||
|     return JS::create_heap_function(heap, move(function)); | ||||
| } | ||||
|  | @ -409,7 +409,7 @@ WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL const& url, Environmen | |||
| 
 | ||||
|     // 2. If performFetch was given, run performFetch with request, true, and with processResponseConsumeBody as defined below.
 | ||||
|     if (perform_fetch != nullptr) { | ||||
|         TRY(perform_fetch->function()(request, IsTopLevel::Yes, move(process_response_consume_body))); | ||||
|         TRY(perform_fetch->function()(request, TopLevelModule::Yes, move(process_response_consume_body))); | ||||
|     } | ||||
| 
 | ||||
|     // Otherwise, fetch request with processResponseConsumeBody set to processResponseConsumeBody as defined below.
 | ||||
|  | @ -421,8 +421,53 @@ WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL const& url, Environmen | |||
|     return {}; | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
 | ||||
| WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL const& url, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete) | ||||
| { | ||||
|     return fetch_worklet_module_worker_script_graph(url, fetch_client, destination, settings_object, move(perform_fetch), move(on_complete)); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph
 | ||||
| WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL const& url, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete) | ||||
| { | ||||
|     auto& realm = settings_object.realm(); | ||||
|     auto& vm = realm.vm(); | ||||
| 
 | ||||
|     // 1. Let options be a script fetch options whose cryptographic nonce is the empty string,
 | ||||
|     //    integrity metadata is the empty string, parser metadata is "not-parser-inserted",
 | ||||
|     //    credentials mode is credentialsMode, referrer policy is the empty string, and fetch priority is "auto".
 | ||||
|     // FIXME: credentialsMode
 | ||||
|     auto options = ScriptFetchOptions { | ||||
|         .cryptographic_nonce = String {}, | ||||
|         .integrity_metadata = String {}, | ||||
|         .parser_metadata = Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted, | ||||
|         .credentials_mode = Fetch::Infrastructure::Request::CredentialsMode::SameOrigin, | ||||
|         .referrer_policy = ReferrerPolicy::ReferrerPolicy::EmptyString, | ||||
|         .fetch_priority = Fetch::Infrastructure::Request::Priority::Auto | ||||
|     }; | ||||
| 
 | ||||
|     // onSingleFetchComplete given result is the following algorithm:
 | ||||
|     auto on_single_fetch_complete = create_on_fetch_script_complete(vm.heap(), [&realm, &fetch_client, destination, perform_fetch = perform_fetch, on_complete = move(on_complete)](auto result) mutable { | ||||
|         // 1. If result is null, run onComplete with null, and abort these steps.
 | ||||
|         if (!result) { | ||||
|             dbgln("on single fetch complete with nool"); | ||||
|             on_complete->function()(nullptr); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // 2. Fetch the descendants of and link result given fetchClient, destination, and onComplete. If performFetch was given, pass it along as well.
 | ||||
|         fetch_descendants_of_and_link_a_module_script(realm, verify_cast<JavaScriptModuleScript>(*result), fetch_client, destination, move(perform_fetch), on_complete); | ||||
|     }); | ||||
| 
 | ||||
|     // 2. Fetch a single module script given url, fetchClient, destination, options, settingsObject, "client", true,
 | ||||
|     //    and onSingleFetchComplete as defined below. If performFetch was given, pass it along as well.
 | ||||
|     fetch_single_module_script(realm, url, fetch_client, destination, options, settings_object, Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, move(perform_fetch), on_single_fetch_complete); | ||||
| 
 | ||||
|     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<ModuleLocationTuple> const& visited_set, OnFetchScriptComplete on_complete) | ||||
| 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<ModuleLocationTuple> 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)); | ||||
|  | @ -437,7 +482,7 @@ void fetch_internal_module_script_graph(JS::Realm& realm, JS::ModuleRequest cons | |||
|     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, on_complete, &fetch_client_settings_object, destination, visited_set](auto result) mutable { | ||||
|     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); | ||||
|  | @ -445,19 +490,17 @@ void fetch_internal_module_script_graph(JS::Realm& realm, JS::ModuleRequest cons | |||
|         } | ||||
| 
 | ||||
|         // 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.
 | ||||
|         // FIXME: Pass performFetch if given.
 | ||||
|         auto& module_script = verify_cast<JavaScriptModuleScript>(*result); | ||||
|         fetch_descendants_of_a_module_script(realm, module_script, fetch_client_settings_object, destination, visited_set, on_complete); | ||||
|         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,
 | ||||
|     //    referringScript's base URL, moduleRequest, false, and onSingleFetchComplete as defined below. If performFetch was given, pass it along as well.
 | ||||
|     // FIXME: Pass performFetch if given.
 | ||||
|     fetch_single_module_script(realm, url, fetch_client_settings_object, destination, options, referring_script.settings_object(), referring_script.base_url(), module_request, TopLevelModule::No, on_single_fetch_complete); | ||||
|     fetch_single_module_script(realm, url, fetch_client_settings_object, destination, options, referring_script.settings_object(), referring_script.base_url(), 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<ModuleLocationTuple> visited_set, OnFetchScriptComplete on_complete) | ||||
| void fetch_descendants_of_a_module_script(JS::Realm& realm, JavaScriptModuleScript& module_script, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination destination, HashTable<ModuleLocationTuple> 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()) { | ||||
|  | @ -544,8 +587,7 @@ void fetch_descendants_of_a_module_script(JS::Realm& realm, JavaScriptModuleScri | |||
|                 on_complete->function()(&module_script); | ||||
|         }); | ||||
| 
 | ||||
|         // FIXME: Pass performFetch if given.
 | ||||
|         fetch_internal_module_script_graph(realm, module_request, fetch_client_settings_object, destination, options, module_script, visited_set, on_internal_fetching_complete); | ||||
|         fetch_internal_module_script_graph(realm, module_request, fetch_client_settings_object, destination, options, module_script, visited_set, perform_fetch, on_internal_fetching_complete); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -559,6 +601,7 @@ void fetch_single_module_script(JS::Realm& realm, | |||
|     Web::Fetch::Infrastructure::Request::ReferrerType const& referrer, | ||||
|     Optional<JS::ModuleRequest> const& module_request, | ||||
|     TopLevelModule is_top_level, | ||||
|     PerformTheFetchHook perform_fetch, | ||||
|     OnFetchScriptComplete on_complete) | ||||
| { | ||||
|     // 1. Let moduleType be "javascript".
 | ||||
|  | @ -622,9 +665,7 @@ void fetch_single_module_script(JS::Realm& realm, | |||
|     // 12. If performFetch was given, run performFetch with request, isTopLevel, and with processResponseConsumeBody as defined below.
 | ||||
|     //     Otherwise, fetch request with processResponseConsumeBody set to processResponseConsumeBody as defined below.
 | ||||
|     //     In both cases, let processResponseConsumeBody given response response and null, failure, or a byte sequence bodyBytes be the following algorithm:
 | ||||
|     // FIXME: Run performFetch if given.
 | ||||
|     Web::Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {}; | ||||
|     fetch_algorithms_input.process_response_consume_body = [&module_map, url, module_type, &settings_object, on_complete](JS::NonnullGCPtr<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) { | ||||
|     auto process_response_consume_body = [&module_map, url, module_type, &settings_object, on_complete](JS::NonnullGCPtr<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) { | ||||
|         // 1. If either of the following conditions are met:
 | ||||
|         //    - bodyBytes is null or failure; or
 | ||||
|         //    - response's status is not an ok status,
 | ||||
|  | @ -662,8 +703,14 @@ void fetch_single_module_script(JS::Realm& realm, | |||
|         on_complete->function()(module_script); | ||||
|     }; | ||||
| 
 | ||||
|     if (perform_fetch != nullptr) { | ||||
|         perform_fetch->function()(request, is_top_level, move(process_response_consume_body)).release_value_but_fixme_should_propagate_errors(); | ||||
|     } else { | ||||
|         Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {}; | ||||
|         fetch_algorithms_input.process_response_consume_body = move(process_response_consume_body); | ||||
|         Fetch::Fetching::fetch(realm, request, Fetch::Infrastructure::FetchAlgorithms::create(realm.vm(), move(fetch_algorithms_input))).release_value_but_fixme_should_propagate_errors(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
 | ||||
| void fetch_external_module_script_graph(JS::Realm& realm, URL const& url, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const& options, OnFetchScriptComplete on_complete) | ||||
|  | @ -680,11 +727,11 @@ void fetch_external_module_script_graph(JS::Realm& realm, URL const& url, Enviro | |||
| 
 | ||||
|         // 2. Fetch the descendants of and link result given settingsObject, "script", and onComplete.
 | ||||
|         auto& module_script = verify_cast<JavaScriptModuleScript>(*result); | ||||
|         fetch_descendants_of_and_link_a_module_script(realm, module_script, settings_object, Fetch::Infrastructure::Request::Destination::Script, on_complete); | ||||
|         fetch_descendants_of_and_link_a_module_script(realm, module_script, settings_object, Fetch::Infrastructure::Request::Destination::Script, nullptr, on_complete); | ||||
|     }); | ||||
| 
 | ||||
|     // 2. Fetch a single module script given url, settingsObject, "script", options, settingsObject, "client", true, and with the following steps given result:
 | ||||
|     fetch_single_module_script(realm, url, settings_object, Fetch::Infrastructure::Request::Destination::Script, options, settings_object, Web::Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, steps); | ||||
|     fetch_single_module_script(realm, url, settings_object, Fetch::Infrastructure::Request::Destination::Script, options, settings_object, Web::Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, nullptr, steps); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-an-inline-module-script-graph
 | ||||
|  | @ -703,7 +750,7 @@ void fetch_inline_module_script_graph(JS::Realm& realm, ByteString const& filena | |||
|     } | ||||
| 
 | ||||
|     // 5. Fetch the descendants of and link script, given settingsObject, "script", and onComplete.
 | ||||
|     fetch_descendants_of_and_link_a_module_script(realm, *script, settings_object, Fetch::Infrastructure::Request::Destination::Script, on_complete); | ||||
|     fetch_descendants_of_and_link_a_module_script(realm, *script, settings_object, Fetch::Infrastructure::Request::Destination::Script, nullptr, on_complete); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-imported-module-script
 | ||||
|  | @ -715,6 +762,7 @@ void fetch_single_imported_module_script(JS::Realm& realm, | |||
|     EnvironmentSettingsObject& settings_object, | ||||
|     Fetch::Infrastructure::Request::Referrer referrer, | ||||
|     JS::ModuleRequest const& module_request, | ||||
|     PerformTheFetchHook perform_fetch, | ||||
|     OnFetchScriptComplete on_complete) | ||||
| { | ||||
|     // 1. Assert: moduleRequest.[[Attributes]] does not contain any Record entry such that entry.[[Key]] is not "type",
 | ||||
|  | @ -734,7 +782,7 @@ void fetch_single_imported_module_script(JS::Realm& realm, | |||
| 
 | ||||
|     // 4. Fetch a single module script given url, fetchClient, destination, options, settingsObject, referrer, moduleRequest, false,
 | ||||
|     //    and onComplete. If performFetch was given, pass it along as well.
 | ||||
|     fetch_single_module_script(realm, url, fetch_client, destination, options, settings_object, referrer, module_request, TopLevelModule::No, on_complete); | ||||
|     fetch_single_module_script(realm, url, fetch_client, destination, options, settings_object, referrer, module_request, TopLevelModule::No, perform_fetch, on_complete); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-and-link-a-module-script
 | ||||
|  | @ -742,6 +790,7 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm, | |||
|     JavaScriptModuleScript& module_script, | ||||
|     EnvironmentSettingsObject& fetch_client, | ||||
|     Fetch::Infrastructure::Request::Destination destination, | ||||
|     PerformTheFetchHook perform_fetch, | ||||
|     OnFetchScriptComplete on_complete) | ||||
| { | ||||
|     // 1. Let record be moduleScript's record.
 | ||||
|  | @ -762,7 +811,8 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm, | |||
|     // 3. Let state be Record { [[ParseError]]: null, [[Destination]]: destination, [[PerformFetch]]: null, [[FetchClient]]: fetchClient }.
 | ||||
|     auto state = realm.heap().allocate_without_realm<FetchContext>(JS::js_null(), destination, nullptr, fetch_client); | ||||
| 
 | ||||
|     // FIXME: 4. If performFetch was given, set state.[[PerformFetch]] to performFetch.
 | ||||
|     // 4. If performFetch was given, set state.[[PerformFetch]] to performFetch.
 | ||||
|     state->perform_fetch = perform_fetch; | ||||
| 
 | ||||
|     // FIXME: These should most likely be steps in the spec.
 | ||||
|     // NOTE: For reasons beyond my understanding, we cannot use TemporaryExecutionContext here.
 | ||||
|  |  | |||
|  | @ -16,16 +16,16 @@ | |||
| 
 | ||||
| namespace Web::HTML { | ||||
| 
 | ||||
| enum class IsTopLevel { | ||||
|     No, | ||||
| enum class TopLevelModule { | ||||
|     Yes, | ||||
|     No | ||||
| }; | ||||
| 
 | ||||
| using OnFetchScriptComplete = JS::NonnullGCPtr<JS::HeapFunction<void(JS::GCPtr<Script>)>>; | ||||
| using PerformTheFetchHook = JS::GCPtr<JS::HeapFunction<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, IsTopLevel, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)>>; | ||||
| using PerformTheFetchHook = JS::GCPtr<JS::HeapFunction<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)>>; | ||||
| 
 | ||||
| OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<void(JS::GCPtr<Script>)> function); | ||||
| PerformTheFetchHook create_perform_the_fetch_hook(JS::Heap& heap, Function<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, IsTopLevel, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function); | ||||
| PerformTheFetchHook create_perform_the_fetch_hook(JS::Heap& heap, Function<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function); | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#script-fetch-options
 | ||||
| struct ScriptFetchOptions { | ||||
|  | @ -60,11 +60,11 @@ class FetchContext : public JS::GraphLoadingState::HostDefined { | |||
| public: | ||||
|     JS::Value parse_error;                                    // [[ParseError]]
 | ||||
|     Fetch::Infrastructure::Request::Destination destination;  // [[Destination]]
 | ||||
|     JS::GCPtr<JS::Promise> perform_fetch;                     // [[PerformFetch]]
 | ||||
|     PerformTheFetchHook perform_fetch;                        // [[PerformFetch]]
 | ||||
|     JS::NonnullGCPtr<EnvironmentSettingsObject> fetch_client; // [[FetchClient]]
 | ||||
| 
 | ||||
| private: | ||||
|     FetchContext(JS::Value parse_error, Fetch::Infrastructure::Request::Destination destination, JS::GCPtr<JS::Promise> perform_fetch, EnvironmentSettingsObject& fetch_client) | ||||
|     FetchContext(JS::Value parse_error, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, EnvironmentSettingsObject& fetch_client) | ||||
|         : parse_error(parse_error) | ||||
|         , destination(destination) | ||||
|         , perform_fetch(perform_fetch) | ||||
|  | @ -88,19 +88,16 @@ Optional<URL> resolve_url_like_module_specifier(ByteString const& specifier, URL | |||
| 
 | ||||
| WebIDL::ExceptionOr<void> fetch_classic_script(JS::NonnullGCPtr<HTMLScriptElement>, URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, String character_encoding, OnFetchScriptComplete on_complete); | ||||
| WebIDL::ExceptionOr<void> fetch_classic_worker_script(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<ModuleLocationTuple> const& visited_set, OnFetchScriptComplete on_complete); | ||||
| WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete); | ||||
| WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(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<ModuleLocationTuple> const& visited_set, PerformTheFetchHook, OnFetchScriptComplete on_complete); | ||||
| void fetch_external_module_script_graph(JS::Realm&, 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 const& base_url, EnvironmentSettingsObject& settings_object, OnFetchScriptComplete on_complete); | ||||
| void fetch_single_imported_module_script(JS::Realm&, URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Fetch::Infrastructure::Request::Referrer, JS::ModuleRequest const&, OnFetchScriptComplete on_complete); | ||||
| void fetch_single_imported_module_script(JS::Realm&, URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Fetch::Infrastructure::Request::Referrer, 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<ModuleLocationTuple> visited_set, OnFetchScriptComplete callback); | ||||
| void fetch_descendants_of_and_link_a_module_script(JS::Realm&, JavaScriptModuleScript&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::Destination, 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<ModuleLocationTuple> 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); | ||||
| 
 | ||||
| enum class TopLevelModule { | ||||
|     Yes, | ||||
|     No | ||||
| }; | ||||
| 
 | ||||
| void fetch_single_module_script(JS::Realm&, URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Web::Fetch::Infrastructure::Request::ReferrerType const&, Optional<JS::ModuleRequest> const&, TopLevelModule, OnFetchScriptComplete callback); | ||||
| void fetch_single_module_script(JS::Realm&, URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject& settings_object, Web::Fetch::Infrastructure::Request::ReferrerType const&, Optional<JS::ModuleRequest> const&, TopLevelModule, PerformTheFetchHook, OnFetchScriptComplete callback); | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -82,14 +82,14 @@ void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::Trans | |||
|                                  : Web::Fetch::Infrastructure::Request::Destination::Worker; | ||||
| 
 | ||||
|     // In both cases, let performFetch be the following perform the fetch hook given request, isTopLevel and processCustomFetchResponse:
 | ||||
|     auto perform_fetch_function = [inner_settings, worker_global_scope](JS::NonnullGCPtr<Web::Fetch::Infrastructure::Request> request, Web::HTML::IsTopLevel is_top_level, Web::Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_custom_fetch_response) -> Web::WebIDL::ExceptionOr<void> { | ||||
|     auto perform_fetch_function = [inner_settings, worker_global_scope](JS::NonnullGCPtr<Web::Fetch::Infrastructure::Request> request, Web::HTML::TopLevelModule is_top_level, Web::Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_custom_fetch_response) -> Web::WebIDL::ExceptionOr<void> { | ||||
|         auto& realm = inner_settings->realm(); | ||||
|         auto& vm = realm.vm(); | ||||
| 
 | ||||
|         Web::Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {}; | ||||
| 
 | ||||
|         // 1. If isTopLevel is false, fetch request with processResponseConsumeBody set to processCustomFetchResponse, and abort these steps.
 | ||||
|         if (is_top_level == Web::HTML::IsTopLevel::No) { | ||||
|         if (is_top_level == Web::HTML::TopLevelModule::No) { | ||||
|             fetch_algorithms_input.process_response_consume_body = move(process_custom_fetch_response); | ||||
|             TRY(Web::Fetch::Fetching::fetch(realm, request, Web::Fetch::Infrastructure::FetchAlgorithms::create(vm, move(fetch_algorithms_input)))); | ||||
|             return {}; | ||||
|  | @ -210,15 +210,21 @@ void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::Trans | |||
|     //               and with onComplete and performFetch as defined below.
 | ||||
|     // module:   Fetch a module worker script graph given url, outside settings, destination, the value of the credentials member of options, inside settings,
 | ||||
|     //               and with onComplete and performFetch as defined below.
 | ||||
|     if (m_type != "classic"sv) { | ||||
|         dbgln("Unsupported script type {} for LibWeb/Worker", m_type); | ||||
|         TODO(); | ||||
|     } | ||||
|     if (m_type == "classic"sv) { | ||||
|         if (auto err = Web::HTML::fetch_classic_worker_script(m_url, outside_settings, destination, inner_settings, perform_fetch, on_complete); err.is_error()) { | ||||
|             dbgln("Failed to run worker script"); | ||||
|             // FIXME: Abort the worker properly
 | ||||
|             TODO(); | ||||
|         } | ||||
|     } else { | ||||
|         VERIFY(m_type == "module"sv); | ||||
|         // FIXME: Pass credentials
 | ||||
|         if (auto err = Web::HTML::fetch_module_worker_script_graph(m_url, outside_settings, destination, inner_settings, perform_fetch, on_complete); err.is_error()) { | ||||
|             dbgln("Failed to run worker script"); | ||||
|             // FIXME: Abort the worker properly
 | ||||
|             TODO(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Kaster
						Andrew Kaster