Skip to content

Commit 051d86f

Browse files
committed
Make event handlers share a code path with addEventListener()
See whatwg/dom#596 and whatwg/dom#365 and w3c/ServiceWorker#1004 for more context.
1 parent 021a575 commit 051d86f

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

source

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89671,22 +89671,32 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
8967189671

8967289672
<hr>
8967389673

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>
89674+
<p>When an <span data-x="event handlers">event handler</span> <var>H</var> of an
89675+
<code>EventTarget</code> object <var>T</var> is first set to a non-null value, then:
89676+
89677+
<ol>
89678+
<li><p>Let <var>type</var> be the <dfn data-export="">event handler event type</dfn>
89679+
corresponding to <var>H</var>.</p></li>
89680+
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><p><span>Add an event listener</span> with <var>T</var>, <var>type</var>,
89698+
<var>callback</var>, and false.</p></li>
89699+
</ol>
8969089700

8969189701
<p class="note">This only happens the first time the <span data-x="event handlers">event
8969289702
handler</span>'s value is set. Since listeners are called in the order they were registered, the

0 commit comments

Comments
 (0)