The second document.write() of an external script fails. Here's a minimal test case. This alerts "[object HTMLScriptElement]", "null": <script> document.write('<script src=ignored.js id=foo></scri'+'pt>'); alert(document.getElementById('foo')); document.write('<script src=ignored.js id=bar></scri'+'pt>'); alert(document.getElementById('bar')); </script> I'd expect it to work like writing two inline scripts. This alerts "[object HTMLScriptElement]", "[object HTMLScriptElement]": <script> document.write('<script id=foo></scri'+'pt>'); alert(document.getElementById('foo')); document.write('<script id=bar></scri'+'pt>'); alert(document.getElementById('bar')); </script>
Thinking about this more it makes some sense. The first write causes the parser to be blocked by the external script. While the parser is blocked, the script continues executing. It executes the second document.write(), but its content is parser-blocked. Thus at the point the getElementById('bar') executes, the parsed source does not contain the 'bar' script yet. The only way to fix this would be to pause script execution until the external script executes. It isn't clear to me if that is the way it should work or if this is working as intended. Perhaps HTML5 defines this behavior? Thoughts?
Is this HTML5 only?
This is without the HTML5 parser. I haven't tested it with HTML5.(In reply to comment #2) > Is this HTML5 only? This is without HTML5. I haven't tried it with the HTML5 parser.
We should attach your test case to this bug, and see what the results are in firefox/IE. This behavior may or may not be expected.
Created attachment 57680 [details] Testcase IE8: PASS Opera 10.5: PASS FF3.6: RACE (passes reliably if an alert is placed after first write) WebKit: FAIL