Fix formatting.
Add comments explaining ServiceWorker related code.

Also provide safe tests for checking if a worker is a SharedWorker or a
ServiceWorker.