Skip to content

Commit 8de9564

Browse files
committed
Allow for customisation of the "get the parent" algorithm
This modifies the EventTarget IDL to allow assignment of a parent EventTarget to an EventTarget instance, while also modifying the "get the parent" algorithm to default to returning that instance. It also modifies the Event Dispatch algorithm to ensure that custom parent chains cannot cause loops.
1 parent 3bddf91 commit 8de9564

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

dom.bs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,9 +908,16 @@ for historical reasons.
908908
<h3 id=interface-eventtarget>Interface {{EventTarget}}</h3>
909909

910910
<pre class=idl>
911+
[Exposed=*]
912+
interface EventTargetInternals {
913+
attribute EventTarget parent;
914+
}
915+
916+
callback EventTargetCallback = undefined (EventTargetInternals internals);
917+
911918
[Exposed=*]
912919
interface EventTarget {
913-
constructor();
920+
constructor(optional EventTargetCallback cb);
914921

915922
undefined addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options = {});
916923
undefined removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options = {});
@@ -939,6 +946,33 @@ when something has occurred.
939946
<a for=/>list</a> of zero or more <a>event listeners</a>). It is initially the empty list.
940947
<!-- Intentionally not exported. -->
941948

949+
<p>Each {{EventTarget}} object has an associated <dfn for=EventTarget>attached internals</dfn> (null
950+
or an {{EventTargetInternals}} object), initially null.
951+
<!-- Intentionally not exported. -->
952+
953+
<p>When a <dfn export for=Event id=concept-eventtarget-constructor>constructor</dfn> of the {{EventTarget}}
954+
interface, or of an interface that inherits from the {{EventTarget}} interface, is invoked, these steps
955+
must be run, given the arguments <var>eventTargetCallback</var>:
956+
957+
<ol>
958+
<li><p>Let <var>eventTarget</var> be the result of creating a new object using this interface.
959+
960+
<li><p>Initialize <var>eventTarget</var>'s {{EventTarget/event listener list}} attribute to the empty list.
961+
962+
<li><p>Initialize <var>eventTarget</var>'s {{EventTarget/parent}} attribute to null.
963+
964+
<li><p>Let <var>eventTargetInternals</var> a new {{EventTargetInternals}} instance.
965+
966+
<li><p>If <var>eventTargetCallback</var> is not null, then <a
967+
for=/invoke-a-callback-function>invoke</a> <var>eventTargetCallback</var> with «
968+
<var>eventTargetInternals</var> and with <var>eventTarget</var> aas the <a>callback this value</a>.
969+
970+
<li><p>Set <var>eventTarget</var>'s {{Eventtarget/attached internals}} attribute to
971+
<var>eventTargetInternals</var>.
972+
973+
<li><p>Return <var>eventTarget</var>.
974+
</ol>
975+
942976
<p>An <dfn export id=concept-event-listener>event listener</dfn> can be used to observe a specific
943977
<a>event</a> and consists of:
944978

@@ -956,8 +990,9 @@ when something has occurred.
956990
object, an <a>event listener</a> is a broader concept as can be seen above.
957991

958992
<p>Each {{EventTarget}} object also has an associated <dfn export>get the parent</dfn> algorithm,
959-
which takes an <a>event</a> <var>event</var>, and returns an {{EventTarget}} object. Unless
960-
specified otherwise it returns null.
993+
which takes an <a>event</a> <var>event</var>, and returns an {{EventTarget}}. Unless otherwise
994+
specified otherwise it returns the associated <a for=EventTarget>attached internals</a><a
995+
for=EventTargetInternals">parent</a> attribute.
961996

962997
<p class=note><a for=/>Nodes</a>, <a for=/>shadow roots</a>, and <a>documents</a>
963998
override the <a>get the parent</a> algorithm.
@@ -1296,6 +1331,8 @@ property of the event being dispatched.
12961331
<ol>
12971332
<li><p>Let <var>touchTargets</var> be a new <a for=/>list</a>.
12981333

1334+
<li><p>Let <var>parentTargets</var> be a new <a for=/>list</a>.
1335+
12991336
<li><p><a for=list>For each</a> <var>touchTarget</var> of <var>event</var>'s
13001337
<a for=Event>touch target list</a>, <a for=list>append</a> the result of <a>retargeting</a>
13011338
<var>touchTarget</var> against <var>target</var> to <var>touchTargets</var>.
@@ -1322,6 +1359,11 @@ property of the event being dispatched.
13221359
<p>While <var>parent</var> is non-null:</p>
13231360

13241361
<ol>
1362+
<li>If <var>parentTargets</var> <a for=/>contains</a> <var>parent</var> then <a>throw</a> a
1363+
"{{HierarchyRequestError!!exception}}" {{DOMException}}.
1364+
1365+
<li>Append <var>parent</var> to <var>parentTargets</var>.
1366+
13251367
<li>
13261368
<p>If <var>slottable</var> is non-null:
13271369

0 commit comments

Comments
 (0)