Re: [whatwg/dom] Change add/remove event listener behavior for service workers (#653)

jakearchibald commented on this pull request.



> @@ -1062,15 +1062,19 @@ 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.
+  <p>If <var>listener</var> observes a <a>functional event</a>, <var>eventTarget</var> is a

Feels clearer to say "If listener's type is…" then link to the list https://w3c.github.io/ServiceWorker/#execution-context-events.


Right now "observes" is a little vague, and "functional event" doesn't cover the lifecycle events.

> @@ -1062,15 +1062,19 @@ 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.
+  <p>If <var>listener</var> observes a <a>functional event</a>, <var>eventTarget</var> 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 the user agent must <a>report a warning to the console</a> with a description that explains
+  that the user agent stores the event <a for="event listener">type</a> of the <a>functional
+  event</a> for the <a>service worker</a> only during the very first evalution of the <a>service

Should the explanation be developer-focused here?

If so:

…the user agent must report a warning to the console explaining that an event with a type of listener's type should be added synchronously, otherwise, then the service worker restarts, events of this type will be dispatched before the listener is added.

> -  <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.
+  <p>If <var>listener</var> observes a <a>functional event</a>, <var>eventTarget</var> 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 the user agent must <a>report a warning to the console</a> with a description that explains
+  that the user agent stores the event <a for="event listener">type</a> of the <a>functional
+  event</a> for the <a>service worker</a> only during the very first evalution of the <a>service
+  worker</a> script, and the asynchronously added <a>functional event</a> will not start the
+  <a>service worker</a>. [[!SERVICE-WORKERS]]
+
+  <p class="note no-backref">To optimize storing the event types allowed for the <a>service
+  worker</a>, Service Workers specification does not store the asynchronously added event <a
+  for="event listener">type</a>. The <a>event listener</a> will still be added under this condition,
+  but the implmentations have to inform developers about this behavior.

We might not need this note if the developer-facing explanation is clear enough.

> @@ -1118,11 +1122,13 @@ and an <a>event listener</a> <var>listener</var>, set <var>listener</var>'s
 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>If <var>type</var> is one of the <a>functional events</a>'s <a for="event
+ listener">type</a>, the <a>context 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 the user agent must <a>report a warning to
+ the console</a> with a description that explains that the user agent will still start the
+ <a>service worker</a> for the <a>functional event</a> that has been stored during the very first
+ evalution of the <a>service worker</a> script and is asynchronously removed. [[!SERVICE-WORKERS]]

(any changes to addEventListener should also be made here)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/653#pullrequestreview-264136809

Received on Friday, 19 July 2019 10:55:25 UTC