Skip to content
Permalink
Browse files

Fix event callback invocation to set entry/incumbent correctly

This fixes #2248 by ensuring that we convert the created JavaScript
Function object to a Web IDL callback, with the appropriate callback
context.

While in the area, it also straightens out and clarifies some confusion
around what exactly the event listener's "callback" is; it is now always
a Web IDL callback, instead of sometimes being just an algorithm.

It also adds a clarifying note as to why we go through the JavaScript
stack-pushing steps.

Tests: web-platform-tests/wpt#4988
  • Loading branch information...
domenic committed Feb 24, 2017
1 parent 8644ad9 commit 037f35d4a114d5543d5caa17689cbe1b095790cf
Showing with 27 additions and 14 deletions.
  1. +27 −14 source
41 source
<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="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>


<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 <span>the event handler
processing algorithm</span> defined below. <ref spec=DOM></p>
<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
<p>If <var>H</var> is an element's <span data-x="event handlers">event
handler</span>, then let <var>element</var> be the element, and <var>document</var> be the element's <span>node document</span>.</p>

<p>Otherwise, <var>H</var> is a <code>Window</code> object's <span data-x="event
handlers">event handler</span>: let <var>element</var> be null, and let <var>document</var> be the <code>Document</code> most recently associated with that
<code>Window</code> object.</p>
<p>Otherwise, <var>H</var> is a <code>Window</code> object's <span data-x="event handlers">event handler</span>:
let <var>element</var> be null, and let <var>document</var> be <var>H</var>'s <span
data-x="concept-document-window">associated <code>Document</code></span>.</p>

</li>


</li>

<li><p>Push <var>settings object</var>'s <span>realm execution context</span> onto the
<span>JavaScript execution context stack</span>; it is now the <span>running JavaScript
execution context</span>.</p></li>
<li>
<p>Push <var>settings object</var>'s <span>realm execution context</span> onto the
<span>JavaScript execution context stack</span>; it is now the <span>running JavaScript
execution context</span>.</p>

<p class="note">This is necessary so the subsequent invocation of <span
data-x="js-FunctionCreate">FunctionCreate</span> takes place in the correct <span>JavaScript
Realm</span>.</p>
</li>

<li>

<span>JavaScript execution context stack</span>.</p></li>

<!-- SCRIPT EXEC, sorta -->
<li><p>Set <var>H</var>'s value to <var>function</var>.</p></li>
<li><p>Set <var>H</var>'s value to the result of creating a Web IDL callback function whose
object reference is <var>function</var> and whose <span>callback context</span> is
<var>settings object</var>.</p></li>

</ol>

0 comments on commit 037f35d

Please sign in to comment.
You can’t perform that action at this time.