Handle client code failures cleanly

Generally make sure that we terminate early and do not leave logic that might possibly execute.

This also ties the script loader into the pending event architecture so we
can be certain that all scripts execute in the event of calling emit early
in the page lifecycle.