Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement Worker.prototype.terminate() #5846
Conversation
Adds support for terminating DOM workers. A new ScriptMsg::Terminate was added to notify the WorkerGlobalScope/DedicatedWorkerGlobalScope to stop processing events and shut down. A closing flag was added to WorkerGlobalScope per the spec. Additionally, a closing flag was added to dom::worker::Worker to ensure no further events are dispatched to the onmessage handler. The change to the wpt WorkerTerminate.js is a patch for the broken Worker_terminate_event_queue test (asserts 10001 == 10000). Resolves #4427
highfive
commented
Apr 26, 2015
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @jdm (or someone else) soon. |
hoppipolla-critic-bot
commented
Apr 26, 2015
|
Critic review: https://critic.hoppipolla.co.uk/r/4802 This is an external review system which you may optionally use for the code review of your pull request. In order to help critic track your changes, please do not make in-place history rewrites (e.g. via |
| @@ -100,6 +103,10 @@ impl Worker { | |||
| data: StructuredCloneData) { | |||
| let worker = address.to_temporary().root(); | |||
|
|
|||
| if worker.r().closing.get() { | |||
This comment has been minimized.
This comment has been minimized.
jwilm
Apr 27, 2015
Author
Contributor
The spec specifies to empty the event/task queue associated with the worker as to not deliver further events to the onmessage handler. Without a synchronous way to affect the DedicatedWorkerGlobalScope, I resorted to these short-circuiting checks to prevent messages from being delivered. I keep thinking about this because it's kind of ugly. Does someone have any perspective on a cleaner way to achieve that behavior?
This comment has been minimized.
This comment has been minimized.
jwilm
Apr 28, 2015
Author
Contributor
Gecko appears to differentiate between normal events in the worker thread's queue and what it calls a ControlRunnable. The run loop in their worker prioritizes the control events and handles at most one normal event on an iteration. We could implement something similar by adding a control channel and moving to a select model for the loop.
|
I commented on critic. |
|
I left a couple of comments/questions in reply. Do reviewers get notified of replies from critic, or should I ping from the issue? |
|
The comments arrive in email form; no ping necessary. |
|
I fixed all of the issues on critic except escaping a long running JS handler. Interrupting JS execution in this case requires a call to JS_RequestInterrupt from |
|
The latest changes add support for killing a blocking script in the worker. Such capability requires a reference to the JSRuntime in It might be good to have a second channel for workers as well. I ended up needing to buffer ScriptMsgs outside of the receiver. This wouldn't even be a problem if there was a dedicated channel for control messages. The code in |
|
Please rebase on master. |
|
Rebased as #6652 |
jwilm commentedApr 26, 2015
Adds support for terminating DOM workers.
ScriptMsg::Terminatewas added to notify the WorkerGlobalScope/DedicatedWorkerGlobalScope to stop processing events and shut down. A closing flag was added to WorkerGlobalScope per the spec.Additionally, a closing flag was added to
dom::worker::Workerto ensure no further events are dispatched to theonmessagehandler.The change to the wpt WorkerTerminate.js is a patch for the broken Worker_terminate_event_queue test (asserts 10001 == 10000).
Resolves #4427