Skip to content

Commit

Permalink
Bug 25489 - [Imports]: Script execution order is non-deterministic in…
Browse files Browse the repository at this point in the history
… cyclic cases

This change gets rid of the notion of "cycle" and introduces "branch" concept intead.
The intention here is that we model it based on minimum spanning tree of the import graph,
instead of based on DAG, marking cycle eliminated from the import graph.

Although this change affects the definition of "import predecessor" and "import parent",
actual blocking criteria shouldn't change, except the case that pointed at the bug 25489.
This should just make the behaviour more deterministic.
  • Loading branch information
omo committed Apr 29, 2014
1 parent 4e9b329 commit a8e9390
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
Binary file modified assets/images/import-link-list.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 34 additions & 13 deletions spec/imports/index.html
Expand Up @@ -74,6 +74,7 @@ <h2 id="toc">Table of Contents</h2>
<li><a href="#loading-imports">Loading Imports</a>
<ol>
<li><a href="#import-dependent">Import Dependent</a>
<li><a href="#updateing-branch">Updating Branch</a>
<li><a href="#requesting-import">Requesting Import</a>
<li><a href="#fetching-import">Fetching Import</a>
<li><a href="#imports-and-csp">Imports and Content Security Policy</a>
Expand Down Expand Up @@ -258,20 +259,19 @@ <h2 id="loading-imports">Loading Imports</h2>
<h3 id="import-dependent">Import Dependent</h3>

<p>Each document has an <dfn id="dfn-import-link-list">import link list</dfn>, each of whose item is consist of <dfn id="dfn-import-link-link">link</dfn>, the <code><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-link-element">link</a></code> element and <dfn id="import-link-list-location">location</dfn>, a URL.
Also, the item is optionally <dfn id="dfn-import-link-list-cycle">marked as cycle</dfn>.
Also, the item is optionally <dfn id="dfn-import-link-list-branch">marked as branch</dfn>.
The list is empty at beginning and the item is added as <a href="#dfn-import-request">import request</a> altorighm specifies.</p>

<p>An <a href="#dfn-imported-document">imported document</a> has zero or more <dfn id="dfn-import-import-ancestor">import ancestors</dfn>. The <a href="#dfn-import-import-ancestor">import ancestor</a> is a document. If the <a href="#dfn-import-link-list">import link list</a> of document <var>A</var> contains an non-<a href="#dfn-import-link-list-cycle">cycle</a> item whose <a href="#import-link-list-location">location</a> points document <var>B</var>, <var>A</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of <var>B</var>. <var>B</var> is also called the <dfn id="dfn-import-parent">import parent</dfn> of the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#document"><code>Document</code></a>. The <a href="#dfn-import-import-ancestor">import ancestor</a> is transitive: If document <var>C</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of document <var>B</var> and document <var>B</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of document <var>A</var>, <var>C</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of document <var>A</var>.</p>
<p>An <a href="#dfn-imported-document">imported document</a> has zero or more <dfn id="dfn-import-import-ancestor">import ancestors</dfn>. The <a href="#dfn-import-import-ancestor">import ancestor</a> is a document. If the <a href="#dfn-import-link-list">import link list</a> of document <var>A</var> contains a <a href="#dfn-import-link-list-branch">branch</a> item whose <a href="#import-link-list-location">location</a> points document <var>B</var>, <var>A</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of <var>B</var>. <var>B</var> is also called the <dfn id="dfn-import-parent">import parent</dfn> of the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#document"><code>Document</code></a>. The <a href="#dfn-import-import-ancestor">import ancestor</a> is transitive: If document <var>C</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of document <var>B</var> and document <var>B</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of document <var>A</var>, <var>C</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of document <var>A</var>.</p>

<p>An <a href="#dfn-imported-document">imported document</a> also has one or more <dfn id="dfn-import-import-predecessor">import predecessor</dfn>. The <a href="#dfn-import-import-predecessor">import predecessor</a> is a document. If the URL of document <var>A</var> is located before the URL of document <var>B</var> in the <a href="#dfn-import-link-list">import link list</a> of <var>B</var>'s <a href="#dfn-import-parent">import parent</a>, <var>A</var> is <a href="#dfn-import-import-predecessor">import predecessor</a> of <var>B</var>. The <a href="#dfn-import-import-predecessor">import predecessor</a> is transitive. If document <var>A</var> is <a href="#dfn-import-import-predecessor">import predecessor</a> of document <var>B</var> and <var>B</var> is redecessor of document <var>C</var>, <var>A</var> is <a href="#dfn-import-import-predecessor">import predecessor</a> of <var>C</var>.</p>
<p>An <a href="#dfn-imported-document">imported document</a> also has one or more <dfn id="dfn-import-import-predecessor">import predecessors</dfn>. An <a href="#dfn-import-import-predecessor">import predecessor</a> is a document. If the URL of document <var>A</var> is located before the URL of document <var>B</var> in the <a href="#dfn-import-link-list">import link list</a> of <var>B</var>'s <a href="#dfn-import-parent">import parent</a>, and the located <a href="#dfn-import-link-link">link</a> is marked as a <a href="#dfn-import-link-list-branch">branch</a>, then <var>A</var> is <a href="#dfn-import-import-predecessor">import predecessor</a> of <var>B</var>. The <a href="#dfn-import-import-predecessor">import predecessor</a> is transitive. If document <var>A</var> is <a href="#dfn-import-import-predecessor">import predecessor</a> of document <var>B</var> and <var>B</var> is redecessor of document <var>C</var>, <var>A</var> is <a href="#dfn-import-import-predecessor">import predecessor</a> of <var>C</var>.</p>

