Skip to content

Make event handlers share a code path with addEventListener() #3561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3183,10 +3183,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x-href="https://dom.spec.whatwg.org/#composed-flag">composed flag</dfn></li>
<li><dfn data-x="dom-Event-isTrusted" data-x-href="https://dom.spec.whatwg.org/#dom-event-istrusted"><code>isTrusted</code></dfn> attribute</li>
<li><dfn data-x="dom-Event-initEvent" data-x-href="https://dom.spec.whatwg.org/#dom-event-initevent"><code>initEvent()</code></dfn> method</li>
<li><dfn data-x-href="https://dom.spec.whatwg.org/#add-an-event-listener">add an event listener</dfn></li>
<li><dfn data-x="dom-EventTarget-addEventListener" data-x-href="https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener"><code>addEventListener()</code></dfn> method</li>
<li><dfn data-x="dom-EventListener" data-x-href="https://dom.spec.whatwg.org/#callbackdef-eventlistener"><code>EventListener</code></dfn> callback interface</li>
<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>
<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>
<li>An <dfn data-x-href="https://dom.spec.whatwg.org/#concept-event-listener">event listener</dfn> and its
<dfn data-x="event listener type" data-x-href="https://dom.spec.whatwg.org/#event-listener-type">type</dfn> and
<dfn data-x="event listener callback" data-x-href="https://dom.spec.whatwg.org/#event-listener-callback">callback</dfn></li>

<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
<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>
Expand Down Expand Up @@ -89671,22 +89674,38 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {

<hr>

<p>When an <span data-x="event handlers">event handler</span> <var>H</var> of an element or object
<var>T</var> implementing the <code>EventTarget</code> interface is first set to a non-null value,
the user agent must append an <span data-x="concept-event-listener">event listener</span> to the
list of <span data-x="concept-event-listener">event listeners</span> associated with <var>T</var>
with <b>type</b> set to the <dfn data-export="">event handler event type</dfn> corresponding to
<var>H</var> and <b>callback</b> set to the result of creating a Web IDL <code
data-x="dom-EventListener">EventListener</code> instance representing a reference to a function of
one argument that executes the steps of <span>the event handler processing algorithm</span>, given
<var>H</var> and its argument. The <code data-x="dom-EventListener">EventListener</code>'s
<span>callback context</span> can be arbitrary; it does not impact the steps of <span>the event
handler processing algorithm</span>. <ref spec=DOM></p>

<p class="note">The <b>callback</b> is emphatically <em>not</em> the <span data-x="event
handlers">event handler</span> itself. Every event handler ends up registering the same
<b>callback</b>, the algorithm defined below, which takes care of invoking the right callback, and
processing the callback's return value.</p>
<p>When an <span data-x="event handlers">event handler</span> <var>H</var> of an
<code>EventTarget</code> object <var>T</var> is first set to a non-null value, then:

<ol>
<li>
<p>Let <var>callback</var> be the result of creating a Web IDL <code
data-x="dom-EventListener">EventListener</code> instance representing a reference to a function
of one argument that executes the steps of <span>the event handler processing algorithm</span>,
given <var>H</var> and its argument.</p>

<p>The <code data-x="dom-EventListener">EventListener</code>'s <span>callback context</span> can
be arbitrary; it does not impact the steps of <span>the event handler processing
algorithm</span>. <ref spec=DOM></p>

<p class="note">The callback is emphatically <em>not</em> the <span data-x="event
handlers">event handler</span> itself. Every event handler ends up registering the same
callback, the algorithm defined below, which takes care of invoking the right callback, and
processing the callback's return value.</p>
</li>

<li>
<p>Let <var>listener</var> be a new <span>event listener</span> whose <span data-x="event
listener type">type</span> is the <dfn data-export="">event handler event type</dfn>
corresponding to <var>H</var> and <span data-x="event listener callback">callback</span> is
<var>callback</var>.</p>

<p class="note">To be clear, an <span>event listener</span> is different from an <code
data-x="dom-EventListener">EventListener</code>.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will get some laughs from future readers :)

</li>

<li><p><span>Add an event listener</span> with <var>T</var> and <var>listener</var>.</p></li>
</ol>

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