Skip to content

Truly independent web browser

LibWeb: Connect upgraded elements in documents without registries

Andreas Klingfcc020332713
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index 42a5407ddd1..6a396ef89da 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -1116,12 +1116,16 @@ void Node::insert_nodes_before(ReadonlySpan<GC::Ref<Node>> nodes, GC::Ptr<Node>
return TraversalDecision::Continue;
// 3. If inclusiveDescendant is an element and inclusiveDescendant’s custom element registry is non-null:
- if (auto* element = as_if<Element>(inclusive_descendant); element && element->custom_element_registry()) {
+ // INTEROP: Already-custom elements still receive connectedCallback after adoption into a document with
+ // no registry, as in Chromium and Firefox. Their definition supplies the callback independently of
+ // the registry available to upgrade new elements.
+ if (auto* element = as_if<Element>(inclusive_descendant)) {
+ auto registry = element->custom_element_registry();
// 1. If inclusiveDescendant’s custom element registry’s is scoped is true, then append
// inclusiveDescendant’s node document to inclusiveDescendant’s custom element registry’s scoped
// document set.
- if (element->custom_element_registry()->is_scoped())
- element->custom_element_registry()->append_scoped_document(element->document());
+ if (registry && registry->is_scoped())
+ registry->append_scoped_document(element->document());
// 2. If inclusiveDescendant is custom, then enqueue a custom element callback reaction with
// inclusiveDescendant, callback name "connectedCallback", and « ».
@@ -1129,7 +1133,7 @@ void Node::insert_nodes_before(ReadonlySpan<GC::Ref<Node>> nodes, GC::Ptr<Node>
element->enqueue_a_custom_element_callback_reaction(HTML::CustomElementReactionNames::connectedCallback);
// 3. Otherwise, try to upgrade inclusiveDescendant.
- else {
+ else if (registry) {
element->try_to_upgrade();
}
}
diff --git a/Tests/LibWeb/Text/expected/wpt-import/custom-elements/adopted-callback.txt b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/adopted-callback.txt
index 129e5b710f0..e213024146d 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/custom-elements/adopted-callback.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/adopted-callback.txt
@@ -2,58 +2,57 @@ Harness status: OK
Found 71 tests
-17 Pass
-54 Fail
+71 Pass
Pass Inserting a custom element into the owner document must not enqueue and invoke adoptedCallback
-Fail Inserting a custom element into the document of the template elements must enqueue and invoke adoptedCallback
-Fail Moving a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
-Fail Inserting an ancestor of custom element into the document of the template elements must enqueue and invoke adoptedCallback
-Fail Moving an ancestor of custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a shadow tree in the document of the template elements must enqueue and invoke adoptedCallback
-Fail Inserting the shadow host of a custom element into the document of the template elements must enqueue and invoke adoptedCallback
-Fail Moving the shadow host of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
-Fail Moving the shadow host's shadow of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
-Fail Moving the <template>'s content of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into the document of the template elements must enqueue and invoke adoptedCallback
+Pass Moving a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
+Pass Inserting an ancestor of custom element into the document of the template elements must enqueue and invoke adoptedCallback
+Pass Moving an ancestor of custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a shadow tree in the document of the template elements must enqueue and invoke adoptedCallback
+Pass Inserting the shadow host of a custom element into the document of the template elements must enqueue and invoke adoptedCallback
+Pass Moving the shadow host of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
+Pass Moving the shadow host's shadow of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
+Pass Moving the <template>'s content of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to the document of the template elements must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a new document must enqueue and invoke adoptedCallback
-Fail Moving a custom element from the owner document into a new document must enqueue and invoke adoptedCallback
-Fail Inserting an ancestor of custom element into a new document must enqueue and invoke adoptedCallback
-Fail Moving an ancestor of custom element from the owner document into a new document must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a shadow tree in a new document must enqueue and invoke adoptedCallback
-Fail Inserting the shadow host of a custom element into a new document must enqueue and invoke adoptedCallback
-Fail Moving the shadow host of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback
-Fail Moving the shadow host's shadow of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback
-Fail Moving the <template>'s content of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a new document must enqueue and invoke adoptedCallback
+Pass Moving a custom element from the owner document into a new document must enqueue and invoke adoptedCallback
+Pass Inserting an ancestor of custom element into a new document must enqueue and invoke adoptedCallback
+Pass Moving an ancestor of custom element from the owner document into a new document must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a shadow tree in a new document must enqueue and invoke adoptedCallback
+Pass Inserting the shadow host of a custom element into a new document must enqueue and invoke adoptedCallback
+Pass Moving the shadow host of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback
+Pass Moving the shadow host's shadow of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback
+Pass Moving the <template>'s content of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to a new document must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a cloned document must enqueue and invoke adoptedCallback
-Fail Moving a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
-Fail Inserting an ancestor of custom element into a cloned document must enqueue and invoke adoptedCallback
-Fail Moving an ancestor of custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a shadow tree in a cloned document must enqueue and invoke adoptedCallback
-Fail Inserting the shadow host of a custom element into a cloned document must enqueue and invoke adoptedCallback
-Fail Moving the shadow host of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
-Fail Moving the shadow host's shadow of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
-Fail Moving the <template>'s content of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a cloned document must enqueue and invoke adoptedCallback
+Pass Moving a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
+Pass Inserting an ancestor of custom element into a cloned document must enqueue and invoke adoptedCallback
+Pass Moving an ancestor of custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a shadow tree in a cloned document must enqueue and invoke adoptedCallback
+Pass Inserting the shadow host of a custom element into a cloned document must enqueue and invoke adoptedCallback
+Pass Moving the shadow host of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
+Pass Moving the shadow host's shadow of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
+Pass Moving the <template>'s content of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to a cloned document must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Moving a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Inserting an ancestor of custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Moving an ancestor of custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a shadow tree in a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Inserting the shadow host of a custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Moving the shadow host of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Moving the shadow host's shadow of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Moving the <template>'s content of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Moving a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Inserting an ancestor of custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Moving an ancestor of custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a shadow tree in a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Inserting the shadow host of a custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Moving the shadow host of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Moving the shadow host's shadow of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
+Pass Moving the <template>'s content of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to a document created by createHTMLDocument must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback
-Fail Moving a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
-Fail Inserting an ancestor of custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback
-Fail Moving an ancestor of custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a shadow tree in an HTML document created by createDocument must enqueue and invoke adoptedCallback
-Fail Inserting the shadow host of a custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback
-Fail Moving the shadow host of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
-Fail Moving the shadow host's shadow of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
-Fail Moving the <template>'s content of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Moving a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Inserting an ancestor of custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Moving an ancestor of custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a shadow tree in an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Inserting the shadow host of a custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Moving the shadow host of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Moving the shadow host's shadow of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
+Pass Moving the <template>'s content of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to an HTML document created by createDocument must enqueue and invoke adoptedCallback
Pass Inserting a custom element into the document of an iframe must enqueue and invoke adoptedCallback
Pass Moving a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback
@@ -65,13 +64,13 @@ Pass Moving the shadow host of a custom element from the owner document into the
Pass Moving the shadow host's shadow of a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback
Pass Moving the <template>'s content of a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to the document of an iframe must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
-Fail Moving a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
-Fail Inserting an ancestor of custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
-Fail Moving an ancestor of custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
-Fail Inserting a custom element into a shadow tree in an HTML document fetched by XHR must enqueue and invoke adoptedCallback
-Fail Inserting the shadow host of a custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
-Fail Moving the shadow host of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
-Fail Moving the shadow host's shadow of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
-Fail Moving the <template>'s content of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Moving a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Inserting an ancestor of custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Moving an ancestor of custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Inserting a custom element into a shadow tree in an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Inserting the shadow host of a custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Moving the shadow host of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Moving the shadow host's shadow of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
+Pass Moving the <template>'s content of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to an HTML document fetched by XHR must enqueue and invoke adoptedCallback
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/custom-elements/connected-callbacks.txt b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/connected-callbacks.txt
index bcf79822fcc..d8da8dc0a1f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/custom-elements/connected-callbacks.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/connected-callbacks.txt
@@ -2,45 +2,44 @@ Harness status: OK
Found 40 tests
-16 Pass
-24 Fail
+40 Pass
Pass Inserting a custom element into the document must enqueue and invoke connectedCallback
Pass Inserting an ancestor of custom element into the document must enqueue and invoke connectedCallback
Pass Inserting a custom element into a shadow tree in the document must enqueue and invoke connectedCallback
Pass Inserting the shadow host of a custom element into the document must enqueue and invoke connectedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to the document must not enqueue and invoke connectedCallback
-Fail Inserting a custom element into the document of the template elements must enqueue and invoke connectedCallback
-Fail Inserting an ancestor of custom element into the document of the template elements must enqueue and invoke connectedCallback
-Fail Inserting a custom element into a shadow tree in the document of the template elements must enqueue and invoke connectedCallback
-Fail Inserting the shadow host of a custom element into the document of the template elements must enqueue and invoke connectedCallback
+Pass Inserting a custom element into the document of the template elements must enqueue and invoke connectedCallback
+Pass Inserting an ancestor of custom element into the document of the template elements must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a shadow tree in the document of the template elements must enqueue and invoke connectedCallback
+Pass Inserting the shadow host of a custom element into the document of the template elements must enqueue and invoke connectedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to the document of the template elements must not enqueue and invoke connectedCallback
-Fail Inserting a custom element into a new document must enqueue and invoke connectedCallback
-Fail Inserting an ancestor of custom element into a new document must enqueue and invoke connectedCallback
-Fail Inserting a custom element into a shadow tree in a new document must enqueue and invoke connectedCallback
-Fail Inserting the shadow host of a custom element into a new document must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a new document must enqueue and invoke connectedCallback
+Pass Inserting an ancestor of custom element into a new document must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a shadow tree in a new document must enqueue and invoke connectedCallback
+Pass Inserting the shadow host of a custom element into a new document must enqueue and invoke connectedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to a new document must not enqueue and invoke connectedCallback
-Fail Inserting a custom element into a cloned document must enqueue and invoke connectedCallback
-Fail Inserting an ancestor of custom element into a cloned document must enqueue and invoke connectedCallback
-Fail Inserting a custom element into a shadow tree in a cloned document must enqueue and invoke connectedCallback
-Fail Inserting the shadow host of a custom element into a cloned document must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a cloned document must enqueue and invoke connectedCallback
+Pass Inserting an ancestor of custom element into a cloned document must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a shadow tree in a cloned document must enqueue and invoke connectedCallback
+Pass Inserting the shadow host of a custom element into a cloned document must enqueue and invoke connectedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to a cloned document must not enqueue and invoke connectedCallback
-Fail Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
-Fail Inserting an ancestor of custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
-Fail Inserting a custom element into a shadow tree in a document created by createHTMLDocument must enqueue and invoke connectedCallback
-Fail Inserting the shadow host of a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
+Pass Inserting an ancestor of custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a shadow tree in a document created by createHTMLDocument must enqueue and invoke connectedCallback
+Pass Inserting the shadow host of a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to a document created by createHTMLDocument must not enqueue and invoke connectedCallback
-Fail Inserting a custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback
-Fail Inserting an ancestor of custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback
-Fail Inserting a custom element into a shadow tree in an HTML document created by createDocument must enqueue and invoke connectedCallback
-Fail Inserting the shadow host of a custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback
+Pass Inserting a custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback
+Pass Inserting an ancestor of custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a shadow tree in an HTML document created by createDocument must enqueue and invoke connectedCallback
+Pass Inserting the shadow host of a custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to an HTML document created by createDocument must not enqueue and invoke connectedCallback
Pass Inserting a custom element into the document of an iframe must enqueue and invoke connectedCallback
Pass Inserting an ancestor of custom element into the document of an iframe must enqueue and invoke connectedCallback
Pass Inserting a custom element into a shadow tree in the document of an iframe must enqueue and invoke connectedCallback
Pass Inserting the shadow host of a custom element into the document of an iframe must enqueue and invoke connectedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to the document of an iframe must not enqueue and invoke connectedCallback
-Fail Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback
-Fail Inserting an ancestor of custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback
-Fail Inserting a custom element into a shadow tree in an HTML document fetched by XHR must enqueue and invoke connectedCallback
-Fail Inserting the shadow host of a custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback
+Pass Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback
+Pass Inserting an ancestor of custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback
+Pass Inserting a custom element into a shadow tree in an HTML document fetched by XHR must enqueue and invoke connectedCallback
+Pass Inserting the shadow host of a custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback
Pass Inserting a custom element into a detached shadow tree that belongs to an HTML document fetched by XHR must not enqueue and invoke connectedCallback
\ No newline at end of file