<p>The <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#document"><code>Document</code></a> that is in either <a href="#dfn-import-import-ancestor">import ancestors</a> or <a href="#dfn-import-import-predecessor">import predecessors</a> of document <var>A</var>, or is linked from non-<a href="#dfn-import-link-list-cycle">cycle</a> item of <var>A</var>'s <a href="#dfn-import-link-list">import link list</a>, is the <dfn id="dfn-import-dependent">import dependent</dfn> of <var>A</var>.</p>
<p>The <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#document"><code>Document</code></a> that is in either <a href="#dfn-import-import-ancestor">import ancestors</a> or <a href="#dfn-import-import-predecessor">import predecessors</a> of document <var>A</var>, or is linked from <a href="#dfn-import-link-list-branch">branch</a> item of <var>A</var>'s <a href="#dfn-import-link-list">import link list</a>, is the <dfn id="dfn-import-dependent">import dependent</dfn> of <var>A</var>.</p>

<div class="informative">
<p>The <a href="#dfn-import-link-list">import link list</a> and the <a href="#dfn-import-dependent">import dependent</a> constrains the order of script execution in imports. It is intend to give a deterministic order of script execution which is defined by the order of <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-link-element"><code>link</code></a> element in each import.</p>
<p>The <a href="#dfn-import-link-list">import link list</a> and the <a href="#dfn-import-dependent">import dependent</a> constrains the order of script execution in imports. It is intend to give a deterministic order of script execution which is defined by the order of <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-link-element"><code>link</code></a> element in each import. The edges of each node is ordered in terms of <a href="#dfn-import-link-list">import link list</a>. The <a href="#dfn-import-import-predecessor">import predecessors</a> selection is aware of the order.</p>

<p>The linking structure of <a href="#dfn-import-link-list">import link lists</a> forms a directed asyclic graph (DAG). Each node of the DAG is a document and its edge is a <a href="#dfn-import-link-link">link</a>. It cannot be a tree because more than one link can point same import. Any cycle is marked by the <a href="#dfn-import-request">import request</a> algorithm and excluded from dependency calculation.
The edges of each node is ordered in terms of <a href="#dfn-import-link-list">import link list</a>. The <a href="#dfn-import-import-predecessor">import predecessors</a> selection is aware of the order.</p>
<p>The linking structure of <a href="#dfn-import-link-list">import link lists</a> forms a directed graph. Each node of the graph is a document and its edge is a <a href="#dfn-import-link-link">link</a>. <a href="#dfn-import-link-list-branch">Branches</a> are intended to form a spanning tree of the graph. This tree gives the deterministic order of the script execution.</p>

<figure id="fig-import-list">
<img src="../../assets/images/import-link-list.png">
Expand All @@ -285,17 +285,38 @@ <h3 id="import-dependent">Import Dependent</h3>
</p>
<ul>
<li>The document <var>A</var> has an <a href="#dfn-import-link-list">import link list</a> which contains a link to <var>B</var> and another link to <var>C</var>.
<li>The document <var>D</var> has a set of <a href="#dfn-import-import-ancestor">import ancestors</a> that are <var>A</var>, <var>B</var> and <var>c</var>.
<li>As <var>B</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of <var>D</var>, one of <var>D</var>'s list item that points <var>B</var> is marked as <a href="#dfn-import-link-list-cycle">cycle</a>.
<li>The <a href="#dfn-import-import-predecessor">import predecessors</a> of <var>E</var> are <var>B</var> and <var>D</var>, its <a href="#dfn-import-import-ancestor">import ancestors</a> are <var>A</var> and <var>C</var> and its <a href="#dfn-import-link-list">import link list</a> is empty.
Thus its <a href="#dfn-import-dependent">import dependents</a> are <var>A</var>, <var>B</var>, <var>C</var> and <var>D</var>.
<li>The document <var>D</var> has two <a href="#dfn-import-parent">import parents</a> which are <var>B</var> and <var>C</var>.
<li>The document <var>D</var> has a couple of <a href="#dfn-import-import-ancestor">import ancestors</a> that are <var>A</var> and <var>B</var>.
<li>As <var>B</var> is a <a href="#dfn-import-import-ancestor">import ancestor</a> of <var>D</var>, one of <var>D</var>'s list item that points <var>B</var> is not marked as a <a href="#dfn-import-link-list-branch">branch</a>.
<li>The <a href="#dfn-import-import-predecessor">import predecessors</a> of <var>E</var> is <var>B</var> but not <var>D</var> becuase the link from <var>C</var> to <var>D</var> is not marked as <a href="#dfn-import-link-list-branch">branch</a>. <var>E</var>'s <a href="#dfn-import-import-ancestor">import ancestors</a> are <var>A</var> and <var>C</var> and its <a href="#dfn-import-link-list">import link list</a> is empty.
Thus its <a href="#dfn-import-dependent">import dependents</a> are <var>A</var>, <var>B</var> and <var>C</var>.
<li>Even though the document <var>D</var> is linked from two documents <var>B</var> and <var>C</var>, its <a href="#dfn-import-parent">import parent</a> is <var>B</var> because <var>B</var> has a <a href="#dfn-import-link-link">link</a> to <var>D</var> which is marked as a <a href="#dfn-import-link-list-branch">branch</a>.
</ul>

