Bug 1798773 Comment 19 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

(In reply to Olli Pettay [:smaug][bugs@pettay.fi] from comment #18)
> To follow the specs, WorkerNavigator should keep the storagemanager alive as long as JS can access it. And if it is accessed first time very late, perhaps Shutdown() should be called immediately. That hopefully makes the manager effectively no-op (at least it should make it such).

But the `StorageManager` is not alive when the worker is asked to cancel, it gets initialized only during the (late) `onmessage` handling, so `WorkerNavigator` cannot keep it alive? We could have a check inside `WorkerNavigator::Storage` if the worker is canceling, not sure what the callers will think of a `nullptr` there, though.

Assuming that we see the "terminate" [case of the spec here](https://html.spec.whatwg.org/multipage/workers.html#terminate-a-worker) I read there:

> 2. If there are any tasks queued in the WorkerGlobalScope object's relevant agent's event loop's task queues, discard them without processing them.
> 3. Abort the script currently running in the worker.

my interpretation would be, that the entire `onmessage` should not be run anymore.
(In reply to Olli Pettay [:smaug][bugs@pettay.fi] from comment #18)
> To follow the specs, WorkerNavigator should keep the storagemanager alive as long as JS can access it. And if it is accessed first time very late, perhaps Shutdown() should be called immediately. That hopefully makes the manager effectively no-op (at least it should make it such).

But the `StorageManager` is not alive when the worker is asked to cancel, it gets initialized only during the (late) `onmessage` handling, so `WorkerNavigator` cannot keep it alive? We could have a check inside `WorkerNavigator::Storage` if the worker is canceling, not sure what the callers will think of a `nullptr` there, though.

Assuming that we see the "terminate" [case of the spec here](https://html.spec.whatwg.org/multipage/workers.html#terminate-a-worker) I read there:

> 2. If there are any tasks queued in the WorkerGlobalScope object's relevant agent's event loop's task queues, discard them without processing them.
> 3. Abort the script currently running in the worker.

my interpretation would be, that the entire `onmessage` should not be run anymore.

There might be a question here, if the order between

```
  worker.postMessage([], [])
  setTimeout(() => {window.location.reload(true)})
```

should be always respected in executing the events on the worker thread, but IIUC `cancel()` can be issued anytime asynchronously, in general.

Back to Bug 1798773 Comment 19