mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +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.
|
// 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);
|
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)).
|
// 3. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(error)).
|
||||||
JS::finish_loading_imported_module(referrer, module_request, payload, JS::throw_completion(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:
|
// 3. If the previous step threw an exception, then:
|
||||||
if (maybe_exception.is_exception()) {
|
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)).
|
// 2. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(resolutionError)).
|
||||||
auto completion = exception_to_throw_completion(main_thread_vm(), maybe_exception.exception());
|
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.
|
// 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)));
|
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)).
|
// 3. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(error)).
|
||||||
JS::finish_loading_imported_module(referrer, module_request, payload, JS::throw_completion(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:
|
// 9. If the previous step threw an exception, then:
|
||||||
if (url.is_exception()) {
|
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)).
|
// 2. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, ThrowCompletion(resolutionError)).
|
||||||
auto completion = exception_to_throw_completion(main_thread_vm(), url.exception());
|
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).
|
// 2. Set completion to ThrowCompletion(parseError).
|
||||||
auto completion = JS::throw_completion(parse_error);
|
auto completion = JS::throw_completion(parse_error);
|
||||||
|
|
||||||
// 3. If loadState is not undefined and loadState.[[ParseError]] is null, set loadState.[[ParseError]] to parseError.
|
// 3. If loadState is not undefined and loadState.[[ErrorToRethrow]] is null, set loadState.[[ErrorToRethrow]] to parseError.
|
||||||
if (load_state) {
|
if (auto* load_state_as_fetch_context = as<HTML::FetchContext>(load_state.ptr());
|
||||||
auto& load_state_as_fetch_context = static_cast<HTML::FetchContext&>(*load_state);
|
load_state_as_fetch_context && load_state_as_fetch_context->error_to_rethrow.is_null()) {
|
||||||
if (load_state_as_fetch_context.parse_error.is_null()) {
|
load_state_as_fetch_context->error_to_rethrow = parse_error;
|
||||||
load_state_as_fetch_context.parse_error = parse_error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return completion;
|
return completion;
|
||||||
|
|
|
@ -817,7 +817,7 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm,
|
||||||
return;
|
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);
|
auto state = realm.heap().allocate<FetchContext>(JS::js_null(), destination, nullptr, fetch_client);
|
||||||
|
|
||||||
// 4. If performFetch was given, set state.[[PerformFetch]] to performFetch.
|
// 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:
|
// 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> {
|
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.
|
// onComplete given moduleScript.
|
||||||
if (!state->parse_error.is_null()) {
|
if (!state->error_to_rethrow.is_null()) {
|
||||||
module_script.set_error_to_rethrow(state->parse_error);
|
module_script.set_error_to_rethrow(state->error_to_rethrow);
|
||||||
|
|
||||||
on_complete->function()(module_script);
|
on_complete->function()(module_script);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,14 +59,14 @@ class FetchContext : public JS::GraphLoadingState::HostDefined {
|
||||||
GC_DECLARE_ALLOCATOR(FetchContext);
|
GC_DECLARE_ALLOCATOR(FetchContext);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JS::Value parse_error; // [[ParseError]]
|
JS::Value error_to_rethrow; // [[ErrorToRethrow]]
|
||||||
Fetch::Infrastructure::Request::Destination destination; // [[Destination]]
|
Fetch::Infrastructure::Request::Destination destination; // [[Destination]]
|
||||||
PerformTheFetchHook perform_fetch; // [[PerformFetch]]
|
PerformTheFetchHook perform_fetch; // [[PerformFetch]]
|
||||||
GC::Ref<EnvironmentSettingsObject> fetch_client; // [[FetchClient]]
|
GC::Ref<EnvironmentSettingsObject> fetch_client; // [[FetchClient]]
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FetchContext(JS::Value parse_error, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, EnvironmentSettingsObject& fetch_client)
|
FetchContext(JS::Value error_to_rethrow, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, EnvironmentSettingsObject& fetch_client)
|
||||||
: parse_error(parse_error)
|
: error_to_rethrow(error_to_rethrow)
|
||||||
, destination(destination)
|
, destination(destination)
|
||||||
, perform_fetch(perform_fetch)
|
, perform_fetch(perform_fetch)
|
||||||
, fetch_client(fetch_client)
|
, fetch_client(fetch_client)
|
||||||
|
@ -76,7 +76,7 @@ private:
|
||||||
void visit_edges(Visitor& visitor) override
|
void visit_edges(Visitor& visitor) override
|
||||||
{
|
{
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
visitor.visit(parse_error);
|
visitor.visit(error_to_rethrow);
|
||||||
visitor.visit(perform_fetch);
|
visitor.visit(perform_fetch);
|
||||||
visitor.visit(fetch_client);
|
visitor.visit(fetch_client);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue