Skip to content
Permalink
Browse files

Fix event handler processing algorithm special cases

This is a follow-up to 7163372, which
forgot about the case of ErrorEvents with a non-"error" event type, or
BeforeUnloadEvents with a non-"beforeunload" event type, as noted in
#2398 (comment).
  • Loading branch information...
domenic committed Mar 15, 2017
1 parent 6db1cba commit c065e991b65e10a1fc77ba77fed9f0822ff6858b
Showing with 27 additions and 22 deletions.
  1. +27 −22 source
49 source

<li><p>If <var>callback</var> is null, then abort these steps.</p></li>

<li>
<p>Let <var>special error event handling</var> be true if <var>E</var> is an
<code>ErrorEvent</code> object and <var>E</var>'s <code
data-x="dom-Event-currentTarget">currentTarget</code> implements the
<code>WindowOrWorkerGlobalScope</code> mixin. Otherwise, let <var>special error event
handling</var> be false.</p>

<p class="note">In this case, <var>E</var>'s <code data-x="dom-Event-type">type</code> will
always be <code data-x="event-error">error</code>, since the only <span data-x="event
handlers">event handler</span> is called with <code>ErrorEvent</code> instances is <code
data-x="handler-onerror">onerror</code>.</p>
</li>
<li><p>Let <var>special error event handling</var> be true if <var>E</var> is an
<code>ErrorEvent</code> object, <var>E</var>'s <code data-x="dom-Event-type">type</code> is <code
data-x="event-error">error</code>, and <var>E</var>'s <code
data-x="dom-Event-currentTarget">currentTarget</code> implements the
<code>WindowOrWorkerGlobalScope</code> mixin. Otherwise, let <var>special error event
handling</var> be false.</p></li>

<li>


<dl class="switch">

<dt>If <var>E</var> is a <code>BeforeUnloadEvent</code> object</dt>
<dt>If <var>E</var> is a <code>BeforeUnloadEvent</code> object and <var>E</var>'s <code
data-x="dom-Event-type">type</code> is <code
data-x="event-beforeunload">beforeunload</code></dt>
<!-- It is possible to get a BeforeUnloadEvent object whose type is not beforeunload via
document.createEvent("beforeunloadevent") + initEvent. This may be removed; see
https://github.com/whatwg/dom/issues/362. But it's still probably a good idea to check both,
just in case e.g. we end up adding a constructor to BeforeUnloadEvent. -->
<dd>
<p class="note">This can only occur when <var>E</var>'s <code
data-x="dom-Event-type">type</code> is <code data-x="event-beforeunload">beforeunload</code>
and when the <span data-x="event handler IDL attributes">event handler IDL attribute</span>'s
type is <code>OnBeforeUnloadEventHandler</code>, since the only <span data-x="event
handlers">event handler</span> that is called with <code>BeforeUnloadEvent</code> instances is
<code data-x="handler-window-onbeforeunload">onbeforeunload</code>. In this case, <var>return
value</var> will therefore have been coerced into either the value null or a <code
<p class="note">In this case, the <span data-x="event handler IDL attributes">event handler
IDL attribute</span>'s type will be <code>OnBeforeUnloadEventHandler</code>, so <var>return
value</var> will have been coerced into either null or a <code
data-x="idl-DOMString">DOMString</code>.</p>

<p>If <var>return value</var> is not null, then:</p>
flag</span>.</p></dd>

<dt>Otherwise</dt>
<dd><p>If <var>return value</var> is false, then set <var>E</var>'s <span>canceled
flag</span>.</p></dd>
<dd>
<p>If <var>return value</var> is false, then set <var>E</var>'s <span>canceled
flag</span>.</p>

<p class="note">If we've gotten to this "Otherwise" clause because <var>E</var>'s <code
data-x="dom-Event-type">type</code> is <code
data-x="event-beforeunload">beforeunload</code> but <var>E</var> is <em>not</em> a
<code>BeforeUnloadEvent</code> object, then <var>return value</var> will never be false, since
in such cases <var>return value</var> will have been coerced into either null or a <code
data-x="idl-DOMString">DOMString</code>.</p>
</dd>

</dl>

0 comments on commit c065e99

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