Skip to content

Commit 7a48d64

Browse files
jungkeesannevk
authored andcommitted
Change add/remove event listener behavior for service workers
This changes addEventListener() and removeEventListener() to not throw even after the very first evalution of the service worker script. Instead, this specifies user agents have to show a console warning. Related: w3c/ServiceWorker#1004 and w3c/ServiceWorker#1322. Tests: web-platform-tests/wpt#19496. Fixes #371.
1 parent 57512fa commit 7a48d64

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

dom.bs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,16 +1150,13 @@ participate in a tree structure.</p>
11501150
and an <a>event listener</a> <var>listener</var>, run these steps:
11511151

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

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

@@ -1189,30 +1186,35 @@ method, when invoked, must run these steps:
11891186
<var>once</var>.
11901187
</ol>
11911188

1192-
<p>To <dfn>remove an event listener</dfn>, given an {{EventTarget}} object <var>eventTarget</var>
1193-
and an <a>event listener</a> <var>listener</var>, set <var>listener</var>'s
1194-
<a for="event listener">removed</a> to true and <a for=list>remove</a> <var>listener</var> from
1195-
<var>eventTarget</var>'s <a for=EventTarget>event listener list</a>.
1196-
<!-- Intentionally not exported. -->
1189+
<p>To <dfn export>remove an event listener</dfn>, given an {{EventTarget}} object
1190+
<var>eventTarget</var> and an <a>event listener</a> <var>listener</var>, run these steps:
1191+
1192+
<ol>
1193+
<li><p>If the <a>context object</a> is a {{ServiceWorkerGlobalScope}} object and its
1194+
<a for="ServiceWorkerGlobalScope">service worker</a>'s
1195+
<a for="service worker">set of event types to handle</a> contains <var>type</var>, then
1196+
<a>report a warning to the console</a> that this might not give the expected results.
1197+
[[!SERVICE-WORKERS]]
1198+
1199+
<li><p>Set <var>listener</var>'s <a for="event listener">removed</a> to true and
1200+
<a for=list>remove</a> <var>listener</var> from <var>eventTarget</var>'s
1201+
<a for=EventTarget>event listener list</a>.
1202+
</ol>
1203+
1204+
<p class=note>HTML needs this to define event handlers. [[HTML]]
11971205

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

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

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

12091217
<ol>
1210-
<li><p>If the <a>context object</a>'s <a>relevant global object</a> is a
1211-
{{ServiceWorkerGlobalScope}} object and its associated <a>service worker</a>'s
1212-
<a for="service worker">script resource</a>'s
1213-
<a for="script resource">has ever been evaluated flag</a> is set, then <a>throw</a> a
1214-
<code>TypeError</code>. [[!SERVICE-WORKERS]]
1215-
12161218
<li><p>Let <var>capture</var> be the result of <a>flattening</a> <var>options</var>.
12171219

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

0 commit comments

Comments
 (0)