Created attachment 215246 [details]
HTML document (needs script.js in same folder)
Appears to be a problem with all WebKit-derived that I tested.
Firefox 24 and Internet Explorer 11 handle the attached test case correctly.
Created attachment 215247 [details]
I just encountered this in the Blink fork used by Chromium, and opened a bug over there: https://bugs.chromium.org/p/chromium/issues/detail?id=611136