Skip to content

Commit 9a2a66c

Browse files
authored
Make event handlers share a code path with addEventListener()
This hook was provided whatwg/dom#596 and event handlers need to use it to fix whatwg/dom#365 and w3c/ServiceWorker#1004 properly. Tests will be added as part of resolving those issues.
1 parent be2f5df commit 9a2a66c

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

source

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,10 +3183,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
31833183
<li><dfn data-x-href="https://dom.spec.whatwg.org/#composed-flag">composed flag</dfn></li>
31843184
<li><dfn data-x="dom-Event-isTrusted" data-x-href="https://dom.spec.whatwg.org/#dom-event-istrusted"><code>isTrusted</code></dfn> attribute</li>
31853185
<li><dfn data-x="dom-Event-initEvent" data-x-href="https://dom.spec.whatwg.org/#dom-event-initevent"><code>initEvent()</code></dfn> method</li>
3186+
<li><dfn data-x-href="https://dom.spec.whatwg.org/#add-an-event-listener">add an event listener</dfn></li>
31863187
<li><dfn data-x="dom-EventTarget-addEventListener" data-x-href="https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener"><code>addEventListener()</code></dfn> method</li>
31873188
<li><dfn data-x="dom-EventListener" data-x-href="https://dom.spec.whatwg.org/#callbackdef-eventlistener"><code>EventListener</code></dfn> callback interface</li>
31883189
<li>The <dfn data-x="concept-event-type" data-x-href="https://dom.spec.whatwg.org/#dom-event-type">type</dfn> of an event</li>
3189-
<li>The concept of an <dfn data-x="concept-event-listener" data-x-href="https://dom.spec.whatwg.org/#concept-event-listener">event listener</dfn> and the <span data-x="concept-event-listener">event listeners</span> associated with an <code>EventTarget</code></li>
3190+
<li>An <dfn data-x-href="https://dom.spec.whatwg.org/#concept-event-listener">event listener</dfn> and its
3191+
<dfn data-x="event listener type" data-x-href="https://dom.spec.whatwg.org/#event-listener-type">type</dfn> and
3192+
<dfn data-x="event listener callback" data-x-href="https://dom.spec.whatwg.org/#event-listener-callback">callback</dfn></li>
31903193

31913194
<li>The <dfn data-x="document's character encoding" data-x-href="https://dom.spec.whatwg.org/#concept-document-encoding">encoding</dfn> (herein the <i>character encoding</i>) and
31923195
<dfn data-x="concept-document-content-type" data-x-href="https://dom.spec.whatwg.org/#concept-document-content-type">content type</dfn> of a <code>Document</code></li>
@@ -89671,22 +89674,38 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
8967189674

8967289675
<hr>
8967389676

89674-
<p>When an <span data-x="event handlers">event handler</span> <var>H</var> of an element or object
89675-
<var>T</var> implementing the <code>EventTarget</code> interface is first set to a non-null value,
89676-
the user agent must append an <span data-x="concept-event-listener">event listener</span> to the
89677-
list of <span data-x="concept-event-listener">event listeners</span> associated with <var>T</var>
89678-
with <b>type</b> set to the <dfn data-export="">event handler event type</dfn> corresponding to
89679-
<var>H</var> and <b>callback</b> set to the result of creating a Web IDL <code
89680-
data-x="dom-EventListener">EventListener</code> instance representing a reference to a function of
89681-
one argument that executes the steps of <span>the event handler processing algorithm</span>, given
89682-
<var>H</var> and its argument. The <code data-x="dom-EventListener">EventListener</code>'s
89683-
<span>callback context</span> can be arbitrary; it does not impact the steps of <span>the event
89684-
handler processing algorithm</span>. <ref spec=DOM></p>
89685-
89686-
<p class="note">The <b>callback</b> is emphatically <em>not</em> the <span data-x="event
89687-
handlers">event handler</span> itself. Every event handler ends up registering the same
89688-
<b>callback</b>, the algorithm defined below, which takes care of invoking the right callback, and
89689-
processing the callback's return value.</p>
89677+
<p>When an <span data-x="event handlers">event handler</span> <var>H</var> of an
89678+
<code>EventTarget</code> object <var>T</var> is first set to a non-null value, then:
89679+
89680+
<ol>
89681+
<li>
89682+
<p>Let <var>callback</var> be the result of creating a Web IDL <code
89683+
data-x="dom-EventListener">EventListener</code> instance representing a reference to a function
89684+
of one argument that executes the steps of <span>the event handler processing algorithm</span>,
89685+
given <var>H</var> and its argument.</p>
89686+
89687+
<p>The <code data-x="dom-EventListener">EventListener</code>'s <span>callback context</span> can
89688+
be arbitrary; it does not impact the steps of <span>the event handler processing
89689+
algorithm</span>. <ref spec=DOM></p>
89690+
89691+
<p class="note">The callback is emphatically <em>not</em> the <span data-x="event
89692+
handlers">event handler</span> itself. Every event handler ends up registering the same
89693+
callback, the algorithm defined below, which takes care of invoking the right callback, and
89694+
processing the callback's return value.</p>
89695+
</li>
89696+
89697+
<li>
89698+
<p>Let <var>listener</var> be a new <span>event listener</span> whose <span data-x="event
89699+
listener type">type</span> is the <dfn data-export="">event handler event type</dfn>
89700+
corresponding to <var>H</var> and <span data-x="event listener callback">callback</span> is
89701+
<var>callback</var>.</p>
89702+
89703+
<p class="note">To be clear, an <span>event listener</span> is different from an <code
89704+
data-x="dom-EventListener">EventListener</code>.</p>
89705+
</li>
89706+
89707+
<li><p><span>Add an event listener</span> with <var>T</var> and <var>listener</var>.</p></li>
89708+
</ol>
8969089709

8969189710
<p class="note">This only happens the first time the <span data-x="event handlers">event
8969289711
handler</span>'s value is set. Since listeners are called in the order they were registered, the
@@ -120779,6 +120798,7 @@ INSERT INTERFACES HERE
120779120798
Carlos Gabriel Cardona,
120780120799
Carlos Perell&oacute; Mar&iacute;n,
120781120800
Casey Leask,
120801+
Cătălin Badea,
120782120802
C&#x103;t&#x103;lin Mari&#x219;,
120783120803
Chao Cai,
120784120804
&#xc724;&#xc11d;&#xcc2c; (Channy Yun),

0 commit comments

Comments
 (0)