mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb: Always set [[ErrorToRethrow]] for import validation errors
Corresponds to f6fb04a11f
This commit is contained in:
parent
4e854ca44a
commit
91e8a19391
Notes:
github-actions[bot]
2025-07-08 16:10:32 +00:00
Author: https://github.com/AtkinsSJ
Commit: 91e8a19391
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5353
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 32 additions and 18 deletions
|
@ -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<HTML::FetchContext>(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<HTML::FetchContext>(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<HTML::FetchContext>(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<HTML::FetchContext>(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<HTML::FetchContext&>(*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<HTML::FetchContext>(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;
|
||||
|
|
|
@ -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<FetchContext>(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<JS::Value> {
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -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<EnvironmentSettingsObject> 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue