From 5d56bb97dc796898cc28b0a54e2ab0454b8f13a6 Mon Sep 17 00:00:00 2001 From: Jungkee Song Date: Tue, 5 Jun 2018 19:59:59 -0700 Subject: [PATCH] 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 that the asynchronously added listener's event type will not affect service worker's behavior with the functional event stored during the first evaluation. This change referneces the funcional event concept defined in Service Workers spec, and confines the EventTarge object of the specified behavior to ServiceWorkerGlobalScope object instead of all the platform object in the global object. Related SW issue: https://github.com/w3c/ServiceWorker/issues/1004. Related SW PR: https://github.com/w3c/ServiceWorker/pull/1322. Fixes https://github.com/whatwg/dom/issues/371. --- dom.bs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/dom.bs b/dom.bs index 2f00ca5ab..56a9e8c2d 100644 --- a/dom.bs +++ b/dom.bs @@ -1062,15 +1062,18 @@ and an event listener listener, run these steps:
  1. -

    If eventTarget's relevant global object is a {{ServiceWorkerGlobalScope}} - object and its associated service worker's script resource's - has ever been evaluated flag is set, then throw a - TypeError. - [[!SERVICE-WORKERS]] - -

    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. +

    If listener observes a functional event, eventTarget is a + {{ServiceWorkerGlobalScope}} object, and its associated service worker's script resource's has ever been evaluated flag is set, + then the user agent must show a message on a developer console that the user agent stores the event + type of the functional event for the service worker only + during the very first evalution of the service worker script, and the asynchronously added + functional event will not start the service worker. [[!SERVICE-WORKERS]] + +

    To optimize storing the event types allowed for the service + worker, Service Workers specification does not store the asynchronously added event type. The event listener will still be added under this condition, + but the implmentations have to inform developers about this behavior.

  2. If listener's callback is null, then return. @@ -1118,11 +1121,13 @@ and an event listener listener, set listener's method, when invoked, must run these steps:

      -
    1. If the context object's relevant global object is a - {{ServiceWorkerGlobalScope}} object and its associated service worker's - script resource's - has ever been evaluated flag is set, then throw a - TypeError. [[!SERVICE-WORKERS]] +

    2. If type is one of the functional events's type, the context object is a {{ServiceWorkerGlobalScope}} object, and its + associated service worker's script resource's has ever been evaluated flag is set, then the user agent must show a message on a + developer console that the user agent will still start the service worker for the + functional event that has been stored during the very first evalution of the service + worker script and is asynchronously removed. [[!SERVICE-WORKERS]]

    3. Let capture be the result of flattening options.