diff --git a/Libraries/LibWeb/DOM/ElementFactory.cpp b/Libraries/LibWeb/DOM/ElementFactory.cpp index ef07a0120b6..4f73431e445 100644 --- a/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -568,8 +568,6 @@ WebIDL::ExceptionOr> create_element(Document& document, FlyStri // 1. If the synchronous custom elements flag is set, then run these steps while catching any exceptions: if (synchronous_custom_elements_flag) { auto synchronously_upgrade_custom_element = [&]() -> JS::ThrowCompletionOr> { - auto& vm = document.vm(); - // 1. Let C be definition’s constructor. auto& constructor = definition->constructor(); @@ -578,7 +576,7 @@ WebIDL::ExceptionOr> create_element(Document& document, FlyStri // NOTE: IDL does not currently convert the object for us, so we will have to do it here. if (!result.has_value() || !result->is_object() || !is(result->as_object())) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "HTMLElement"sv); + return JS::throw_completion(JS::TypeError::create(realm, "Custom element constructor must return an object that implements HTMLElement"_string)); GC::Ref element = verify_cast(result->as_object()); diff --git a/Tests/LibWeb/Text/expected/wpt-import/custom-elements/parser/parser-fallsback-to-unknown-element.txt b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/parser/parser-fallsback-to-unknown-element.txt new file mode 100644 index 00000000000..6ec4029fe7f --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/parser/parser-fallsback-to-unknown-element.txt @@ -0,0 +1,9 @@ +Harness status: OK + +Found 4 tests + +4 Pass +Pass HTML parser must create a fallback HTMLUnknownElement when a custom element constructor returns a Text node +Pass HTML parser must create a fallback HTMLUnknownElement when a custom element constructor returns non-Element object +Pass HTML parser must create a fallback HTMLUnknownElement when a custom element constructor does not call super() +Pass HTML parser must create a fallback HTMLUnknownElement when a custom element constructor throws an exception \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/custom-elements/parser/parser-fallsback-to-unknown-element.html b/Tests/LibWeb/Text/input/wpt-import/custom-elements/parser/parser-fallsback-to-unknown-element.html new file mode 100644 index 00000000000..b19f54a6dec --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/custom-elements/parser/parser-fallsback-to-unknown-element.html @@ -0,0 +1,91 @@ + + + +Custom Elements: Changes to the HTML parser + + + + + + + + +
+ + + + + + + +