Re: [w3c/ServiceWorker] Skip executing fetch handlers if it is no-op. (PR #1672)

@domenic commented on this pull request.



> +    <h3 id="empty-fetch-handler-identification-algorithm"><dfn>Empty Fetch Handler Identification</dfn></h3>
+
+      : Input
+      :: |workerGlobalScope|, a [=service worker/global object=].
+      : Output
+      :: a boolean
+
+      1. If |workerGlobalScope|'s [=set of event types to handle=] does not [=set/contain=] <code>fetch</code>, then returns false.
+      1. Let |onFetchHandler| be |workerGlobalScope|'s <code>onfetch</code> attribute.
+      1. If |onFetchHandler|'s <a spec="html">listener</a> is null, then return false.
+      1. Let |eventListenerList| be an empty [=list=].
+      1. [=list/For each=] |eventListener| of [onFetchHandler|'s <a spec="html">listener</a>:
+          1. If |eventListener|'s <a spec="dom">type</a> is <code>fetch</code>, then [=list/append=] |eventListener| to |eventListenerList|.
+      1. [=list/For each=] |eventListener| of |eventListenerList|:
+          1. If |eventListener|'s [=callback=] is not null:
+              1. If |eventListener| is an EventListener of the type created by <a spec="html">activate an event handler</a>, then set |callback| to the result of [=converting|convert to an ECMAScript value=] |workerGlobalScope|'s <a spec="html">event handler map</a>["fetch"]'s value to an ECMAScript value.

I suggested this type of handwave, because I didn't realize we could do better. But I think you're right. I think it should be something like this:

- Outside the loop, let |eventHandler| be |workerGlobalScope|'s <a spec="html">event handler map</a>["fetch"].

- Inside the loop, check if |eventListener| equals |eventHandler|'s [listener](https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-listener). If so, set |callback| to the result of converting |eventHandler|'s [value](https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-value) to an ECMAScript value.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/pull/1672#discussion_r1121087752
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/pull/1672/review/1318982360@github.com>

Received on Wednesday, 1 March 2023 03:20:43 UTC