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 f004410
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions 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,29 @@ 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.
<!-- Intentionally not exported. -->

<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><a for=/invoke-a-callback-function>invoke</a> <var>cb</var> with «
<var>eventTargetInternals</var> » and with <var>eventTarget</var> as the <a>callback this
value</a>.

<li><p>Set <var>eventTarget</var>'s {{Eventtarget/attached internals}} to
<var>eventTargetInternals</var>.
</ol>

<li><p>Return <var>eventTarget</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 All @@ -956,8 +986,9 @@ when something has occurred.
object, an <a>event listener</a> is a broader concept as can be seen above.

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

<p class=note><a for=/>Nodes</a>, <a for=/>shadow roots</a>, and <a>documents</a>
override the <a>get the parent</a> algorithm.
Expand Down Expand Up @@ -1322,6 +1353,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=/>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 f004410

Please sign in to comment.