diff --git a/Tests/LibWeb/Text/expected/HTML/import-maps-invalid.txt b/Tests/LibWeb/Text/expected/HTML/import-maps-invalid.txt new file mode 100644 index 00000000000..7ef22e9a431 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/import-maps-invalid.txt @@ -0,0 +1 @@ +PASS diff --git a/Tests/LibWeb/Text/input/HTML/import-maps-invalid.html b/Tests/LibWeb/Text/input/HTML/import-maps-invalid.html new file mode 100644 index 00000000000..13218f00329 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/import-maps-invalid.html @@ -0,0 +1,10 @@ + + + + diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.cpp index 026a284e96a..132cb0c873f 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -23,15 +24,13 @@ JS::NonnullGCPtr ImportMapParseResult::create(JS::Realm& r { // 1. Let result be an import map parse result whose import map is null and whose error to rethrow is null. auto result = realm.heap().allocate(realm); - result->set_error_to_rethrow(JS::js_null()); // 2. Parse an import map string given input and baseURL, catching any exceptions. auto import_map = parse_import_map_string(realm, input, base_url); // 2.1. If this threw an exception, then set result's error to rethrow to that exception. - // FIXME: rethrow the original exception if (import_map.is_exception()) - result->set_error_to_rethrow(JS::Error::create(realm, "Failed to parse import map string"sv)); + result->set_error_to_rethrow(import_map.exception()); // 2.2. Otherwise, set result's import map to the return value. else @@ -41,7 +40,7 @@ JS::NonnullGCPtr ImportMapParseResult::create(JS::Realm& r return result; } -void ImportMapParseResult::visit_host_defined_self(JS::Cell::Visitor& visitor) +void ImportMapParseResult::visit_host_defined_self(Visitor& visitor) { visitor.visit(*this); } @@ -49,15 +48,28 @@ void ImportMapParseResult::visit_host_defined_self(JS::Cell::Visitor& visitor) void ImportMapParseResult::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); - visitor.visit(m_error_to_rethrow); + if (m_error_to_rethrow.has_value()) { + m_error_to_rethrow.value().visit( + [&](WebIDL::SimpleException const&) { + // ignore + }, + [&](JS::NonnullGCPtr exception) { + visitor.visit(exception); + }, + [&](JS::Completion const& completion) { + if (completion.value().has_value()) + visitor.visit(completion.value().value()); + }); + } } // https://html.spec.whatwg.org/multipage/webappapis.html#register-an-import-map void ImportMapParseResult::register_import_map(Window& global) { // 1. If result's error to rethrow is not null, then report the exception given by result's error to rethrow and return. - if (!m_error_to_rethrow.is_null()) { - HTML::report_exception(m_error_to_rethrow, global.realm()); + if (m_error_to_rethrow.has_value()) { + auto completion = Web::Bindings::dom_exception_to_throw_completion(global.vm(), m_error_to_rethrow.value()); + HTML::report_exception(completion, global.realm()); return; } diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.h b/Userland/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.h index e21c6346e42..bd4e64b5566 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ImportMapParseResult.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace Web::HTML { @@ -29,8 +30,8 @@ public: [[nodiscard]] Optional const& import_map() const { return m_import_map; } void set_import_map(ImportMap const& value) { m_import_map = value; } - [[nodiscard]] JS::Value error_to_rethrow() const { return m_error_to_rethrow; } - void set_error_to_rethrow(JS::Value value) { m_error_to_rethrow = value; } + [[nodiscard]] Optional const& error_to_rethrow() const { return m_error_to_rethrow; } + void set_error_to_rethrow(WebIDL::Exception const& value) { m_error_to_rethrow = value; } void register_import_map(Window& global); @@ -40,13 +41,13 @@ protected: virtual void visit_edges(Visitor&) override; private: - virtual void visit_host_defined_self(JS::Cell::Visitor&) override; + virtual void visit_host_defined_self(Visitor&) override; // https://html.spec.whatwg.org/multipage/webappapis.html#impr-import-map Optional m_import_map; // https://html.spec.whatwg.org/multipage/webappapis.html#impr-error-to-rethrow - JS::Value m_error_to_rethrow; + Optional m_error_to_rethrow; }; }