mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 09:18:52 +00:00
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:
parent
2959c2f2eb
commit
819fb39a87
Notes:
sideshowbarker
2024-07-17 22:01:16 +09:00
Author: https://github.com/awesomekling
Commit: 819fb39a87
Pull-request: https://github.com/SerenityOS/serenity/pull/18909
6 changed files with 47 additions and 22 deletions
|
@ -42,8 +42,9 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(DeprecatedString filename,
|
|||
// 8. Set script's muted errors to muted errors.
|
||||
script->m_muted_errors = muted_errors;
|
||||
|
||||
// FIXME: 9. Set script's parse error and error to rethrow to null.
|
||||
// NOTE: Error to rethrow was set to null in the construction of ClassicScript. We do not have parse error as it would currently go unused.
|
||||
// 9. Set script's parse error and error to rethrow to null.
|
||||
script->set_parse_error(JS::js_null());
|
||||
script->set_error_to_rethrow(JS::js_null());
|
||||
|
||||
// 10. Let result be ParseScript(source, settings's Realm, script).
|
||||
auto parse_timer = Core::ElapsedTimer::start_new();
|
||||
|
@ -55,9 +56,9 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(DeprecatedString filename,
|
|||
auto& parse_error = result.error().first();
|
||||
dbgln_if(HTML_SCRIPT_DEBUG, "ClassicScript: Failed to parse: {}", parse_error.to_deprecated_string());
|
||||
|
||||
// FIXME: 1. Set script's parse error and its error to rethrow to result[0].
|
||||
// We do not have parse error as it would currently go unused.
|
||||
script->m_error_to_rethrow = parse_error;
|
||||
// 1. Set script's parse error and its error to rethrow to result[0].
|
||||
script->set_parse_error(JS::SyntaxError::create(environment_settings_object.realm(), parse_error.to_string().release_value_but_fixme_should_propagate_errors()));
|
||||
script->set_error_to_rethrow(script->parse_error());
|
||||
|
||||
// 2. Return script.
|
||||
return script;
|
||||
|
@ -73,8 +74,6 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(DeprecatedString filename,
|
|||
// https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script
|
||||
JS::Completion ClassicScript::run(RethrowErrors rethrow_errors, JS::GCPtr<JS::Environment> lexical_environment_override)
|
||||
{
|
||||
auto& vm = settings_object().realm().vm();
|
||||
|
||||
// 1. Let settings be the settings object of script.
|
||||
auto& settings = settings_object();
|
||||
|
||||
|
@ -89,8 +88,8 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors, JS::GCPtr<JS::En
|
|||
JS::Completion evaluation_status;
|
||||
|
||||
// 5. If script's error to rethrow is not null, then set evaluationStatus to Completion { [[Type]]: throw, [[Value]]: script's error to rethrow, [[Target]]: empty }.
|
||||
if (m_error_to_rethrow.has_value()) {
|
||||
evaluation_status = vm.throw_completion<JS::SyntaxError>(TRY_OR_THROW_OOM(vm, m_error_to_rethrow.value().to_string()));
|
||||
if (!error_to_rethrow().is_null()) {
|
||||
evaluation_status = JS::Completion { JS::Completion::Type::Throw, error_to_rethrow(), {} };
|
||||
} else {
|
||||
auto timer = Core::ElapsedTimer::start_new();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue