Flushing trailing text in document.write()

While fixing an issue related to flushing elements so that gEBI can  
see elements that were document.written immediately before the gEBI  
call, it occurred to me to test the flushing of trailing text.

Demos:
http://hsivonen.iki.fi/test/moz/flushing-document-written-text.html
http://hsivonen.iki.fi/test/moz/flushing-document-written-text-no-alert.html

Firefox 3, WebKit trunk, Opera 10, IE8 (IE8 standards mode) and IE7  
(standards mode) all flush the document.written element node to the  
DOM before the gEBI.

WebKit and Opera don't flush the trailing text, a behavior that flows  
naturally from an implementation that has a lazily flushed text  
accumulation buffer in the tree builder.

Firefox 3 flushes the trailing text and then append subsequent text to  
the text node that was already added to the DOM.

IE7 and IE8 seem to append the next text flush to the pre-existing  
text node if it is the last child of its parent at that point or  
create a new text node if the previous text node is no longer the last  
child.

The spec requires the Firefox behavior, which involves more complexity  
than the WebKit/Opera behavior by requiring an operation for adding  
text to an existing text node plus keeping track of the node to which  
to add. One might imagine that there are sites depending on the  
behavior that Firefox and IE have in common (the case where a script  
doesn't deliberately insert stuff between the text flushes). However,  
since Safari and Opera have gotten away with a different behavior, I  
wonder if supporting the Firefox/IE behavior Solves a Real Problem or  
introduces Needless Complexity.

Are there any real sites that motivate supporting the Firefox or IE  
behavior? If not, it would be nice to go with the WebKit/Opera  
behavior. (I think the IE behavior is the least desirable from an  
implementation point of view.)

In any case, the implementation requirements aren't obvious from the  
spec text. Even if the specced behavior stays as is, it would be good  
to draw attention to the implications in this case.

-- 
Henri Sivonen
hsivonen@iki.fi
http://hsivonen.iki.fi/

Received on Thursday, 19 March 2009 12:22:01 UTC