Skip to content

Commit

Permalink
Fix event handler processing algorithm special cases
Browse files Browse the repository at this point in the history
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
whatwg#2398 (comment).
  • Loading branch information
domenic authored and Alice Boxhall committed Jan 7, 2019
1 parent 8e297ae commit 31e1254
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -88691,18 +88691,12 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {

<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>

Expand Down Expand Up @@ -88752,15 +88746,17 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {

<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>
Expand All @@ -88780,8 +88776,17 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
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>

Expand Down

0 comments on commit 31e1254

Please sign in to comment.