My attempt a fix for #644.

https://github.com/tmpvar/jsdom/issues/644. New test included. Seems to work. Please review.