W3C home > Mailing lists > Public > public-html@w3.org > November 2008

document.write from event handlers (was: Re: Black-box equivalence of parsing fragments directly into context node)

From: Henri Sivonen <hsivonen@iki.fi>
Date: Thu, 27 Nov 2008 18:59:06 +0200
Cc: Jonas Sicking <jonas@sicking.cc>, HTML WG <public-html@w3.org>
Message-Id: <4635A35A-6A91-49CF-BD29-1C3EEBEA7095@iki.fi>
To: Boris Zbarsky <bzbarsky@MIT.EDU>

On Nov 27, 2008, at 17:15, Boris Zbarsky wrote:

>> Speaking of the load event for SVG subtrees: During normal parse,  
>> when the load event for an <svg> element fires, can a handler react  
>> to it before there has been an event loop spin?
> Yes, absolutely.  The event fires synchronously, as required by the  
> spec.
>> That is, should I treat the firing of that event as a potential  
>> trigger of document.write() entering the parser?
> Yes.

This brings up a spec-relevant issue:

Should document.write() tokenize synchronously when called from a  
event handler?

I tested document.write() from a mutation event handler by mutating  
the tree from script during parse. It looks like Gecko might in some  
cases tokenize the argument of document.write() from mutation event  
handler before the mutation that fired the event is complete. I  
couldn't figure out when exactly that happens. However, when it did,  
WebKit and Opera behaved differently, so there's no interop.

As a preliminary opinion, I'd like to suggest that if at all feasible  
considering legacy, document.write() from an event handler should  
write to the stream but not tokenize before the method returns.  
Otherwise, the ways in which the parser needs to be re-entrant become  
complicated for very little practical gain. With simple testing, this  
*seems* to be what WebKit and Opera do.

More generally, if document.write() occurs for any reason other than  
the parser kicking off the evaluation of a script element, it would be  
simpler if document.write() returned without tokenizing.

Henri Sivonen
Received on Thursday, 27 November 2008 16:59:48 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:15:39 UTC