<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>24623</bug_id>
          
          <creation_ts>2014-02-11 21:42:58 +0000</creation_ts>
          <short_desc>Hooks to disable document.write() from HTML Imports</short_desc>
          <delta_ts>2014-04-07 21:45:50 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          <blocked>24808</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Morrita Hajime">morrita</reporter>
          <assigned_to name="Morrita Hajime">morrita</assigned_to>
          <cc>annevk</cc>
    
    <cc>dglazkov</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>100331</commentid>
    <comment_count>0</comment_count>
    <who name="Morrita Hajime">morrita</who>
    <bug_when>2014-02-11 21:42:58 +0000</bug_when>
    <thetext>Anne told me that monkey patcher should let HTML know about that. 
https://www.w3.org/Bugs/Public/show_bug.cgi?id=24042#c6

HTML Imports want to prohibit document.write() which is called from
scripts in imported documents. This is because script execution timing
is undeterministic from the &quot;master&quot; document point of view as 
imports are loaded concurrently, and location to be written by write() is
unreliable.

It would be great if HTML spec has some integration point for this purpose.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100412</commentid>
    <comment_count>1</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-02-12 17:27:37 +0000</bug_when>
    <thetext>Why would the location be unreliable? Isn&apos;t the parser maintaining the pointer properly? How are you invoking the parser?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100419</commentid>
    <comment_count>2</comment_count>
    <who name="Morrita Hajime">morrita</who>
    <bug_when>2014-02-12 18:26:35 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #1)
&gt; Why would the location be unreliable? Isn&apos;t the parser maintaining the
&gt; pointer properly? How are you invoking the parser?

Let me clarify how scripts in imported document works.
It runs in the context of the &quot;master&quot; document
that is the document that has &lt;link&gt;. 

Think about following example:

-----
* index.html
&lt;html&gt;
&lt;head&gt;
&lt;link rel=a.html&gt;
&lt;/head&gt;
&lt;body&gt;
.....
&lt;/body&gt;
&lt;/html&gt;

* a.html
&lt;script&gt;
document.write(&quot;Hello&quot;); // |document| points index.html
&lt;/script&gt;
-----

In this case, it isn&apos;t deterministic that where document.write() puts the text in index.html
because the parser for index.html goes ahead regardless a.html is loaded or not.
So a.html might be loaded before the &lt;head&gt; in index.html is closed,
or it might come after &lt;/html&gt;, etc.

In other word, index.html and a.html are parsed concurrently by different parsers.
This concurrent nature is vital for imports&apos; loading speed. 

Does this make sense?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100638</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-02-14 21:59:09 +0000</bug_when>
    <thetext>It&apos;s very deterministic, actually.

Assuming that index.html was opened directly (not created using document.open), then the insertion point is undefined, which implies a call to document.open(), which blows away the index.html DOM and aborts its parser, creates a new parser, and you end up with index.html just showing &quot;Hello&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100646</commentid>
    <comment_count>4</comment_count>
    <who name="Morrita Hajime">morrita</who>
    <bug_when>2014-02-14 22:47:18 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #3)
&gt; It&apos;s very deterministic, actually.
&gt; 
&gt; Assuming that index.html was opened directly (not created using
&gt; document.open), then the insertion point is undefined, which implies a call
&gt; to document.open(), which blows away the index.html DOM and aborts its
&gt; parser, creates a new parser, and you end up with index.html just showing
&gt; &quot;Hello&quot;.

Hmm, I was confused or my explanation was wrong.

Scripts in import (a.html in the example above) can run while the master document (index.html in the example) is being parsed. It runs without waiting the master being loaded.

So timing-wise, there is no difference between a document.write() call from the script in the master document and one from script in an import. Assuming document.write() of the master inserts bytes in the stream (the insertion point is at the end of document under construction), document.write() call from an import should behave in same way. This is why we need a special-casing that bug 24042 outlines.

What do I overlook here? Were you assuming that the import parsed after the master is parsed?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101021</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-02-20 21:02:57 +0000</bug_when>
    <thetext>It doesn&apos;t matter if the document is being parsed or not. When you call document.write() on it, you blow it away.

The only times that isn&apos;t true are when the whole document was previously created with document.write(), or when you are in inline script running from the parser (which doesn&apos;t apply here).


(In reply to Morrita Hajime from comment #4)
&gt; 
&gt; So timing-wise, there is no difference between a document.write() call from
&gt; the script in the master document and one from script in an import.

Agreed, except for the case of an inline script in the master document, in which case there is a difference: the insertion point is defined in that case.


&gt; Assuming document.write() of the master inserts bytes in the stream

That&apos;s a bad assumption.


&gt; (the insertion point is at the end of document under construction),

Generally speaking, it&apos;s not. Usually, the insertion point is undefined.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101400</commentid>
    <comment_count>6</comment_count>
    <who name="Morrita Hajime">morrita</who>
    <bug_when>2014-02-25 20:48:35 +0000</bug_when>
    <thetext>Thanks for the explanation!
I finally got your point.

So It seems what I want is a way to bump ignore-destructive-writes-counter for scripts in import. As we plan to merge imports into HTML eventually, it might be fine just to monkey patch it from imports side so far.

[1] http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#ignore-destructive-writes-counter</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>