Skip to content

Commit 2870b4a

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 2870b4a

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

dom.bs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,9 +908,14 @@ 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+
911916
[Exposed=*]
912917
interface EventTarget {
913-
constructor();
918+
constructor(optional EventTargetCallback cb);
914919

915920
undefined addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options = {});
916921
undefined removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options = {});
@@ -930,6 +935,8 @@ dictionary AddEventListenerOptions : EventListenerOptions {
930935
boolean once = false;
931936
AbortSignal signal;
932937
};
938+
939+
callback EventTargetCallback = undefined (EventTargetInternals internals);
933940
</pre>
934941

935942
<p>An {{EventTarget}} object represents a target to which an <a>event</a> can be <a>dispatched</a>
@@ -939,6 +946,26 @@ 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+
952+
<p>The <dfn export for=Event id=concept-eventtarget-constructor>new EventTarget(cb)</dfn> constructor steps are:
953+
954+
<ol>
955+
<li><p>If <var>cb</var> is not null then:
956+
957+
<ol>
958+
<li><p>Let <var>eventTargetInternals</var> a new {{EventTargetInternals}} instance.
959+
960+
<li><a for=/invoke-a-callback-function>invoke</a> <var>cb</var> with «
961+
<var>eventTargetInternals</var> » and with <var>eventTarget</var> as the <a>callback this
962+
value</a>.
963+
964+
<li><p>Set <var>this</var>'s {{Eventtarget/attached internals}} to
965+
<var>eventTargetInternals</var>.
966+
</ol>
967+
</ol>
968+
942969
<p>An <dfn export id=concept-event-listener>event listener</dfn> can be used to observe a specific
943970
<a>event</a> and consists of:
944971

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

958985
<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.
986+
which takes an <a>event</a> <var>event</var>, and returns an {{EventTarget}}. Unless otherwise
987+
specified otherwise it returns the associated <a for=EventTarget>attached internals</a><a
988+
for=EventTargetInternals">parent</a> attribute.
961989

962990
<p class=note><a for=/>Nodes</a>, <a for=/>shadow roots</a>, and <a>documents</a>
963991
override the <a>get the parent</a> algorithm.
@@ -1322,6 +1350,9 @@ property of the event being dispatched.
13221350
<p>While <var>parent</var> is non-null:</p>
13231351

13241352
<ol>
1353+
<li>If the <var>event</var>'s <a for=Event>path</a> <a for=/>contains</a> <var>parent</var> then <a>throw</a> a
1354+
"{{HierarchyRequestError!!exception}}" {{DOMException}}.
1355+
13251356
<li>
13261357
<p>If <var>slottable</var> is non-null:
13271358

0 commit comments

Comments
 (0)