Skip to content
This repository was archived by the owner on Jul 30, 2022. It is now read-only.

Commit 6340382

Browse files
mfreed7moz-wptsync-bot
authored andcommitted
Bug 1665215 [wpt PR 25554] - Deny ElementInternals.shadowRoot for pre-created shadow roots, a=testonly
Automatic update from web-platform-tests Deny ElementInternals.shadowRoot for pre-created shadow roots Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <[email protected]> Auto-Submit: Mason Freed <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Cr-Commit-Position: refs/heads/master@{#807311} -- wpt-commits: 8e3392df536283e843589c176ffbc7e00e94e64e wpt-pr: 25554
1 parent 3a5e945 commit 6340382

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

testing/web-platform/tests/shadow-dom/declarative/element-internals-shadowroot.tentative.html

+19-2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@
108108
assert_throws_dom('NotSupportedError', () => element.attachInternals(), 'attachInternals forbidden by disabledFeatures, post-upgrade');
109109
}, 'ElementInternals disabled by disabledFeatures');
110110

111-
112-
111+
test(() => {
112+
let constructed = false;
113+
const element = document.createElement('x-6');
114+
const sr = element.attachShadow({mode: 'closed'});
115+
assert_true(sr instanceof ShadowRoot);
116+
customElements.define('x-6', class extends HTMLElement {
117+
constructor() {
118+
super();
119+
assert_throws_dom('NotSupportedError', () => this.attachShadow({mode:'open'}), 'attachShadow already called');
120+
const elementInternals = this.attachInternals();
121+
assert_equals(elementInternals.shadowRoot, null, 'ElementInternals.shadowRoot should not be available for pre-attached shadow');
122+
constructed = true;
123+
}
124+
});
125+
assert_false(constructed);
126+
customElements.upgrade(element);
127+
assert_true(constructed,'Failed to construct - test failed');
128+
assert_equals(element.shadowRoot, null, 'shadow root is closed');
129+
}, 'ElementInternals.shadowRoot doesn\'t reveal pre-attached closed shadowRoot');
113130
</script>

0 commit comments

Comments
 (0)