diff --git a/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Libraries/LibWeb/Bindings/MainThreadVM.cpp index 4b3b4613d28..a9eead814cb 100644 --- a/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -463,7 +463,11 @@ void initialize_main_thread_vm(AgentType type) // 1. Let error be a new SyntaxError exception. auto error = JS::SyntaxError::create(*module_map_realm, "Module request attributes must only contain a type attribute"_string); - // FIXME: 2. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to error. + // 2. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to error. + if (auto* load_state_as_fetch_context = as(load_state.ptr()); + load_state_as_fetch_context && load_state_as_fetch_context->error_to_rethrow.is_null()) { + load_state_as_fetch_context->error_to_rethrow = error; + } // 3. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(error)). JS::finish_loading_imported_module(referrer, module_request, payload, JS::throw_completion(error)); @@ -479,7 +483,11 @@ void initialize_main_thread_vm(AgentType type) // 3. If the previous step threw an exception, then: if (maybe_exception.is_exception()) { - // FIXME: 1. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to resolutionError. + // 1. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to resolutionError. + if (auto* load_state_as_fetch_context = as(load_state.ptr()); + load_state_as_fetch_context && load_state_as_fetch_context->error_to_rethrow.is_null()) { + load_state_as_fetch_context->error_to_rethrow = exception_to_throw_completion(vm, maybe_exception.exception()).release_value(); + } // 2. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(resolutionError)). auto completion = exception_to_throw_completion(main_thread_vm(), maybe_exception.exception()); @@ -497,7 +505,11 @@ void initialize_main_thread_vm(AgentType type) // 1. Let error be a new TypeError exception. auto error = JS::TypeError::create(*module_map_realm, MUST(String::formatted("Module type '{}' is not supported", module_type))); - // FIXME: 2. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to error. + // 2. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to error. + if (auto* load_state_as_fetch_context = as(load_state.ptr()); + load_state_as_fetch_context && load_state_as_fetch_context->error_to_rethrow.is_null()) { + load_state_as_fetch_context->error_to_rethrow = error; + } // 3. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(error)). JS::finish_loading_imported_module(referrer, module_request, payload, JS::throw_completion(error)); @@ -521,7 +533,11 @@ void initialize_main_thread_vm(AgentType type) // 9. If the previous step threw an exception, then: if (url.is_exception()) { - // FIXME: 1. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to resolutionError. + // 1. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to resolutionError. + if (auto* load_state_as_fetch_context = as(load_state.ptr()); + load_state_as_fetch_context && load_state_as_fetch_context->error_to_rethrow.is_null()) { + load_state_as_fetch_context->error_to_rethrow = exception_to_throw_completion(vm, url.exception()).release_value(); + } // 2. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(resolutionError)). auto completion = exception_to_throw_completion(main_thread_vm(), url.exception()); @@ -582,12 +598,10 @@ void initialize_main_thread_vm(AgentType type) // 2. Set completion to ThrowCompletion(parseError). auto completion = JS::throw_completion(parse_error); - // 3. If loadState is not undefined and loadState.[[ParseError]] is null, set loadState.[[ParseError]] to parseError. - if (load_state) { - auto& load_state_as_fetch_context = static_cast(*load_state); - if (load_state_as_fetch_context.parse_error.is_null()) { - load_state_as_fetch_context.parse_error = parse_error; - } + // 3. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to parseError. + if (auto* load_state_as_fetch_context = as(load_state.ptr()); + load_state_as_fetch_context && load_state_as_fetch_context->error_to_rethrow.is_null()) { + load_state_as_fetch_context->error_to_rethrow = parse_error; } return completion; diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp index 72200fb2e53..38a6f277a50 100644 --- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp +++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp @@ -817,7 +817,7 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm, return; } - // 3. Let state be Record { [[ParseError]]: null, [[Destination]]: destination, [[PerformFetch]]: null, [[FetchClient]]: fetchClient }. + // 3. Let state be Record { [[ErrorToRethrow]]: null, [[Destination]]: destination, [[PerformFetch]]: null, [[FetchClient]]: fetchClient }. auto state = realm.heap().allocate(JS::js_null(), destination, nullptr, fetch_client); // 4. If performFetch was given, set state.[[PerformFetch]] to performFetch. @@ -854,10 +854,10 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm, // 7. Upon rejection of loadingPromise, run the following steps: GC::create_function(realm.heap(), [state, &module_script, on_complete](JS::Value) -> WebIDL::ExceptionOr { - // 1. If state.[[ParseError]] is not null, set moduleScript's error to rethrow to state.[[ParseError]] and run + // 1. If state.[[ErrorToRethrow]] is not null, set moduleScript's error to rethrow to state.[[ErrorToRethrow]] and run // onComplete given moduleScript. - if (!state->parse_error.is_null()) { - module_script.set_error_to_rethrow(state->parse_error); + if (!state->error_to_rethrow.is_null()) { + module_script.set_error_to_rethrow(state->error_to_rethrow); on_complete->function()(module_script); } diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.h b/Libraries/LibWeb/HTML/Scripting/Fetching.h index 92310db043a..ad2252e3a08 100644 --- a/Libraries/LibWeb/HTML/Scripting/Fetching.h +++ b/Libraries/LibWeb/HTML/Scripting/Fetching.h @@ -59,14 +59,14 @@ class FetchContext : public JS::GraphLoadingState::HostDefined { GC_DECLARE_ALLOCATOR(FetchContext); public: - JS::Value parse_error; // [[ParseError]] + JS::Value error_to_rethrow; // [[ErrorToRethrow]] Fetch::Infrastructure::Request::Destination destination; // [[Destination]] PerformTheFetchHook perform_fetch; // [[PerformFetch]] GC::Ref fetch_client; // [[FetchClient]] private: - FetchContext(JS::Value parse_error, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, EnvironmentSettingsObject& fetch_client) - : parse_error(parse_error) + FetchContext(JS::Value error_to_rethrow, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, EnvironmentSettingsObject& fetch_client) + : error_to_rethrow(error_to_rethrow) , destination(destination) , perform_fetch(perform_fetch) , fetch_client(fetch_client) @@ -76,7 +76,7 @@ private: void visit_edges(Visitor& visitor) override { Base::visit_edges(visitor); - visitor.visit(parse_error); + visitor.visit(error_to_rethrow); visitor.visit(perform_fetch); visitor.visit(fetch_client); }