Skip to content

Commit 2ddfe80

Browse files
committed
Scope non-scoped (global) registries to a single document
This preserves existing behavior. We throw exceptions in certain corner cases to give us some wiggle room in the future to change some of this around. Corresponding HTML PR: TODO Tests: web-platform-tests/wpt#53791. Fixes #1390.
1 parent 1b4bd48 commit 2ddfe80

File tree

1 file changed

+74
-9
lines changed

1 file changed

+74
-9
lines changed

dom.bs

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,10 +4920,18 @@ and an optional <a for=/>document</a> <dfn export for="clone a node"><var>docume
49204920

49214921
<dl class=switch>
49224922
<dt>{{Document}}
4923-
<dd><p>Set <var>copy</var>'s <a for=Document>encoding</a>, <a for=Document>content type</a>,
4924-
<a for=Document>URL</a>, <a for=Document>origin</a>, <a for=Document>type</a>,
4925-
<a for=Document>mode</a>, <a for=Document>allow declarative shadow roots</a>, and
4926-
<a for=Document>custom element registry</a> to those of <var>node</var>.
4923+
<dd>
4924+
<ol>
4925+
<li><p>Set <var>copy</var>'s <a for=Document>encoding</a>, <a for=Document>content type</a>,
4926+
<a for=Document>URL</a>, <a for=Document>origin</a>, <a for=Document>type</a>,
4927+
<a for=Document>mode</a>, and <a for=Document>allow declarative shadow roots</a>, to those of
4928+
<var>node</var>.
4929+
4930+
<li><p>If <var>node</var>'s <a for=Document>custom element registry</a>'s
4931+
<a for=CustomElementRegistry>is scoped</a> is true, then set <var>copy</var>'s
4932+
<a for=Document>custom element registry</a> to <var>node</var>'s
4933+
<a for=Document>custom element registry</a>.
4934+
</ol>
49274935

49284936
<dt>{{DocumentType}}
49294937
<dd><p>Set <var>copy</var>'s <a for=DocumentType>name</a>, <a>public ID</a>, and
@@ -5774,6 +5782,7 @@ method steps are to return the <a>list of elements with class names <var>classNa
57745782
<p class=note>The HTML Standard will, e.g., define that for <code>html</code> and the
57755783
<a>HTML namespace</a>, the {{HTMLHtmlElement}} interface is used. [[!HTML]]
57765784

5785+
<div algorithm>
57775786
<p>The
57785787
<dfn method for=Document><code>createElement(<var>localName</var>, <var>options</var>)</code></dfn>
57795788
method steps are:
@@ -5795,7 +5804,9 @@ method steps are:
57955804
<li><p>Return the result of <a>creating an element</a> given <a>this</a>, <var>localName</var>,
57965805
<var>namespace</var>, null, <var>is</var>, true, and <var>registry</var>.
57975806
</ol>
5807+
</div>
57985808

5809+
<div algorithm>
57995810
<p>The <dfn noexport>internal <code>createElementNS</code> steps</dfn>, given <var>document</var>,
58005811
<var>namespace</var>, <var>qualifiedName</var>, and <var>options</var>, are as follows:
58015812

@@ -5811,13 +5822,17 @@ method steps are:
58115822
<var>localName</var>, <var>namespace</var>, <var>prefix</var>, <var>is</var>, true, and
58125823
<var>registry</var>.
58135824
</ol>
5825+
</div>
58145826

5827+
<div algorithm>
58155828
<p>The
58165829
<dfn method for=Document><code>createElementNS(<var>namespace</var>, <var>qualifiedName</var>, <var>options</var>)</code></dfn>
58175830
method steps are to return the result of running the
58185831
<a>internal <code>createElementNS</code> steps</a>, given <a>this</a>, <var>namespace</var>,
58195832
<var>qualifiedName</var>, and <var>options</var>.
5833+
</div>
58205834

5835+
<div algorithm>
58215836
<p>To <dfn>flatten element creation options</dfn>, given a string or {{ElementCreationOptions}}
58225837
dictionary <var>options</var> and a <a for=/>document</a> <var>document</var>:
58235838

@@ -5833,6 +5848,10 @@ dictionary <var>options</var> and a <a for=/>document</a> <var>document</var>:
58335848
<li><p>If <var>options</var>["{{ElementCreationOptions/customElementRegistry}}"]
58345849
<a for=map>exists</a>, then set <var>registry</var> to it.
58355850

5851+
<li><p>If <var>registry</var>'s <a for=CustomElementRegistry>is scoped</a> is false and
5852+
<var>registry</var> is not <var>document</var>'s <a for=Document>custom element registry</a>,
5853+
then <a>throw</a> a "{{NotSupportedError!!exception}}" {{DOMException}}.
5854+
58365855
<li><p>If <var>options</var>["{{ElementCreationOptions/is}}"] <a for=map>exists</a>, then set
58375856
<var>is</var> to it.
58385857

@@ -5848,6 +5867,7 @@ dictionary <var>options</var> and a <a for=/>document</a> <var>document</var>:
58485867

58495868
<p class=note>{{Document/createElement()}} and {{Document/createElementNS()}}'s <var>options</var>
58505869
parameter is allowed to be a string for web compatibility.
5870+
</div>
58515871

58525872
<p>The <dfn method for=Document><code>createDocumentFragment()</code></dfn> method steps are to
58535873
return a new {{DocumentFragment}} <a for=/>node</a> whose <a for=Node>node document</a> is
@@ -5944,6 +5964,10 @@ method steps are:
59445964

