Skip to content
Permalink
Browse files

Fix onbeforeunload event handler processing

There are two particular fixes:

* null should *not* cancel the event. This has been flipped ever since
  it was introduced in 7612afe. It
  appears the mistake occurred between
  https://www.w3.org/Bugs/Public/show_bug.cgi?id=19713#c11 (includes
  "not") and https://www.w3.org/Bugs/Public/show_bug.cgi?id=19713#c12
  (which elides it).
* Only applies the special behavior to BeforeUnloadEvents, not to any
  Event with the name "beforeunload". This is especially important since
  such events could be non-cancelable, in which case the previous text
  could potentially cancel them anyway.

This also modernizes the surrounding section, style-wise.

Fixes #2297.
  • Loading branch information...
domenic committed Feb 14, 2017
1 parent 0ca0377 commit fb7e621eab8a437df7ac524e547e31e117b7fce5
Showing with 23 additions and 18 deletions.
  1. +23 −18 source
41 source
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#eventtarget-legacy-canceled-activation-behavior">legacy-canceled-activation behavior</dfn> hook</li>
<li>The <dfn data-x="creating an event" data-x-href="https://dom.spec.whatwg.org/#concept-event-create">create an event</dfn> algorithm</li>
<li>The <dfn data-x="concept-event-fire" data-x-href="https://dom.spec.whatwg.org/#concept-event-fire">fire an event</dfn> algorithm</li>
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#canceled-flag">canceled flag</dfn></li>
<li>The <dfn data-x="concept-event-dispatch" data-x-href="https://dom.spec.whatwg.org/#concept-event-dispatch">dispatch</dfn> algorithm</li>
<li><dfn data-x-href="https://dom.spec.whatwg.org/#dictdef-eventinit"><code>EventInit</code></dfn> dictionary type</li>
<li><dfn data-x="dom-Event-type" data-x-href="https://dom.spec.whatwg.org/#dom-event-type"><code>type</code></dfn> attribute</li>

<dl class="switch">

<dt>If the event type is <code data-x="event-mouseover">mouseover</code></dt>
<dt>If the event type is <code data-x="event-error">error</code> and <var>E</var> is an <code>ErrorEvent</code> object</dt>

<dd><p>If <var>return value</var> is a Web IDL boolean true value, then cancel the event.</p></dd>


<dt>If the event type is <code data-x="event-beforeunload">beforeunload</code></dt>
<dt>If <var>E</var>'s <code data-x="dom-event-type">type</code> is <code
data-x="event-mouseover">mouseover</code></dt>
<dt>If <var>E</var>'s <code data-x="dom-event-type">type</code> is <code
data-x="event-error">error</code> and <var>E</var> is an <code>ErrorEvent</code> object</dt>
<dd><p>If <var>return value</var> is true, then set <var>E</var>'s <span>canceled
flag</span>.</p></dd>

<dt>If <var>E</var>'s <code data-x="dom-event-type">type</code> is <code
data-x="event-beforeunload">beforeunload</code> and <var>E</var> is a
<code>BeforeUnloadEvent</code> object</dt>
<dd>

<p class="note">The <span data-x="event handler IDL attributes">event handler IDL
attribute</span>'s type is <code>OnBeforeUnloadEventHandler</code>, and the <var>return value</var> will therefore have been coerced into either the value null or a
DOMString.</p>
attribute</span>'s type is <code>OnBeforeUnloadEventHandler</code>, and the <var>return
value</var> will therefore have been coerced into either the value null or a <code
data-x="idl-DOMString">DOMString</code>.</p>

<p>If the <var>return value</var> is null, then cancel the event.</p>
<p>If <var>return value</var> is not null, then:</p>

<p>Otherwise, If the <code>Event</code> object <var>E</var> is a
<code>BeforeUnloadEvent</code> object, and the <code>Event</code> object <var>E</var>'s <code data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code>
attribute's value is the empty string, then set the <code
data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code> attribute's value to <var>return value</var>.</p>
<ol>
<li><p>Set <var>E</var>'s <span>canceled flag</span>.</p></li>

<li><p>If <var>E</var>'s <code data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code>
attribute's value is the empty string, then set <var>E</var>'s <code
data-x="dom-BeforeUnloadEvent-returnValue">returnValue</code> attribute's value to
<var>return value</var>.</p></li>
</ol>
</dd>

<dt>Otherwise</dt>

<dd><p>If <var>return value</var> is a Web IDL boolean false value, then cancel the
event.</p></dd>
<dd><p>If <var>return value</var> is false, then set <var>E</var>'s <span>canceled
flag</span>.</p></dd>

<!-- IE actually uncancels the event if the function returns true -->

0 comments on commit fb7e621

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