Skip to content

Commit 601544f

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 601544f

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

dom.bs

+65-1
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,63 @@ 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>Each {{EventTargetInternals}} object has an associated <dfn
953+
for=EventTargetInternals>eventTarget</dfn> (an {{EventTarget}} object).
954+
955+
<p>The <dfn export for=Event id=concept-eventtarget-constructor>new EventTarget(cb)</dfn> constructor steps are:
956+
957+
<ol>
958+
<li><p>If <var>cb</var> is not null then:
959+
960+
<ol>
961+
<li><p>Let <var>eventTargetInternals</var> a new {{EventTargetInternals}} instance.
962+
963+
<li><p>Set <var>eventTargetInternals</var>'s <a for=EventTargetInternals>eventTarget</a> to
964+
<var>this</var>.
965+
966+
<li><a>Invoke</a> <var>cb</var> with « <var>eventTargetInternals</var> » and with <var>this</var>
967+
as the <a>callback this value</a>.
968+
969+
<li><p>Set <var>this</var>'s <a for="EventTarget">attached internals</a> to
970+
<var>eventTargetInternals</var>.
971+
</ol>
972+
</ol>
973+
974+
<p>To <dfn export for=Event id=concept-eventtargetinternals-set-parent>set the parent</dfn> given
975+
an {{EventTargetInternals}} <var>internals</var> and {{EventTarget}} <var>theParent</var>:
976+
977+
<ol>
978+
<li><p>Let <var>targets</var> be a new <a for=/>list</a>.
979+
980+
<li>Append <var>internals</var> <a for=EventTargetInternals>eventTarget</a> to <var>targets</var>.
981+
982+
<li><p>Let <var>parent</var> be <var>theParent</var>.
983+
984+
<li>
985+
<p>While <var>parent</var> is non-null:</p>
986+
987+
<ol>
988+
<li>If <var>targets</var> <a for=set>contains</a> <var>parent</var> then <a>throw</a> a
989+
"{{HierarchyRequestError!!exception}}" {{DOMException}}.
990+
991+
<li>Append <var>parent</var> to <var>targets</var>.
992+
993+
<li>Let <var>parentInternals</var> be <var>parent</var>'s <a for=EventTarget>attached internals</a>.
994+
995+
<li>Set <var>parent</var> to <var>parentInternals</var>'s <a
996+
for=EventTargetInternals>eventTarget</a>.
997+
998+
</ol>
999+
1000+
<li>Set <var>internal</var>'s <a for=EventTargetInternals>eventTarget</a> <a>get the parent</a>
1001+
algorithm to return <var>theParent</var>.
1002+
1003+
<li>Set <var>internal</var>'s {{EventTargetInternals/parent}} to <var>theParent</var>.
1004+
</ol>
1005+
9421006
<p>An <dfn export id=concept-event-listener>event listener</dfn> can be used to observe a specific
9431007
<a>event</a> and consists of:
9441008

0 commit comments

Comments
 (0)