Skip to content

Commit

Permalink
Revise event listener removal in document.open()
Browse files Browse the repository at this point in the history
This change aligns the event listener removal behavior with
implementations, specifically in two aspects:

- The event handler's value should be set to null (i.e., deactivated).
- Event listeners and handlers should be removed from the Window object
  as well.

See prior investigation around deactivation of event handlers in whatwg#3836
and whatwg#3850. See investigation around document.open()'s behavior in
whatwg#3818.

Tests: web-platform-tests/wpt#12122
  • Loading branch information
TimothyGu authored and mustaqahmed committed Feb 15, 2019
1 parent 803befd commit f154614
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -89947,8 +89947,7 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {

<p>To <dfn>deactivate an event handler</dfn> given an <code>EventTarget</code> object
<var>eventTarget</var> and a string <var>name</var> that is the <span data-x="event handler
name">name</span> of an <span data-x="event handlers">event handler</span>, take the following
steps:</p>
name">name</span> of an <span data-x="event handlers">event handler</span>, run these steps:</p>

<ol>
<li><p>Let <var>handlerMap</var> be <var>eventTarget</var>'s <span>event handler
Expand All @@ -89969,10 +89968,24 @@ dictionary <dfn>PromiseRejectionEventInit</dfn> : <span>EventInit</span> {
null.</p></li>
</ol>

<p>To <dfn>erase all event listeners and handlers</dfn> given an <code>EventTarget</code> object
<var>eventTarget</var>, run these steps:</p>

<ol>
<li><p>If <var>eventTarget</var> has an associated <span>event handler map</span>, then for each
<var>name</var> → <var>eventHandler</var> of <var>eventTarget</var>'s associated <span>event
handler map</span>, <span>deactivate an event handler</span> given <var>eventTarget</var> and
<var>name</var>.</p></li>

<li><p><span>Remove all event listeners</span> given <var>eventTarget</var>.</p></li>
</ol>

<p class="note">This algorithm is used to define <code
data-x="dom-document-open">document.open(<var>type</var>, <var>replace</var>)</code>.</p>

<p>To <dfn>activate an event handler</dfn> given an <code>EventTarget</code> object
<var>eventTarget</var> and a string <var>name</var> that is the <span data-x="event handler
name">name</span> of an <span data-x="event handlers">event handler</span>, take the following
steps:</p>
name">name</span> of an <span data-x="event handlers">event handler</span>, run these steps:</p>

<ol>
<li><p>Let <var>handlerMap</var> be <var>eventTarget</var>'s <span>event handler
Expand Down Expand Up @@ -90987,6 +91000,9 @@ document.body.appendChild(frame)</code></pre>
<li><p>If <var>document</var> is not an <span>active document</span>, then return
<var>document</var>.</p></li>

<li><p>Let <var>window</var> be <var>document</var>'s <span
data-x="concept-relevant-global">relevant global object</span>.</p></li>

<li><p>If <var>document</var>'s <span>origin</span> is not <span>same origin</span> to the
<span>origin</span> of the <span>responsible document</span> specified by the <span>entry
settings object</span>, then throw a <span>"<code>SecurityError</code>"</span>
Expand Down Expand Up @@ -91041,7 +91057,10 @@ document.body.appendChild(frame)</code></pre>
<li><p><span data-x="abort a document">Abort</span> <var>document</var>.</p></li>

<li><p>For each <span>shadow-including inclusive descendant</span> <var>node</var> of
<var>document</var>, <span>remove all event listeners</span> with <var>node</var>.</p></li>
<var>document</var>, <span>erase all event listeners and handlers</span> given
<var>node</var>.</p></li>

<li><p><span>Erase all event listeners and handlers</span> given <var>window</var>.</p></li>

<li><p>Remove any <span data-x="concept-task">tasks</span> associated with <var>document</var> in
any <span>task source</span>.</p></li>
Expand All @@ -91056,8 +91075,8 @@ document.body.appendChild(frame)</code></pre>
realm</span> with the following customizations:</p>

<ul>
<li><p>For the global object, create a new <code>Window</code> object
<var>window</var>.</p></li>
<li><p>For the global object, create a new <code>Window</code> object and set
<var>window</var> to it.</p></li>

<li><p>For the global <b>this</b> binding, use <var>document</var>'s <span>browsing
context</span>'s associated <code>WindowProxy</code>.</p></li>
Expand Down

0 comments on commit f154614

Please sign in to comment.