Skip to content

Commit

Permalink
Factor out history state update steps
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Aug 21, 2018
1 parent 9a6595d commit 8dfc827
Showing 1 changed file with 97 additions and 79 deletions.
176 changes: 97 additions & 79 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -80575,6 +80575,85 @@ interface <dfn>History</dfn> {

<hr id="history-1">

<p>The <dfn>history state update steps</dfn>, given a <code>Document</code> object
<var>document</var>, a <span>URL</span> <var>newURL</var>, an optional <span>serialized
state</span> <var>serializedData</var>, and an optional string <var>title</var>, optionally with a
<var>state push flag</var>, are:</p>

<ol>
<li><p>Let <var>browsingContext</var> be <var>document</var>'s <span
data-x="concept-document-bc">browsing context</span>.</p></li>

<li>
<p>If the <var>state push flag</var> is set, then:</p>

<ol>
<li>
<p>Remove all the entries in <var>browsingContext</var>'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 <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>If appropriate, update the <span>current entry</span> to reflect any state that the user
agent wishes to persist. The entry is then said to be <span>an entry with persisted user
state</span>.</p></li>

<li>
<p>Add a <span>session history entry</span> entry to the session history, after the
<span>current entry</span>, with</p>

<ul>
<li><p><var>newURL</var> as the <span>URL</span></p></li>

<li><p>the <span>scroll restoration mode</span> of the current entry in the <span>session
history</span> as the scroll restoration mode</p></li>

<li><p><var>serializedData</var> as the <span>serialized state</span>, if it is
given</p></li>

<li><p><var>title</var> as the title, if it is given</p></li>
</ul>
</li>

<li><p>Update the <span>current entry</span> to be this newly added entry.</p></li>
</ol>
</li>

<li>
<p>Otherwise, update the <span>current entry</span> in <var>browsingContext</var>'s
<span>session history</span> so that:</p>

<ul>
<li><p><var>newURL</var> is the entry's new <span>URL</span></p></li>

<li><p><var>serializedData</var> is the entry's new <span>serialized state</span>, if it is
given; otherwise, the entry does not have a <span>serialized state</span></p></li>

<li><p><var>title</var> is the entry's new title, if it is given; otherwise, the entry does not
have a title</p></li>

<li><p>it represents a GET request, if it currently represents a non-GET request (e.g. it was
the result of a POST submission)</p></li>
</ul>
</li>

<li>
<p>Set <var>document</var>'s <span data-x="concept-document-url">URL</span> to
<var>newURL</var>.</p>

<p class="note">Since this is neither a <span data-x="navigate">navigation</span> of the
<span>browsing context</span> nor a <span data-x="traverse the history">history traversal</span>,
it does not cause a <code data-x="event-hashchange">hashchange</code> event to be fired.</p>
</li>
</ol>

<p>The <dfn><code data-x="dom-history-pushState">pushState(<var>data</var>, <var>title</var>, <var>url</var>)</code></dfn> method adds a state object entry to
the history.</p>

Expand All @@ -80600,103 +80679,42 @@ interface <dfn>History</dfn> {
<li><p>Let <var>serializedData</var> be
<span>StructuredSerializeForStorage</span>(<var>data</var>). Rethrow any exceptions.</p></li>

<li>
<li><p>Let <var>newURL</var> be the <span>URL</span> of the <span>current entry</span> in
<var>browsingContext</var>'s <span>session history</span>.</p></li>

<p>If the third argument is not null, run these substeps:</p>
<li>
<p>If <var>url</var> is not null, then:</p>

<ol>
<li><p><span data-x="parse a url">Parse</span> <var>url</var>, relative to the <span>relevant
settings object</span> of this <code>History</code> object.</p></li>

<li><span data-x="parse a url">Parse</span> the value of the third argument, relative to the
<span>relevant settings object</span> of this <code>History</code> object.</li>

<li>If that fails, throw a <span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</li>
<li><p>If that fails, then throw a <span>"<code>SecurityError</code>"</span>
<code>DOMException</code>.</p></li>

<li><p>Let <var>new URL</var> be the <span>resulting URL record</span>.</p></li>
<li><p>Set <var>newURL</var> to the <span>resulting URL record</span>.</p></li>

<li>Compare <var>new URL</var> to <var>document</var>'s <span
<li><p>Compare <var>newURL</var> to <var>document</var>'s <span
data-x="concept-document-url">URL</span>. If any component of these two <span data-x="URL
record">URL records</span> differ other than the <span data-x="concept-url-path">path</span>,
<span data-x="concept-url-query">query</span>, and <span
data-x="concept-url-fragment">fragment</span> components, then throw a
<span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</li>
<span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p></li>

<li>If the <span data-x="concept-url-origin">origin</span> of <var>new URL</var> is not
<li><p>If the <span data-x="concept-url-origin">origin</span> of <var>newURL</var> is not
<span>same origin</span> with the <span>origin</span> of <var>document</var>, and either the
<span data-x="concept-url-path">path</span> or <span data-x="concept-url-query">query</span>
components of the two <span data-x="URL record">URL records</span> compared in the previous
step differ, throw a <span>"<code>SecurityError</code>"</span> <code>DOMException</code>.(This prevents sandboxed content from spoofing other pages on the same origin.) </li>

step differ, throw a <span>"<code>SecurityError</code>"</span> <code>DOMException</code>. (This
prevents sandboxed content from spoofing other pages on the same origin.)</p></li>
</ol>

</li>

<li><p>If the third argument is null, then let <var>new URL</var> be the <span>URL</span>
of the <span>current entry</span>.</p></li>

<li>

<p>If the method invoked was the <code data-x="dom-history-pushState">pushState()</code>
method:</p>

<ol>

<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 <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>If appropriate, update the <span>current entry</span> to reflect any state that the user
agent wishes to persist. The entry is then said to be <span>an entry with persisted user
state</span>.</p></li>

<li><p>Add a <span>session history entry</span> entry to the session history, after the
<span>current entry</span>, with <var>serializedData</var> as the <span>serialized
state</span>, the given <var>title</var> as the title, <var>new URL</var> as the
<span>URL</span> of the entry, and the <span>scroll restoration mode</span> of the current
entry in the <span>session history</span> as the scroll restoration mode.</p></li>

<li><p>Update the <span>current entry</span> to be this newly added entry.</p></li>

</ol>

<p>Otherwise, if the method invoked was the <code
data-x="dom-history-replaceState">replaceState()</code> method:</p>

<ol>

<li><p>Update the <span>current entry</span> in the session history so that
<var>serializedData</var> is the entry's new <span>serialized state</span>, the given
<var>title</var> is the new title, and <var>new URL</var> is the entry's new
<span>URL</span>.</p></li>

</ol>

</li>

<li><p>If the <span>current entry</span> in the session history represents a non-GET request
(e.g. it was the result of a POST submission) then update it to instead represent a GET
request.</p></li>

<li>

<p>Set <var>document</var>'s <span data-x="concept-document-url">URL</span> to <var>new
URL</var>.</p>

<p class="note">Since this is neither a <span data-x="navigate">navigation</span> of the
<span>browsing context</span> nor a <span data-x="traverse the history">history traversal</span>,
it does not cause a <code data-x="event-hashchange">hashchange</code> event to be fired.</p>

</li>
<li><p>Run the <span>history state update steps</span> given <var>document</var>,
<var>newURL</var>, <var>serializedData</var>, and <var>title</var>, with the <var>state push
flag</var> set if the method invoked was the <code
data-x="dom-history-pushState">pushState()</code> method.</p></li>

<li><p>Let <var>state</var> be <span>StructuredDeserialize</span>(<var>serializedData</var>,
<var>targetRealm</var>). If this throws an exception, catch it, ignore the exception, and set
Expand Down

0 comments on commit 8dfc827

Please sign in to comment.