fix($sce): do not assume $document[0] exists

this is important so that people can mock $window without having to add stuff that angular uses internally into it

Closes #9661
This looks good to me and is not much more ugly that the bit you've removed :-)