Rewrite the definition of service worker client and its references
This changes the definition of the service worker client from type of an
environment or an environment settings object to just an environment. As
an environment settings object *is-a* environment, this rewrites the
references to those objects without using the explicit *type of*
language. Instead, this changes to use if-else statments that check
types from most-specialized to most-general order.
Fixes #1045 #1046