LibWeb: Implement the "error to rethrow" mechanism in HTML::Script

This allows JS module loads to fail and throw without crashing the
WebContent process due to a TODO() assertion.
This commit is contained in:
Andreas Kling 2023-05-18 19:05:56 +02:00
parent 2959c2f2eb
commit 819fb39a87
Notes: sideshowbarker 2024-07-17 22:01:16 +09:00
6 changed files with 47 additions and 22 deletions

View file

@ -49,7 +49,8 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
// FIXME: 5. Set script's fetch options to options.
// 6. Set script's parse error and error to rethrow to null.
// NOTE: Parse error and error to rethrow were set to null in the construction of Script.
script->set_parse_error(JS::js_null());
script->set_error_to_rethrow(JS::js_null());
// 7. Let result be ParseModule(source, settings's Realm, script).
auto result = JS::SourceTextModule::parse(source, settings_object.realm(), filename.view(), script);
@ -59,7 +60,8 @@ WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::c
auto& parse_error = result.error().first();
dbgln("JavaScriptModuleScript: Failed to parse: {}", parse_error.to_deprecated_string());
// FIXME: 1. Set script's parse error to result[0].
// 1. Set script's parse error to result[0].
script->set_parse_error(JS::SyntaxError::create(settings_object.realm(), parse_error.to_string().release_value_but_fixme_should_propagate_errors()));
// 2. Return script.
return script;
@ -123,12 +125,16 @@ JS::Promise* JavaScriptModuleScript::run(PreventErrorReporting)
// 4. Let evaluationPromise be null.
JS::Promise* evaluation_promise = nullptr;
// FIXME: 5. If script's error to rethrow is not null, then set evaluationPromise to a promise rejected with script's error to rethrow.
// 5. If script's error to rethrow is not null, then set evaluationPromise to a promise rejected with script's error to rethrow.
if (!error_to_rethrow().is_null()) {
evaluation_promise = JS::Promise::create(settings.realm());
evaluation_promise->reject(error_to_rethrow());
}
// 6. Otherwise:
if (m_record) {
else {
// 1. Let record be script's record.
auto record = m_record;
VERIFY(record);
auto interpreter = JS::Interpreter::create_with_existing_realm(settings.realm());
JS::VM::InterpreterExecutionScope scope(*interpreter);
@ -147,8 +153,6 @@ JS::Promise* JavaScriptModuleScript::run(PreventErrorReporting)
} else {
evaluation_promise = elevation_promise_or_error.value();
}
} else {
TODO();
}
// FIXME: 7. If preventErrorReporting is false, then upon rejection of evaluationPromise with reason, report the exception given by reason for script.