Skip to content

Commit

Permalink
Allow for customisation of the "get the parent" algorithm
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
keithamus committed Oct 11, 2023
1 parent 3bddf91 commit 3a8cd2b
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,14 @@ for historical reasons.
<h3 id=interface-eventtarget>Interface {{EventTarget}}</h3>

<pre class=idl>
[Exposed=*]
interface EventTargetInternals {
attribute EventTarget parent;
};

[Exposed=*]
interface EventTarget {
constructor();
constructor(optional EventTargetCallback cb);

undefined addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options = {});
undefined removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options = {});
Expand All @@ -930,6 +935,8 @@ dictionary AddEventListenerOptions : EventListenerOptions {
boolean once = false;
AbortSignal signal;
};

callback EventTargetCallback = undefined (EventTargetInternals internals);
</pre>

<p>An {{EventTarget}} object represents a target to which an <a>event</a> can be <a>dispatched</a>
Expand All @@ -939,6 +946,63 @@ when something has occurred.
<a for=/>list</a> of zero or more <a>event listeners</a>). It is initially the empty list.
<!-- Intentionally not exported. -->

<p>Each {{EventTarget}} object has an associated <dfn for=EventTarget>attached internals</dfn> (null
or an {{EventTargetInternals}} object), initially null.

<p>Each {{EventTargetInternals}} object has an associated <dfn
for=EventTargetInternals>eventTarget</dfn> (an {{EventTarget}} object).

<p>The <dfn export for=Event id=concept-eventtarget-constructor>new EventTarget(cb)</dfn> constructor steps are:

<ol>
<li><p>If <var>cb</var> is not null then:

<ol>
<li><p>Let <var>eventTargetInternals</var> a new {{EventTargetInternals}} instance.

<li><p>Set <var>eventTargetInternals</var>'s <a for=EventTargetInternals>eventTarget</a> to
<var>this</var>.

<li><a>Invoke</a> <var>cb</var> with « <var>eventTargetInternals</var> » and with <var>this</var>
as the <a>callback this value</a>.

<li><p>Set <var>this</var>'s <a for="EventTarget">attached internals</a> to
<var>eventTargetInternals</var>.
</ol>
</ol>

<p>To <dfn export for=Event id=concept-eventtargetinternals-set-parent>set the parent</dfn> given
an {{EventTargetInternals}} <var>internals</var> and {{EventTarget}} <var>theParent</var>:

<ol>
<li><p>Let <var>targets</var> be a new <a for=/>list</a>.

<li>Append <var>internals</var> <a for=EventTargetInternals>eventTarget</a> to <var>targets</var>.

<li><p>Let <var>parent</var> be <var>theParent</var>.

<li>
<p>While <var>parent</var> is non-null:</p>

<ol>
<li>If <var>targets</var> <a for=set>contains</a> <var>parent</var> then <a>throw</a> a
"{{HierarchyRequestError!!exception}}" {{DOMException}}.

<li>Append <var>parent</var> to <var>targets</var>.

<li>Let <var>parentInternals</var> be <var>parent</var>'s <a for=EventTarget>attached internals</a>.

<li>Set <var>parent</var> to <var>parentIntenrals</var>'s <a
for=EventTargetInternals>parent</a>.

</ol>

<li>Set <var>internal</var>'s <a for=EventTargetInternals>eventTarget</a> <a>get the parent</a>
algorithm to return <var>theParent</var>.

<li>Set <var>internal</var>'s {{EventTargetInternals/parent}} to <var>theParent</var>.
</ol>

<p>An <dfn export id=concept-event-listener>event listener</dfn> can be used to observe a specific
<a>event</a> and consists of:

Expand Down Expand Up @@ -1322,6 +1386,9 @@ property of the event being dispatched.
<p>While <var>parent</var> is non-null:</p>

<ol>
<li>If the <var>event</var>'s <a for=Event>path</a> <a for=set>contains</a> <var>parent</var>
then <a>throw</a> a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

<li>
<p>If <var>slottable</var> is non-null:

Expand Down

0 comments on commit 3a8cd2b

Please sign in to comment.