Skip to content

Commit 652ef26

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 652ef26

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

dom.bs

Lines changed: 46 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,34 @@ 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
969+
value</a>.
970+
971+
<li><p>Set <var>eventTarget</var>'s {{Eventtarget/attached internals}} attribute to
972+
<var>eventTargetInternals</var>.
973+
974+
<li><p>Return <var>eventTarget</var>.
975+
</ol>
976+
942977
<p>An <dfn export id=concept-event-listener>event listener</dfn> can be used to observe a specific
943978
<a>event</a> and consists of:
944979

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

958993
<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.
994+
which takes an <a>event</a> <var>event</var>, and returns an {{EventTarget}}. Unless otherwise
995+
specified otherwise it returns the associated <a for=EventTarget>attached internals</a><a
996+
for=EventTargetInternals">parent</a> attribute.
961997

962998
<p class=note><a for=/>Nodes</a>, <a for=/>shadow roots</a>, and <a>documents</a>
963999
override the <a>get the parent</a> algorithm.
@@ -1296,6 +1332,8 @@ property of the event being dispatched.
12961332
<ol>
12971333
<li><p>Let <var>touchTargets</var> be a new <a for=/>list</a>.
12981334

1335+
<li><p>Let <var>parentTargets</var> be a new <a for=/>list</a>.
1336+
12991337
<li><p><a for=list>For each</a> <var>touchTarget</var> of <var>event</var>'s
13001338
<a for=Event>touch target list</a>, <a for=list>append</a> the result of <a>retargeting</a>
13011339
<var>touchTarget</var> against <var>target</var> to <var>touchTargets</var>.
@@ -1322,6 +1360,11 @@ property of the event being dispatched.
13221360
<p>While <var>parent</var> is non-null:</p>
13231361

13241362
<ol>
1363+
<li>If <var>parentTargets</var> <a for=/>contains</a> <var>parent</var> then <a>throw</a> a
1364+
"{{HierarchyRequestError!!exception}}" {{DOMException}}.
1365+
1366+
<li>Append <var>parent</var> to <var>parentTargets</var>.
1367+
13251368
<li>
13261369
<p>If <var>slottable</var> is non-null:
13271370

0 commit comments

Comments
 (0)