Fetching.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*
  2. * Copyright (c) 2022, networkException <networkexception@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/URLParser.h>
  7. #include <LibWeb/HTML/Scripting/Environments.h>
  8. #include <LibWeb/HTML/Scripting/Fetching.h>
  9. #include <LibWeb/HTML/Scripting/ModuleScript.h>
  10. #include <LibWeb/HTML/Window.h>
  11. #include <LibWeb/Infra/Strings.h>
  12. #include <LibWeb/Loader/LoadRequest.h>
  13. #include <LibWeb/Loader/ResourceLoader.h>
  14. #include <LibWeb/MimeSniff/MimeType.h>
  15. namespace Web::HTML {
  16. // https://html.spec.whatwg.org/multipage/webappapis.html#module-type-from-module-request
  17. String module_type_from_module_request(JS::ModuleRequest const& module_request)
  18. {
  19. // 1. Let moduleType be "javascript".
  20. String module_type = "javascript"sv;
  21. // 2. If moduleRequest.[[Assertions]] has a Record entry such that entry.[[Key]] is "type", then:
  22. for (auto const& entry : module_request.assertions) {
  23. if (entry.key != "type"sv)
  24. continue;
  25. // 1. If entry.[[Value]] is "javascript", then set moduleType to null.
  26. if (entry.value == "javascript"sv)
  27. module_type = nullptr;
  28. // 2. Otherwise, set moduleType to entry.[[Value]].
  29. else
  30. module_type = entry.value;
  31. }
  32. // 3. Return moduleType.
  33. return module_type;
  34. }
  35. // https://html.spec.whatwg.org/multipage/webappapis.html#resolve-a-module-specifier
  36. WebIDL::ExceptionOr<AK::URL> resolve_module_specifier(Optional<Script&> referring_script, String const& specifier)
  37. {
  38. // 1. Let settingsObject and baseURL be null.
  39. Optional<EnvironmentSettingsObject&> settings_object;
  40. Optional<AK::URL const&> base_url;
  41. // 2. If referringScript is not null, then:
  42. if (referring_script.has_value()) {
  43. // 1. Set settingsObject to referringScript's settings object.
  44. settings_object = referring_script->settings_object();
  45. // 2. Set baseURL to referringScript's base URL.
  46. base_url = referring_script->base_url();
  47. }
  48. // 3. Otherwise:
  49. else {
  50. // 1. Assert: there is a current settings object.
  51. // NOTE: This is handled by the current_settings_object() accessor.
  52. // 2. Set settingsObject to the current settings object.
  53. settings_object = current_settings_object();
  54. // 3. Set baseURL to settingsObject's API base URL.
  55. base_url = settings_object->api_base_url();
  56. }
  57. // 4. Let importMap be an empty import map.
  58. ImportMap import_map;
  59. // 5. If settingsObject's global object implements Window, then set importMap to settingsObject's global object's import map.
  60. if (is<Window>(settings_object->global_object()))
  61. import_map = verify_cast<Window>(settings_object->global_object()).import_map();
  62. // 6. Let baseURLString be baseURL, serialized.
  63. auto base_url_string = base_url->serialize();
  64. // 7. Let asURL be the result of resolving a URL-like module specifier given specifier and baseURL.
  65. auto as_url = resolve_url_like_module_specifier(specifier, *base_url);
  66. // 8. Let normalizedSpecifier be the serialization of asURL, if asURL is non-null; otherwise, specifier.
  67. auto normalized_specifier = as_url.has_value() ? as_url->serialize() : specifier;
  68. // 9. For each scopePrefix → scopeImports of importMap's scopes:
  69. for (auto const& entry : import_map.scopes()) {
  70. // FIXME: Clarify if the serialization steps need to be run here. The steps below assume
  71. // scopePrefix to be a string.
  72. auto const& scope_prefix = entry.key.serialize();
  73. auto const& scope_imports = entry.value;
  74. // 1. If scopePrefix is baseURLString, or if scopePrefix ends with U+002F (/) and scopePrefix is a code unit prefix of baseURLString, then:
  75. if (scope_prefix == base_url_string || (scope_prefix.ends_with("/"sv) && Infra::is_code_unit_prefix(scope_prefix, base_url_string))) {
  76. // 1. Let scopeImportsMatch be the result of resolving an imports match given normalizedSpecifier, asURL, and scopeImports.
  77. auto scope_imports_match = TRY(resolve_imports_match(normalized_specifier, as_url, scope_imports));
  78. // 2. If scopeImportsMatch is not null, then return scopeImportsMatch.
  79. if (scope_imports_match.has_value())
  80. return scope_imports_match.release_value();
  81. }
  82. }
  83. // 10. Let topLevelImportsMatch be the result of resolving an imports match given normalizedSpecifier, asURL, and importMap's imports.
  84. auto top_level_imports_match = TRY(resolve_imports_match(normalized_specifier, as_url, import_map.imports()));
  85. // 11. If topLevelImportsMatch is not null, then return topLevelImportsMatch.
  86. if (top_level_imports_match.has_value())
  87. return top_level_imports_match.release_value();
  88. // 12. If asURL is not null, then return asURL.
  89. if (as_url.has_value())
  90. return as_url.release_value();
  91. // 13. Throw a TypeError indicating that specifier was a bare specifier, but was not remapped to anything by importMap.
  92. return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Failed to resolve non relative module specifier '{}' from an import map.", specifier) };
  93. }
  94. // https://html.spec.whatwg.org/multipage/webappapis.html#resolving-an-imports-match
  95. WebIDL::ExceptionOr<Optional<AK::URL>> resolve_imports_match(String const& normalized_specifier, Optional<AK::URL> as_url, ModuleSpecifierMap const& specifier_map)
  96. {
  97. // 1. For each specifierKey → resolutionResult of specifierMap:
  98. for (auto const& [specifier_key, resolution_result] : specifier_map) {
  99. // 1. If specifierKey is normalizedSpecifier, then:
  100. if (specifier_key == normalized_specifier) {
  101. // 1. If resolutionResult is null, then throw a TypeError indicating that resolution of specifierKey was blocked by a null entry.
  102. if (!resolution_result.has_value())
  103. return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Import resolution of '{}' was blocked by a null entry.", specifier_key) };
  104. // 2. Assert: resolutionResult is a URL.
  105. VERIFY(resolution_result->is_valid());
  106. // 3. Return resolutionResult.
  107. return resolution_result;
  108. }
  109. // 2. If all of the following are true:
  110. if (
  111. // - specifierKey ends with U+002F (/);
  112. specifier_key.ends_with("/"sv) &&
  113. // - specifierKey is a code unit prefix of normalizedSpecifier; and
  114. Infra::is_code_unit_prefix(specifier_key, normalized_specifier) &&
  115. // - either asURL is null, or asURL is special,
  116. (!as_url.has_value() || as_url->is_special())
  117. // then:
  118. ) {
  119. // 1. If resolutionResult is null, then throw a TypeError indicating that the resolution of specifierKey was blocked by a null entry.
  120. if (!resolution_result.has_value())
  121. return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Import resolution of '{}' was blocked by a null entry.", specifier_key) };
  122. // 2. Assert: resolutionResult is a URL.
  123. VERIFY(resolution_result->is_valid());
  124. // 3. Let afterPrefix be the portion of normalizedSpecifier after the initial specifierKey prefix.
  125. // FIXME: Clarify if this is meant by the portion after the initial specifierKey prefix.
  126. auto after_prefix = normalized_specifier.substring(specifier_key.length());
  127. // 4. Assert: resolutionResult, serialized, ends with U+002F (/), as enforced during parsing.
  128. VERIFY(resolution_result->serialize().ends_with("/"sv));
  129. // 5. Let url be the result of URL parsing afterPrefix with resolutionResult.
  130. auto url = URLParser::parse(after_prefix, &*resolution_result);
  131. // 6. If url is failure, then throw a TypeError indicating that resolution of normalizedSpecifier was blocked since the afterPrefix portion
  132. // could not be URL-parsed relative to the resolutionResult mapped to by the specifierKey prefix.
  133. if (!url.is_valid())
  134. return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Could not resolve '{}' as the after prefix portion could not be URL-parsed.", normalized_specifier) };
  135. // 7. Assert: url is a URL.
  136. VERIFY(url.is_valid());
  137. // 8. If the serialization of resolutionResult is not a code unit prefix of the serialization of url, then throw a TypeError indicating
  138. // that the resolution of normalizedSpecifier was blocked due to it backtracking above its prefix specifierKey.
  139. if (!Infra::is_code_unit_prefix(resolution_result->serialize(), url.serialize()))
  140. return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Could not resolve '{}' as it backtracks above its prefix specifierKey.", normalized_specifier) };
  141. // 9. Return url.
  142. return url;
  143. }
  144. }
  145. // 2. Return null.
  146. return Optional<AK::URL> {};
  147. }
  148. // https://html.spec.whatwg.org/multipage/webappapis.html#resolving-a-url-like-module-specifier
  149. Optional<AK::URL> resolve_url_like_module_specifier(String const& specifier, AK::URL const& base_url)
  150. {
  151. // 1. If specifier starts with "/", "./", or "../", then:
  152. if (specifier.starts_with("/"sv) || specifier.starts_with("./"sv) || specifier.starts_with("../"sv)) {
  153. // 1. Let url be the result of URL parsing specifier with baseURL.
  154. auto url = URLParser::parse(specifier, &base_url);
  155. // 2. If url is failure, then return null.
  156. if (!url.is_valid())
  157. return {};
  158. // 3. Return url.
  159. return url;
  160. }
  161. // 2. Let url be the result of URL parsing specifier (with no base URL).
  162. auto url = URLParser::parse(specifier);
  163. // 3. If url is failure, then return null.
  164. if (!url.is_valid())
  165. return {};
  166. // 4. Return url.
  167. return url;
  168. }
  169. // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure
  170. void fetch_internal_module_script_graph(JS::ModuleRequest const& module_request, EnvironmentSettingsObject& fetch_client_settings_object, StringView destination, Script& referring_script, HashTable<ModuleLocationTuple> const& visited_set, ModuleCallback on_complete)
  171. {
  172. // 1. Let url be the result of resolving a module specifier given referringScript and moduleRequest.[[Specifier]].
  173. auto url = MUST(resolve_module_specifier(referring_script, module_request.module_specifier));
  174. // 2. Assert: the previous step never throws an exception, because resolving a module specifier must have been previously successful with these same two arguments.
  175. // NOTE: Handled by MUST above.
  176. // 3. Let moduleType be the result of running the module type from module request steps given moduleRequest.
  177. auto module_type = module_type_from_module_request(module_request);
  178. // 4. Assert: visited set contains (url, moduleType).
  179. VERIFY(visited_set.contains({ url, module_type }));
  180. // 5. Fetch a single module script given url, fetch client settings object, destination, options, referringScript's settings object,
  181. // referringScript's base URL, moduleRequest, false, and onSingleFetchComplete as defined below. If performFetch was given, pass it along as well.
  182. // FIXME: Pass options and performFetch if given.
  183. fetch_single_module_script(url, fetch_client_settings_object, destination, referring_script.settings_object(), referring_script.base_url(), module_request, TopLevelModule::No, [on_complete = move(on_complete), &fetch_client_settings_object, destination, visited_set](auto* result) mutable {
  184. // onSingleFetchComplete given result is the following algorithm:
  185. // 1. If result is null, run onComplete with null, and abort these steps.
  186. if (!result) {
  187. on_complete(nullptr);
  188. return;
  189. }
  190. // 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.
  191. // FIXME: Pass performFetch if given.
  192. fetch_descendants_of_a_module_script(*result, fetch_client_settings_object, destination, visited_set, move(on_complete));
  193. });
  194. }
  195. // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-a-module-script
  196. void fetch_descendants_of_a_module_script(JavaScriptModuleScript& module_script, EnvironmentSettingsObject& fetch_client_settings_object, StringView destination, HashTable<ModuleLocationTuple> visited_set, ModuleCallback on_complete)
  197. {
  198. // 1. If module script's record is null, run onComplete with module script and return.
  199. if (!module_script.record()) {
  200. on_complete(&module_script);
  201. return;
  202. }
  203. // 2. Let record be module script's record.
  204. auto const& record = module_script.record();
  205. // 3. If record is not a Cyclic Module Record, or if record.[[RequestedModules]] is empty, run onComplete with module script and return.
  206. // FIXME: Currently record is always a cyclic module.
  207. if (record->requested_modules().is_empty()) {
  208. on_complete(&module_script);
  209. return;
  210. }
  211. // 4. Let moduleRequests be a new empty list.
  212. Vector<JS::ModuleRequest> module_requests;
  213. // 5. For each ModuleRequest Record requested of record.[[RequestedModules]],
  214. for (auto const& requested : record->requested_modules()) {
  215. // 1. Let url be the result of resolving a module specifier given module script and requested.[[Specifier]].
  216. auto url = MUST(resolve_module_specifier(module_script, requested.module_specifier));
  217. // 2. Assert: the previous step never throws an exception, because resolving a module specifier must have been previously successful with these same two arguments.
  218. // NOTE: Handled by MUST above.
  219. // 3. Let moduleType be the result of running the module type from module request steps given requested.
  220. auto module_type = module_type_from_module_request(requested);
  221. // 4. If visited set does not contain (url, moduleType), then:
  222. if (!visited_set.contains({ url, module_type })) {
  223. // 1. Append requested to moduleRequests.
  224. module_requests.append(requested);
  225. // 2. Append (url, moduleType) to visited set.
  226. visited_set.set({ url, module_type });
  227. }
  228. }
  229. // FIXME: 6. Let options be the descendant script fetch options for module script's fetch options.
  230. // FIXME: 7. Assert: options is not null, as module script is a JavaScript module script.
  231. // 8. Let pendingCount be the length of moduleRequests.
  232. auto pending_count = module_requests.size();
  233. // 9. If pendingCount is zero, run onComplete with module script.
  234. if (pending_count == 0) {
  235. on_complete(&module_script);
  236. return;
  237. }
  238. // 10. Let failed be false.
  239. auto context = DescendantFetchingContext::create();
  240. context->set_pending_count(pending_count);
  241. context->set_failed(false);
  242. context->set_on_complete(move(on_complete));
  243. // 11. For each moduleRequest in moduleRequests, perform the internal module script graph fetching procedure given moduleRequest,
  244. // fetch client settings object, destination, options, module script, visited set, and onInternalFetchingComplete as defined below.
  245. // If performFetch was given, pass it along as well.
  246. for (auto const& module_request : module_requests) {
  247. // FIXME: Pass options and performFetch if given.
  248. fetch_internal_module_script_graph(module_request, fetch_client_settings_object, destination, module_script, visited_set, [context, &module_script](auto const* result) mutable {
  249. // onInternalFetchingComplete given result is the following algorithm:
  250. // 1. If failed is true, then abort these steps.
  251. if (context->failed())
  252. return;
  253. // 2. If result is null, then set failed to true, run onComplete with null, and abort these steps.
  254. if (!result) {
  255. context->set_failed(true);
  256. context->on_complete(nullptr);
  257. return;
  258. }
  259. // 3. Assert: pendingCount is greater than zero.
  260. VERIFY(context->pending_count() > 0);
  261. // 4. Decrement pendingCount by one.
  262. context->decrement_pending_count();
  263. // 5. If pendingCount is zero, run onComplete with module script.
  264. if (context->pending_count() == 0)
  265. context->on_complete(&module_script);
  266. });
  267. }
  268. }
  269. // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
  270. void fetch_single_module_script(AK::URL const& url, EnvironmentSettingsObject&, StringView, EnvironmentSettingsObject& module_map_settings_object, AK::URL const&, Optional<JS::ModuleRequest> const& module_request, TopLevelModule, ModuleCallback on_complete)
  271. {
  272. // 1. Let moduleType be "javascript".
  273. String module_type = "javascript"sv;
  274. // 2. If moduleRequest was given, then set moduleType to the result of running the module type from module request steps given moduleRequest.
  275. if (module_request.has_value())
  276. module_type = module_type_from_module_request(*module_request);
  277. // 3. Assert: the result of running the module type allowed steps given moduleType and module map settings object is true.
  278. // Otherwise we would not have reached this point because a failure would have been raised when inspecting moduleRequest.[[Assertions]]
  279. // in create a JavaScript module script or fetch an import() module script graph.
  280. VERIFY(module_map_settings_object.module_type_allowed(module_type));
  281. // 4. Let moduleMap be module map settings object's module map.
  282. auto& module_map = module_map_settings_object.module_map();
  283. // 5. If moduleMap[(url, moduleType)] is "fetching", wait in parallel until that entry's value changes,
  284. // then queue a task on the networking task source to proceed with running the following steps.
  285. if (module_map.is_fetching(url, module_type)) {
  286. module_map.wait_for_change(url, module_type, [on_complete = move(on_complete)](auto entry) {
  287. // FIXME: This should queue a task.
  288. // FIXME: This should run other steps, for now we just assume the script loaded.
  289. VERIFY(entry.type == ModuleMap::EntryType::ModuleScript);
  290. on_complete(entry.module_script);
  291. });
  292. return;
  293. }
  294. // 6. If moduleMap[(url, moduleType)] exists, run onComplete given moduleMap[(url, moduleType)], and return.
  295. auto entry = module_map.get(url, module_type);
  296. if (entry.has_value() && entry->type == ModuleMap::EntryType::ModuleScript) {
  297. on_complete(entry->module_script);
  298. return;
  299. }
  300. // 7. Set moduleMap[(url, moduleType)] to "fetching".
  301. module_map.set(url, module_type, { ModuleMap::EntryType::Fetching, nullptr });
  302. // FIXME: Implement non ad-hoc version of steps 8 to 20.
  303. auto request = LoadRequest::create_for_url_on_page(url, nullptr);
  304. ResourceLoader::the().load(
  305. request,
  306. [url, module_type, &module_map_settings_object, on_complete = move(on_complete), &module_map](StringView data, auto& response_headers, auto) {
  307. if (data.is_null()) {
  308. dbgln("Failed to load module {}", url);
  309. module_map.set(url, module_type, { ModuleMap::EntryType::Failed, nullptr });
  310. on_complete(nullptr);
  311. return;
  312. }
  313. auto content_type_header = response_headers.get("Content-Type");
  314. if (!content_type_header.has_value()) {
  315. dbgln("Module has no content type! {}", url);
  316. module_map.set(url, module_type, { ModuleMap::EntryType::Failed, nullptr });
  317. on_complete(nullptr);
  318. return;
  319. }
  320. if (MimeSniff::is_javascript_mime_type_essence_match(*content_type_header) && module_type == "javascript"sv) {
  321. auto module_script = JavaScriptModuleScript::create(url.basename(), data, module_map_settings_object, url);
  322. module_map.set(url, module_type, { ModuleMap::EntryType::ModuleScript, module_script });
  323. on_complete(module_script);
  324. return;
  325. }
  326. dbgln("Module has no JS content type! {} of type {}, with content {}", url, module_type, *content_type_header);
  327. module_map.set(url, module_type, { ModuleMap::EntryType::Failed, nullptr });
  328. on_complete(nullptr);
  329. },
  330. [module_type, url](auto&, auto) {
  331. dbgln("Failed to load module script");
  332. TODO();
  333. });
  334. }
  335. // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
  336. void fetch_external_module_script_graph(AK::URL const& url, EnvironmentSettingsObject& settings_object, ModuleCallback on_complete)
  337. {
  338. // 1. Disallow further import maps given settings object.
  339. settings_object.disallow_further_import_maps();
  340. // 2. Fetch a single module script given url, settings object, "script", options, settings object, "client", true, and with the following steps given result:
  341. // FIXME: Pass options.
  342. fetch_single_module_script(url, settings_object, "script"sv, settings_object, "client"sv, {}, TopLevelModule::Yes, [&settings_object, on_complete = move(on_complete), url](auto* result) mutable {
  343. // 1. If result is null, run onComplete given null, and abort these steps.
  344. if (!result) {
  345. on_complete(nullptr);
  346. return;
  347. }
  348. // 2. Let visited set be « (url, "javascript") ».
  349. HashTable<ModuleLocationTuple> visited_set;
  350. visited_set.set({ url, "javascript"sv });
  351. // 3. Fetch the descendants of and link result given settings object, "script", visited set, and onComplete.
  352. fetch_descendants_of_and_link_a_module_script(*result, settings_object, "script"sv, move(visited_set), move(on_complete));
  353. });
  354. }
  355. // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-an-inline-module-script-graph
  356. void fetch_inline_module_script_graph(String const& filename, String const& source_text, AK::URL const& base_url, EnvironmentSettingsObject& settings_object, ModuleCallback on_complete)
  357. {
  358. // 1. Disallow further import maps given settings object.
  359. settings_object.disallow_further_import_maps();
  360. // 2. Let script be the result of creating a JavaScript module script using source text, settings object, base URL, and options.
  361. auto script = JavaScriptModuleScript::create(filename, source_text.view(), settings_object, base_url);
  362. // 3. If script is null, run onComplete given null, and return.
  363. if (!script) {
  364. on_complete(nullptr);
  365. return;
  366. }
  367. // 4. Let visited set be an empty set.
  368. HashTable<ModuleLocationTuple> visited_set;
  369. // 5. Fetch the descendants of and link script, given settings object, the destination "script", visited set, and onComplete.
  370. fetch_descendants_of_and_link_a_module_script(*script, settings_object, "script"sv, visited_set, move(on_complete));
  371. }
  372. // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-and-link-a-module-script
  373. void fetch_descendants_of_and_link_a_module_script(JavaScriptModuleScript& module_script, EnvironmentSettingsObject& fetch_client_settings_object, StringView destination, HashTable<ModuleLocationTuple> const& visited_set, ModuleCallback on_complete)
  374. {
  375. // 1. Fetch the descendants of module script, given fetch client settings object, destination, visited set, and onFetchDescendantsComplete as defined below.
  376. // If performFetch was given, pass it along as well.
  377. // FIXME: Pass performFetch if given.
  378. fetch_descendants_of_a_module_script(module_script, fetch_client_settings_object, destination, visited_set, [on_complete = move(on_complete)](JavaScriptModuleScript* result) {
  379. // onFetchDescendantsComplete given result is the following algorithm:
  380. // 1. If result is null, then run onComplete given result, and abort these steps.
  381. if (!result) {
  382. on_complete(nullptr);
  383. return;
  384. }
  385. // FIXME: 2. Let parse error be the result of finding the first parse error given result.
  386. // 3. If parse error is null, then:
  387. if (result->record()) {
  388. // 1. Let record be result's record.
  389. auto const& record = *result->record();
  390. // 2. Perform record.Link().
  391. auto linking_result = const_cast<JS::SourceTextModule&>(record).link(result->vm());
  392. // TODO: If this throws an exception, set result's error to rethrow to that exception.
  393. if (linking_result.is_error())
  394. TODO();
  395. } else {
  396. // FIXME: 4. Otherwise, set result's error to rethrow to parse error.
  397. TODO();
  398. }
  399. // 5. Run onComplete given result.
  400. on_complete(result);
  401. });
  402. }
  403. }