mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 06:48:49 +00:00
LibWeb: Don't crash with invalid import maps
See: - http://wpt.live/import-maps/multiple-import-maps/with-errors.html
This commit is contained in:
parent
040653311e
commit
c891b83fc0
Notes:
github-actions[bot]
2024-08-06 14:26:37 +00:00
Author: https://github.com/jamierocks
Commit: c891b83fc0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/957
Reviewed-by: https://github.com/awesomekling
4 changed files with 35 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibJS/Runtime/ModuleRequest.h>
|
||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
||||
#include <LibWeb/HTML/Scripting/ImportMapParseResult.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
@ -23,15 +24,13 @@ JS::NonnullGCPtr<ImportMapParseResult> 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<ImportMapParseResult>(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> 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<WebIDL::DOMException> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue