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 10, 2023
1 parent 3bddf91 commit 8de9564
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,16 @@ for historical reasons.
<h3 id=interface-eventtarget>Interface {{EventTarget}}</h3>

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

callback EventTargetCallback = undefined (EventTargetInternals internals);

[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 Down Expand Up @@ -939,6 +946,33 @@ 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>When a <dfn export for=Event id=concept-eventtarget-constructor>constructor</dfn> of the {{EventTarget}}
interface, or of an interface that inherits from the {{EventTarget}} interface, is invoked, these steps
must be run, given the arguments <var>eventTargetCallback</var>:

<ol>
<li><p>Let <var>eventTarget</var> be the result of creating a new object using this interface.

<li><p>Initialize <var>eventTarget</var>'s {{EventTarget/event listener list}} attribute to the empty list.

<li><p>Initialize <var>eventTarget</var>'s {{EventTarget/parent}} attribute to null.

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

<li><p>If <var>eventTargetCallback</var> is not null, then <a
for=/invoke-a-callback-function>invoke</a> <var>eventTargetCallback</var> with «
<var>eventTargetInternals</var> and with <var>eventTarget</var> aas the <a>callback this value</a>.

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

<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 +990,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 @@ -1296,6 +1331,8 @@ property of the event being dispatched.
<ol>
<li><p>Let <var>touchTargets</var> be a new <a for=/>list</a>.

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

<li><p><a for=list>For each</a> <var>touchTarget</var> of <var>event</var>'s
<a for=Event>touch target list</a>, <a for=list>append</a> the result of <a>retargeting</a>
<var>touchTarget</var> against <var>target</var> to <var>touchTargets</var>.
Expand All @@ -1322,6 +1359,11 @@ property of the event being dispatched.
<p>While <var>parent</var> is non-null:</p>

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

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

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

Expand Down

0 comments on commit 8de9564

Please sign in to comment.