Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change add/remove event listener behavior for service workers #653

Merged
46 changes: 24 additions & 22 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,16 +1150,13 @@ participate in a tree structure.</p>
and an <a>event listener</a> <var>listener</var>, run these steps:

<ol>
<li>
<p>If <var>eventTarget</var>'s <a>relevant global object</a> is a {{ServiceWorkerGlobalScope}}
object and its associated <a>service worker</a>'s <a for="service worker">script resource</a>'s
<a for="script resource">has ever been evaluated flag</a> is set, then <a>throw</a> a
<code>TypeError</code>.
[[!SERVICE-WORKERS]]

<p class="note no-backref">To optimize storing the event types allowed for the service worker and
to avoid non-deterministic changes to the event listeners, invocation of the method is allowed
only during the very first evaluation of the service worker script.
<li><p>If <var>eventTarget</var> is a {{ServiceWorkerGlobalScope}} object, its
<a for="ServiceWorkerGlobalScope">service worker</a>'s
<a for="service worker">script resource</a>'s
<a for="script resource">has ever been evaluated flag</a> is set, and <var>listener</var>'s
<a for="event listener">type</a> matches the {{Event/type}} attribute value of any of the
<a>service worker events</a>, then <a>report a warning to the console</a> that this might not give
the expected results. [[!SERVICE-WORKERS]]

<li><p>If <var>listener</var>'s <a for="event listener">callback</a> is null, then return.

Expand Down Expand Up @@ -1189,30 +1186,35 @@ method, when invoked, must run these steps:
<var>once</var>.
</ol>

<p>To <dfn>remove an event listener</dfn>, given an {{EventTarget}} object <var>eventTarget</var>
and an <a>event listener</a> <var>listener</var>, set <var>listener</var>'s
<a for="event listener">removed</a> to true and <a for=list>remove</a> <var>listener</var> from
<var>eventTarget</var>'s <a for=EventTarget>event listener list</a>.
<!-- Intentionally not exported. -->
<p>To <dfn export>remove an event listener</dfn>, given an {{EventTarget}} object
<var>eventTarget</var> and an <a>event listener</a> <var>listener</var>, run these steps:

<ol>
<li><p>If the <a>context object</a> is a {{ServiceWorkerGlobalScope}} object and its
<a for="ServiceWorkerGlobalScope">service worker</a>'s
<a for="service worker">set of event types to handle</a> contains <var>type</var>, then
<a>report a warning to the console</a> that this might not give the expected results.
[[!SERVICE-WORKERS]]
Comment on lines +1196 to +1197
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give the context of what the expected results would be, does leaving a short note along the lines of "Service Workers will still be started after the removal." make sense?


<li><p>Set <var>listener</var>'s <a for="event listener">removed</a> to true and
<a for=list>remove</a> <var>listener</var> from <var>eventTarget</var>'s
<a for=EventTarget>event listener list</a>.
</ol>

<p class=note>HTML needs this to define event handlers. [[HTML]]

<p>To <dfn export>remove all event listeners</dfn>, given an {{EventTarget}} object
<var>eventTarget</var>, <a for=list>for each</a> <var>listener</var> of <var>eventTarget</var>'s
<a for=EventTarget>event listener list</a>, <a>remove an event listener</a> with
<var>eventTarget</var> and <var>listener</var>.

<p class="note">HTML needs this to define <code>document.open()</code>. [[HTML]]
<p class=note>HTML needs this to define <code>document.open()</code>. [[HTML]]

<p>The
<dfn method for=EventTarget><code>removeEventListener(<var>type</var>, <var>callback</var>, <var>options</var>)</code></dfn>
method, when invoked, must run these steps:

<ol>
<li><p>If the <a>context object</a>'s <a>relevant global object</a> is a
{{ServiceWorkerGlobalScope}} object and its associated <a>service worker</a>'s
<a for="service worker">script resource</a>'s
<a for="script resource">has ever been evaluated flag</a> is set, then <a>throw</a> a
<code>TypeError</code>. [[!SERVICE-WORKERS]]

<li><p>Let <var>capture</var> be the result of <a>flattening</a> <var>options</var>.

<li><p>If the <a>context object</a>'s <a for=EventTarget>event listener list</a>
Expand Down