소스 검색

LibWeb/Fetch: Implement "fetch destination from module type" AO

See:
- https://github.com/whatwg/html/commit/37659e9
Jamie Mansfield 1 년 전
부모
커밋
e2f242a552
2개의 변경된 파일17개의 추가작업 그리고 0개의 파일을 삭제
  1. 15 0
      Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
  2. 2 0
      Userland/Libraries/LibWeb/HTML/Scripting/Fetching.h

+ 15 - 0
Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp

@@ -593,6 +593,21 @@ void fetch_descendants_of_a_module_script(JS::Realm& realm, JavaScriptModuleScri
     }
 }
 
+// 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)
+{
+    // 1. If moduleType is "json", then return "json".
+    if (module_type == "json"sv)
+        return Fetch::Infrastructure::Request::Destination::JSON;
+
+    // 2. If moduleType is "css", then return "style".
+    if (module_type == "css"sv)
+        return Fetch::Infrastructure::Request::Destination::Style;
+
+    // 3. Return defaultDestination.
+    return default_destination;
+}
+
 // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
 void fetch_single_module_script(JS::Realm& realm,
     URL::URL const& url,

+ 2 - 0
Userland/Libraries/LibWeb/HTML/Scripting/Fetching.h

@@ -99,5 +99,7 @@ void fetch_single_imported_module_script(JS::Realm&, URL::URL const&, Environmen
 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);
 
+Fetch::Infrastructure::Request::Destination fetch_destination_from_module_type(Fetch::Infrastructure::Request::Destination, ByteString const&);
+
 void fetch_single_module_script(JS::Realm&, URL::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);
 }