Skip to content

Commit 281b5a9

Browse files
committed
attachShadow() should use the global registry by default
https://bugs.webkit.org/show_bug.cgi?id=300027 Reviewed by Ryosuke Niwa. Address whatwg/dom#1407 by partially reverting 296896@main. Canonical link: https://commits.webkit.org/300996@main
1 parent e53fd85 commit 281b5a9

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

LayoutTests/imported/w3c/web-platform-tests/custom-elements/registries/ShadowRoot-init-customElementRegistry-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PASS A newly attached disconnected ShadowRoot should use the global registry by
33
PASS A newly attached connected ShadowRoot should use the global registry by default
44
PASS A newly attached disconnected ShadowRoot should use the scoped registry if explicitly specified in attachShadow
55
PASS A newly attached connected ShadowRoot should use the scoped registry if explicitly specified in attachShadow
6-
PASS attachShadow() should use the global registry when customElementRegistry is null
7-
PASS attachShadow() should use the shadow host's registry when customElementRegistry is null
6+
PASS attachShadow() should use the global registry when customElementRegistry is null (host uses global registry)
7+
PASS attachShadow() should use the global registry when customElementRegistry is null (host uses custom registry)
88
PASS attachShadow() should use the null registry when the shadow host uses null registry and customElementRegistry is null
99

LayoutTests/imported/w3c/web-platform-tests/custom-elements/registries/ShadowRoot-init-customElementRegistry.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
const host = document.body.appendChild(document.createElement('div'));
3838
const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
3939
assert_equals(shadowRoot.customElementRegistry, window.customElements);
40-
}, 'attachShadow() should use the global registry when customElementRegistry is null');
40+
}, 'attachShadow() should use the global registry when customElementRegistry is null (host uses global registry)');
4141

4242
test(() => {
4343
const registry = new CustomElementRegistry;
4444
const host = document.body.appendChild(document.createElement('div', {customElementRegistry: registry}));
4545
const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
46-
assert_equals(shadowRoot.customElementRegistry, registry);
47-
}, 'attachShadow() should use the shadow host\'s registry when customElementRegistry is null');
46+
assert_equals(shadowRoot.customElementRegistry, window.customElements);
47+
}, 'attachShadow() should use the global registry when customElementRegistry is null (host uses custom registry)');
4848

4949
test(() => {
5050
const registry = new CustomElementRegistry;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
PASS Custom element inside 'shadowrootcustomelementregistry' declarative shadow root
3+
FAIL Built-in element inside 'shadowrootcustomelementregistry' declarative shadow root assert_equals: expected null but got object "[object CustomElementRegistry]"
4+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<title>Scoped Custom Element Registries: declarative shadow root</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<div id="host">
6+
<template shadowrootmode="open" shadowrootcustomelementregistry>
7+
<custom-element></custom-element>
8+
<div></div>
9+
</template>
10+
</div>
11+
<script>
12+
test(() => {
13+
const customElement = host.shadowRoot.firstElementChild;
14+
assert_equals(customElement.customElementRegistry, null);
15+
customElement.attachShadow({
16+
mode: "open"
17+
});
18+
assert_equals(customElement.shadowRoot.customElementRegistry, null);
19+
}, "Custom element inside 'shadowrootcustomelementregistry' declarative shadow root");
20+
21+
test(() => {
22+
const divElement = host.shadowRoot.lastElementChild;
23+
assert_equals(divElement.customElementRegistry, null);
24+
divElement.attachShadow({
25+
mode: "open"
26+
});
27+
assert_equals(divElement.shadowRoot.customElementRegistry, null);
28+
}, "Built-in element inside 'shadowrootcustomelementregistry' declarative shadow root");
29+
</script>

Source/WebCore/dom/Element.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3428,7 +3428,7 @@ ExceptionOr<ShadowRoot&> Element::attachShadow(const ShadowRootInit& init, std::
34283428
ASSERT(registryKind == CustomElementRegistryKind::Window);
34293429
scopedRegistry = ShadowRootScopedCustomElementRegistry::Yes;
34303430
} else
3431-
registry = CustomElementRegistry::registryForElement(*this);
3431+
registry = document().customElementRegistry();
34323432
Ref shadow = ShadowRoot::create(document(), init.mode, init.slotAssignment,
34333433
init.delegatesFocus ? ShadowRootDelegatesFocus::Yes : ShadowRootDelegatesFocus::No,
34343434
init.clonable ? ShadowRoot::Clonable::Yes : ShadowRoot::Clonable::No,

0 commit comments

Comments
 (0)