<p>The difference between the <a href="#dfn-import-referrer">import referrer</a> and the <a href="#dfn-import-parent">import parent</a> is that <a href="#dfn-import-referrer">import referrer</a> reflects the state of the <a href="http://www.w3.org/TR/dom/#node-tree">node tree</a> and that the <a href="#dfn-import-parent">import parent</a> is built by the algorithm described in this document.</p>

</div>

<h3 id="updateing-branch">Updating Branch</h3>

<p>After a <a href="#dfn-import-link-link">link</a> is added to the <a href="#dfn-import-link-list">import link list</a>, the <dfn id="dfn-update-marking">update marking</dfn> algorithm <strong>must</strong> been run with the <a href="#dfn-master-document">master document</a>. which is <a href="#dfn-processing-equivalence">equivalent</a> to running these steps:</p>

<dl>
<dt>Input</dt>
<dd><var>DOCUMENT</var>, the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#document">Document</a></dd>
</dl>

<ol>
<li>If the <var>DOCUMENT</var> is the <a href="#dfn-master-document">master document</a>, unmark <a href="#dfn-import-link-list-branch">branch</a> of all the <a href="#dfn-import-link-link">links</a> in the <a href="#dfn-import-link-list">import link list</a> of <var>DOCUMENT</var> and every <a href="#dfn-imported-document">import</a> that is associated to <var>DOCUMENT</var>.</li>
<li>Let <var>LIST</var> be an <a href="#dfn-import-link-list">import link list</a> of <var>DOCUMENT</var>.</li>
<li>For each <var>ITEM</var> in the <var>LIST</var>:</li>
<li><ol>
<li>Let <var>LOCATION</var> be a <a href="#import-link-list-location">location</a> of <var>ITEM</var>.</li>
<li>Let <var>IMPORT</var> be an <a href="#dfn-import">import</a> whose URL is same as <var>LOCATION</var>.</li>
<li>If there is no other <a href="#dfn-import-link-link">link</a> whose <a href="#import-link-list-location">location</a> is same as <var>LOCATION</var> and which is marked as a <a href="#dfn-import-link-list-branch">branch</a>, mark <var>ITEM</var> as a <a href="#dfn-import-link-list-branch">branch</a>.</li>
<li>If <var>ITEM</var> is marked as a <a href="#dfn-import-link-list-branch">branch</a> and <var>IMPORT</var> is not <strong>null</strong>, invoke <a href="#dfn-update-marking">update marking</a> algorithm with <var>IMPORT</var>.</li>
</ol></li>
</ol>

<h3 id="requesting-import">Requesting Import</h3>

<p>When user agents attempt to <a href="#dfn-obtaining-import">obtain</a> a linked import, they <strong>must</strong> also run the <dfn id="dfn-import-request">import request</dfn> algorithm, which is <a href="#dfn-processing-equivalence">equivalent</a> to running these steps:</p>
Expand All @@ -312,8 +333,8 @@ <h3 id="requesting-import">Requesting Import</h3>
<li>Let <var>LIST</var> be an <a href="#dfn-import-link-list">import link list</a> of <var>DOCUMENT</var>.
<li>Let <var>ITEM</var> be <var>LINK</var> and <var>LOCATION</var>:</li>
<li><ol>
<li>If there is a <a href="#dfn-import-import-ancestor">import ancestor</a> of <var>DOCUMENT</var> whose URL is same as <var>LOCATION</var>, Mark <var>ITEM</var> as <a href="#dfn-import-link-list-cycle">cycle</a>.
<li>Add <var>ITEM</var> at the end of <var>LIST</var>.
<li>Invoke <a href="#dfn-update-marking">update marking</a> algorithm with the <a href="#dfn-master-document">master document</a>.
</ol></li>
</ol>
</div>
Expand Down

0 comments on commit a8e9390

Please sign in to comment.