Re: An HTML language specification

Mark Baker wrote:
> On Thu, Nov 20, 2008 at 4:43 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
>> Mark Baker wrote:
>>> Your definition of "go away" is implementation dependent.  Consider a
>>> (admittedly very inefficient) implementation which rewrote the byte
>>> stream and then reparsed it after a document.write().
>>
>> This implementation would be not only inefficient but also incorrect.
>> Consider the a document being loaded in a subframe which contains:
>>
>>  <script>
>>    parent.nonIdempotentMethod();
>>    document.write("I wrote something");
>>  </script>
> 
> I didn't say that no state could be maintained between parsing the two
> byte streams.

If you maintain enough state that you can re-parse the document, 
disabling all externally-visible side-effects while deterministically 
replaying the scripts up to the point of the document.write, then it 
still won't work if you do:

   <script>
     document.write('<span>Hello</span>');
     alert(document.getElementsByTagName('span')[0].textContent);
   </script> world

because the conceptual byte stream after the document.write is

   <script>
     document.write('<span>Hello</span>');
     alert(document.getElementsByTagName('span')[0].textContent);
   </script><span>Hello</span> world

and the alert will fail because the span hasn't yet been parsed at the 
point when the script element is inserted into the DOM and executed. I 
can't think of a way to write an HTML document that will have the same 
effect as the original one without using document.write (and without 
making assumptions that won't work in general for arbitrary scripts).

-- 
Philip Taylor
pjt47@cam.ac.uk

Received on Friday, 21 November 2008 16:26:56 UTC