[whatwg] Script/parser interaction bug?

Ian Hickson ian at hixie.ch
Wed Feb 11 22:55:18 PST 2009


On Tue, 20 Jan 2009, Kartikaya Gupta wrote:
>
> I have a test case that works in major browsers (FF, Opera, Safari, IE6) 
> but that I don't think would work if the they followed the behavior as 
> currently specified in HTML5. I've put the test case online:
> 
> http://stakface.com/pub/mango/ext7.html
> 
> The assertion "document.getElementById('r').firstChild.data == 'PASS'" 
> is true after the page has loaded, whereas according to the spec I don't 
> think it shouldn't be.
> 
> The steps are roughly as follows:
> - tokenize/treebuild ext7.html until the first closing script tag is found (for the 7a.js script)
> - run the script. this sets 7a.js to be the "pending external script"
> - execute the "pending external script" (7a.js) since it's not a re-entrant invocation of the tree builder
> --- insert the 7b.js line into the input stream
> --- tokenize/treebuild the 7b.js script tag until the </script> for 7b.js is found
> --- run the script. this sets 7b.js to be the "pending external script"
> --- now, since there is a "pending external script" and this is a re-entrant invocation, set the pause flag to true and bail
> --- insert the other stuff in 7a.js into the input stream
> --- since the parser pause flag is set this other stuff does NOT get tokenized/treebuilt yet
> - 7a.js finishes executing, and now we have a new "pending external script", which is 7b.js

I think the parser pause flag gets set to false again here.

> - execute 7b.js
> --- throws
> - continue processing input stream (this now has the contents of the document.write calls from 7a.js, line 2 onwards)
> - tokenize/treebuild the input stream until the </script> that was document.write'd at the bottom of 7a.js is encountered
> - execute the script
> --- insert the div into the input stream
> --- since the parser pause flag is still set the div does NOT get tokenized/treebuilt

Why is it still set?

> --- run the line that sets .firstChild.data to PASS. since the div isn't in the DOM yet, this throws and the script is done
> - unwind back to the treebuilder, which clears the parser pause flag since the script nesting level drops to zero
> - tokenize/treebuild the input stream, which contains the div tag
> - add div with content FAIL to the DOM
> - done
> 
> Here, I think the pause flag needs to get cleared earlier, so that when 
> the div is inserted into the input stream, it gets tokenized and added 
> to the DOM. This would make the behavior consistent with what I'm seeing 
> in major browsers. Thoughts?

Could you reannotate the above but with the script nesting level 
explicitly given at each step?

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list