Skip to content

Commit

Permalink
Investigate a new document.open()
Browse files Browse the repository at this point in the history
For #1698, #3564, ... Needs many tests.
  • Loading branch information
annevk committed May 2, 2018
1 parent d5903c4 commit 40c3917
Showing 1 changed file with 10 additions and 99 deletions.
109 changes: 10 additions & 99 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -9171,7 +9171,7 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
readonly attribute <span>HTMLOrSVGScriptElement</span>? <span data-x="dom-document-currentScript">currentScript</span>; // classic scripts in a document tree only

// <span>dynamic markup insertion</span>
[<span>CEReactions</span>] <span>Document</span> <span data-x="dom-document-open">open</span>(optional DOMString type, optional DOMString replace = ""); // type is ignored
[<span>CEReactions</span>] <span>Document</span> <span data-x="dom-document-open">open</span>(optional DOMString type, optional DOMString replace); // type and replace are ignored
<span>WindowProxy</span> <span data-x="dom-document-open">open</span>(USVString url, DOMString name, DOMString features);
[<span>CEReactions</span>] void <span data-x="dom-document-close">close</span>();
[<span>CEReactions</span>] void <span data-x="dom-document-write">write</span>(DOMString... text);
Expand Down Expand Up @@ -76913,14 +76913,12 @@ dictionary <dfn>DragEventInit</dfn> : <span>MouseEventInit</span> {

<p class="note">In general, there is a 1-to-1 mapping from the <code>Window</code> object to the
<code>Document</code> object, as long as the <code>Document</code> object has a <span
data-x="concept-document-bc">browsing context</span>. There are two exceptions. First, a
data-x="concept-document-bc">browsing context</span>. There is one exception. A
<code>Window</code> can be reused for the presentation of a second <code>Document</code> in the
same <span>browsing context</span>, such that the mapping is then 1-to-2. This occurs when a
<span>browsing context</span> is <span data-x="navigate">navigated</span> from the initial
<code>about:blank</code> <code>Document</code> to another, with <span>replacement enabled</span>.
Second, a <code>Document</code> can end up being reused for several <code>Window</code> objects
when the <code data-x="dom-document-open">document.open()</code> method is used, such that the
mapping is then many-to-1.</p>
<code>about:blank</code> <code>Document</code> to another, with <span>replacement
enabled</span>.</p>

<p class="note">A <code>Document</code> does not necessarily have a <span
data-x="concept-document-bc">browsing context</span> associated with it. In particular, data
Expand Down Expand Up @@ -79476,6 +79474,7 @@ interface <dfn>BarProp</dfn> {
the <code>Document</code>'s <span data-x="concept-document-url">URL</span> to
"<code>about:blank</code>". Therefore the <span>origin</span> is assigned when the
<code>Document</code> is created.</p>
<!-- TODO it's unclear whether it always mutates the URL -->
</dd>


Expand Down Expand Up @@ -90544,18 +90543,13 @@ document.body.appendChild(frame)</pre>
with different numbers of arguments.</p>

<dl class="domintro">
<dt><var>document</var> = <var>document</var> . <code subdfn data-x="dom-document-open">open</code>( [ <var>type</var> [, <var>replace</var> ] ] )</dt>
<dt><var>document</var> = <var>document</var> . <code subdfn data-x="dom-document-open">open</code>()</dt>
<dd>
<p>Causes the <code>Document</code> to be replaced in-place, as if it was a new
<code>Document</code> object, but reusing the previous object, which is then returned.</p>

<p>The resulting <code>Document</code> has an HTML parser associated with it, which can be given
data to parse using <code data-x="dom-document-write">document.write()</code>. (The
<var>type</var> argument is ignored.)</p>

<p>If the <var>replace</var> argument is present and has the value "<code
data-x="">replace</code>", the existing entries in the session history for the
<code>Document</code> object are removed.</p>
data to parse using <code data-x="dom-document-write">document.write()</code>.</p>

<p>The method has no effect if the <code>Document</code> is still being parsed.</p>

Expand All @@ -90578,8 +90572,7 @@ document.body.appendChild(frame)</pre>
unloaded</span>. Initially, the counter must be set to zero.</p> <!--
https://www.hixie.ch/tests/adhoc/dom/level0/document/open/unload/ -->

<p>The <dfn>document open steps</dfn>, given a <var>document</var> and <var>replaceInput</var>,
are as follows:</p>
<p>The <dfn>document open steps</dfn>, given a <var>document</var>, are as follows:</p>

<ol>
<li><p>If <var>document</var> is an <span data-x="XML documents">XML document</span>, then throw
Expand Down Expand Up @@ -90616,21 +90609,6 @@ document.body.appendChild(frame)</pre>
handler while the <code>Document</code> is being unloaded.</p>
</li>

<li><p>Let <var>replace</var> be false.

<li>
<p>If <var>replaceInput</var> is an <span>ASCII case-insensitive</span> match for "<code
data-x="">replace</code>", then set <var>replace</var> to true.</p>

<p>Otherwise, if <var>document</var>'s <span>browsing context</span>'s <span>session
history</span> contains only one <code>Document</code> object, and that was the
<code>about:blank</code> <code>Document</code> created when <var>document</var>'s <span>browsing
context</span> was <span data-x="creating a new browsing context">created</span>, and that
<code>Document</code> object has never had the <span>unload a document</span> algorithm invoked
on it (e.g., by a previous call to <code data-x="dom-document-open">document.open()</code>),
then set <var>replace</var> to true.</p>
</li>

<li><p>Set <var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state
to false.</p></li>

Expand All @@ -90653,48 +90631,6 @@ document.body.appendChild(frame)</pre>
<li><p><span data-x="concept-node-replace-all">Replace all</span> with null within
<var>document</var>, without firing any mutation events.</p></li>

<li>
<p>Call the JavaScript <span
data-x="js-InitializeHostDefinedRealm">InitializeHostDefinedRealm()</span> abstract operation
with the following customizations:</p>

<ul>
<li><p>For the global object, create a new <code>Window</code> object
<var>window</var>.</p></li>

<li><p>For the global <b>this</b> value, use <var>document</var>'s <span>browsing
context</span>'s associated <code>WindowProxy</code>.</p></li>
</ul>

<p class="&#x0058;&#x0058;&#x0058;">This is not universally implemented and can perhaps be
removed; see <a href="https://github.com/whatwg/html/issues/1698">issue #1698</a>.</p>
</li>

<li>
<p>Let <var>realm execution context</var> be the <span>running JavaScript execution
context</span>.</p>

<p class="note">This is the <span>JavaScript execution context</span> created in the previous
step.</p>
</li>

<li><p><span>Set up a window environment settings object</span> with <var>realm execution
context</var>.</p></li>

<li><p><span>Set the active document</span> of <var>document</var>'s <span>browsing
context</span> to <var>document</var> with <var>window</var>.</p></li>

<li><p>Replace <var>document</var>'s singleton objects with new instances of those objects,
created in <var>window</var>'s <span data-x="concept-global-object-realm">Realm</span>. (This
includes in particular the <code>History</code>, <code>ApplicationCache</code>, and
<code>Navigator</code>, objects, the various <code>BarProp</code> objects, the two
<code>Storage</code> objects, the various <code>HTMLCollection</code> objects, and objects
defined by other specifications, like <code>Selection</code>. It also includes all the Web IDL
prototypes in the JavaScript binding, including <var>document</var>'s prototype.)</p></li>

<!-- https://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Ciframe%20src%3D%22document%22%3E%3C%2Fiframe%3E%0A%3Cscript%3Eonload%20%3D%20function%20()%20%7B%20f%20%3D%20document.getElementsByTagName('iframe')%5B0%5D%3B%20d%20%3D%20f.contentWindow.document%3B%20%7D%3C%2Fscript%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22w(d.documentElement.innerHTML)%22%20value%3D%22dump%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cscript%3Evar%20x%20%3D%20new%20XMLHttpRequest()%3Bx.open(%26quot%3BGET%26quot%3B%2C%20%26quot%3BGET%26quot%3B)%3Bx.onreadystatechange%3Dfunction()%20%7B%20alert(x.readyState)%3B%20%7D%3Bx.send(null)%3B%3C%2Fscript%3E')%3Bd.close()%3B%20setTimeout(function()%20%7B%20d.open()%3B%20d.write('%3Cp%3Etest%3C%2Fp%3E')%3B%20d.close()%20%7D%2C%200)%3B%22%20value%3D%22xhr%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.onclick%20%3D%20function()%20%7B%20w('click')%20%7D%22%20value%3D%22add%20click%20handler%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cp%3Etest%3C%2Fp%3E')%3B%20d.close()%22%20value%3D%22replace%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cp%3E%3Cscript%3Ei%20%3D%200%3B%20setTimeout(%26quot%3Bparent.w(i%2B%2B)%26quot%3B%2C%202000)%3C%2Fscript%3E%3C%2Fp%3E')%3B%20d.close()%22%20value%3D%22replace%20with%20timer%22%3E -->
<!-- https://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0D%0A...%3Ciframe%3E%3C%2Fiframe%3E%0D%0A%3Cscript%3E%0D%0Aonload%20%3D%20function%20()%20%7B%0D%0A%20frames%5B0%5D.test%20%3D%201%0D%0A%20w(frames%5B0%5D.test)%3B%0D%0A%20var%20a%20%3D%20frames%5B0%5D.document.location.assign%3B%0D%0A%20w(a)%3B%0D%0A%20w(frames%5B0%5D.document.location.assign%20%3D%3D%3D%20a)%3B%0D%0A%20frames%5B0%5D.document.open()%3B%0D%0A%20frames%5B0%5D.document.write('%3Cscript%3Edocument.write(test)%3C%5C%2Fscript%3E')%3B%0D%0A%20frames%5B0%5D.document.close()%3B%0D%0A%20w(frames%5B0%5D.test)%3B%0D%0A%20w(frames%5B0%5D.document.location.assign%20%3D%3D%3D%20a)%3B%0D%0A%7D%0D%0A%3C%2Fscript%3E -->

<li><p>Change <var>document</var>'s <span data-x="document's character encoding">character
encoding</span> to <span>UTF-8</span>.</p></li>

Expand Down Expand Up @@ -90725,30 +90661,6 @@ document.body.appendChild(frame)</pre>
<li><p>Set the <span>current document readiness</span> of <var>document</var> to "<code
data-x="">loading</code>".</p></li>

<li><p>Remove any <span data-x="concept-task">tasks</span> queued by the <span>history traversal
task source</span> that are associated with any <code>Document</code> objects in the
<span>top-level browsing context</span>'s <span>document family</span>.</p></li>

<li>
<p>Remove all the entries in the <span>browsing context</span>'s <span>session history</span>
after the <span>current entry</span>. If the <span>current entry</span> is the last entry in the
session history, then no entries are removed.</p>

<p class="note">This <a href="#history-notes">doesn't necessarily have to affect</a> the user
agent's user interface.</p>
</li>

<li><p>Remove any earlier entries whose <code>Document</code> object is
<var>document</var>.</p></li>

<li><p>If <var>replace</var> is false, then add a new entry, just before the last entry,
and associate with the new entry the text that was parsed by the previous parser associated with
<var>document</var>, as well as the state of <var>document</var> at the start of these steps.
This allows the user to step backwards in the session history to see the page before it was blown
away by the <code data-x="dom-document-open">document.open()</code> call. This new entry does not
have a <code>Document</code> object, so a new one will be created if the session history is
traversed to that entry.</p></li>

<li><p>Set <var>document</var>'s <span>fired unload</span> flag to false. (It could have been set
to true during the <span data-x="unload a document">unload</span> step above.)</p></li>

Expand All @@ -90759,9 +90671,8 @@ document.body.appendChild(frame)</pre>
</ol>

<p>When invoked with two arguments or fewer, the <code
data-x="dom-document-open">document.open(<var>type</var>, <var>replace</var>)</code> method must
return the result of running the <span>document open steps</span> with this <code>Document</code>
object and <var>replace</var>.
data-x="dom-document-open">document.open(<var>type</var>)</code> method must return the result of
running the <span>document open steps</span> with this <code>Document</code> object.

<p class="note">The <var>type</var> argument is ignored. Also, the <code
data-x="dom-document-open">document.open()</code> method does not affect whether a
Expand Down

0 comments on commit 40c3917

Please sign in to comment.