Re: [whatwg/dom] Nerfing all events on all event targets in a serviceworker after initial script evaluation seems odd (#371)

> I have no idea what "spin off" means here. Again, no idea what "run" means here.

That is [Run Service Worker](https://w3c.github.io/ServiceWorker/#run-service-worker-algorithm) the only call sites of which are SW Update/Install/Active, Handle Fetch, Handle Functional Event, and postMessage to SW.

>  This isn't how the precedent in the platform for this (XHR upload events) works...

As @annevk noted, SW already does this (but with the _has ever been evaluated flag_ constraint): [Run Service Worker](https://w3c.github.io/ServiceWorker/#run-service-worker-algorithm) step 15.

> That has precisely 0 discussion about the throwing behavior.

So this kind of usages is totally feasible

```
if (Math.random() > .9) { xhr.upload.onloadstart = handlerFunc; }

xhr.send(body);
```

under the uncertainty whether the upload events will be fired.

But in the case of SW to meet the original goal of optimizing the behavior (i.e., not starting the SW in the first place), the constraint was needed.

> Should that last set throw? Why would it? It doesn't add an event listener, note.

Yes, it throws in the current behavior. It's a matter of whether we'd consider this as a valid constraint for the optimization for SW or not.

> I thought we were only going to do this throwing behavior for fetch event. Why do we need to do it for any other event? Everything else has an API to explicitly opt in to the event.

I think it was discussed in the f2f lead to this comment: https://github.com/w3c/ServiceWorker/issues/718#issuecomment-175971941. This applies the benefit of not starting the SW that has no event listener for the event regardless of whether the app opted in for the event.

> @jungkees in theory you can do self.dispatchEvent(new Event("blah")) though, except now that would only work during the initial run, which is a little limiting.

Right. I'm not sure if there's a reasonable way to not throw in the case of CustomEvents. If so, that seems to be an option 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/issues/371#issuecomment-259865712

Received on Friday, 11 November 2016 02:31:55 UTC