59455965
<li><p>If <var>options</var>["{{ImportNodeOptions/customElementRegistry}}"]
59465966
<a for=map>exists</a>, then set <var>registry</var> to it.
5967+
5968+
<li><p>If <var>registry</var>'s <a for=CustomElementRegistry>is scoped</a> is false and
5969+
<var>registry</var> is not <a>this</a>'s <a for=Document>custom element registry</a>, then
5970+
<a>throw</a> a "{{NotSupportedError!!exception}}" {{DOMException}}.
59475971
</ol>
59485972

59495973
<li><p>If <var>registry</var> is null, then set <var>registry</var> to the result of
@@ -5961,6 +5985,7 @@ method steps are:
59615985
algorithm is passed <var>node</var> and <var>oldDocument</var>, as indicated in the <a>adopt</a>
59625986
algorithm.
59635987

5988+
<div algorithm>
59645989
<p>To <dfn export id=concept-node-adopt>adopt</dfn> a <var>node</var> into a <var>document</var>, run
59655990
these steps:
59665991

@@ -5974,16 +5999,44 @@ these steps:
59745999
<p>If <var>document</var> is not <var>oldDocument</var>:
59756000

59766001
<ol>
6002+
<li><p>Let <var>documentRegistry</var> be <var>document</var>'s
6003+
<a for=Document>custom element registry</a>.
6004+
6005+
<li><p>Let <var>documentHasGlobalRegistry</var> be true if <var>documentRegistry</var> is
6006+
non-null and <var>documentRegistry</var>'s <a for=CustomElementRegistry>is scoped</a> is false;
6007+
otherwise false.
6008+
59776009
<li>
59786010
<p>For each <var>inclusiveDescendant</var> in <var>node</var>'s
59796011
<a>shadow-including inclusive descendants</a>:
59806012

59816013
<ol>
59826014
<li><p>Set <var>inclusiveDescendant</var>'s <a for=Node>node document</a> to <var>document</var>.
59836015

5984-
<li><p>If <var>inclusiveDescendant</var> is an <a for=/>element</a>, then set the
5985-
<a for=Node>node document</a> of each <a>attribute</a> in <var>inclusiveDescendant</var>'s
5986-
<a for=Element>attribute list</a> to <var>document</var>.
6016+
<li>
6017+
<p>If <var>inclusiveDescendant</var> is a <a for=/>shadow root</a>:
6018+
6019+
<ol>
6020+
<li><p>If <var>inclusiveDescendant</var>'s <a for=ShadowRoot>custom element registry</a> is
6021+
non-null, <var>inclusiveDescendant</var>'s <a for=ShadowRoot>custom element registry</a>'s
6022+
<a for=CustomElementRegistry>is scoped</a> is false, and <var>documentHasGlobalRegistry</var>
6023+
is true, then set <var>inclusiveDescendant</var>'s
6024+
<a for=ShadowRoot>custom element registry</a> to <var>documentRegistry</var>.
6025+
</ol>
6026+
6027+
<li>
6028+
<p>Otherwise, if <var>inclusiveDescendant</var> is an <a for=/>element</a>:
6029+
6030+
<ol>
6031+
<li><p>Set the <a for=Node>node document</a> of each <a>attribute</a> in
6032+
<var>inclusiveDescendant</var>'s <a for=Element>attribute list</a> to <var>document</var>.
6033+
6034+
<li><p>If <var>inclusiveDescendant</var>'s <a for=Element>custom element registry</a> is
6035+
non-null, <var>inclusiveDescendant</var>'s <a for=Element>custom element registry</a>'s
6036+
<a for=CustomElementRegistry>is scoped</a> is false, and <var>documentHasGlobalRegistry</var>
6037+
is true, then set <var>inclusiveDescendant</var>'s <a for=Element>custom element registry</a>
6038+
to <var>documentRegistry</var>.
6039+
</ol>
59876040
</ol>
59886041

59896042
<li><p>For each <var>inclusiveDescendant</var> in <var>node</var>'s
@@ -5997,7 +6050,9 @@ these steps:
59976050
<a>adopting steps</a> with <var>inclusiveDescendant</var> and <var>oldDocument</var>.
59986051
</ol>
59996052
</ol>
6053+
</div>
60006054

6055+
<div algorithm>
60016056
<p>The <dfn method for=Document><code>adoptNode(<var>node</var>)</code></dfn> method steps are:
60026057

60036058
<ol>
@@ -6014,6 +6069,7 @@ these steps:
60146069

60156070
<li><p>Return <var>node</var>.
60166071
</ol>
6072+
</div>
60176073

60186074
<hr>
60196075

@@ -7515,8 +7571,17 @@ are:
75157571
<ol>
75167572
<li><p>Let <var>registry</var> be <a>this</a>'s <a for=Element>custom element registry</a>.
75177573

7518-
<li><p>If <var>init</var>["{{ShadowRootInit/customElementRegistry}}"] is non-null, then set
7519-
<var>registry</var> to it.
7574+
<li>
7575+
<p>If <var>init</var>["{{ShadowRootInit/customElementRegistry}}"] is non-null:
7576+
7577+
<ol>
7578+
<li><p>Set <var>registry</var> to <var>init</var>["{{ShadowRootInit/customElementRegistry}}"].
7579+
7580+
<li><p>If <var>registry</var>'s <a for=CustomElementRegistry>is scoped</a> is false and
7581+
<var>registry</var> is not <a>this</a>'s <a>node document</a>'s
7582+
<a for=Document>custom element registry</a>, then <a>throw</a> a
7583+
"{{NotSupportedError!!exception}}" {{DOMException}}.
7584+
</ol>
75207585

75217586
<li><p>Run <a>attach a shadow root</a> with <a>this</a>,
75227587
<var>init</var>["{{ShadowRootInit/mode}}"], <var>init</var>["{{ShadowRootInit/clonable}}"],

0 commit comments

Comments
 (0)