Skip to content

Commit

Permalink
Add code to allocate agent clusters.
Browse files Browse the repository at this point in the history
Store shared agent clusters in the browsing context group via a map of
scheme & registrable domain.

Hook the document initialization methods to obtain a similar-orgin
window agent.

Fixes whatwg#4361
  • Loading branch information
dtapuska committed Aug 13, 2019
1 parent 817ee1b commit 4fdf5bd
Showing 1 changed file with 98 additions and 58 deletions.
156 changes: 98 additions & 58 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-dfn-for="url" data-x="concept-url-origin" data-x-href="https://url.spec.whatwg.org/#concept-url-origin">Origin</dfn> of URLs</li>
<li><dfn data-x-href="https://url.spec.whatwg.org/#syntax-url-absolute">Absolute URL</dfn></li>
<li><dfn data-x-href="https://url.spec.whatwg.org/#syntax-url-relative">Relative URL</dfn></li>
<li><dfn data-x="host-registrable-domain" data-x-href="https://url.spec.whatwg.org/#host-registrable-domain">registrable domain</dfn></li>
<li>
The <dfn data-x-href="https://url.spec.whatwg.org/#concept-url-parser">URL parser</dfn> and
<dfn data-x-href="https://url.spec.whatwg.org/#concept-basic-url-parser">basic URL
Expand Down Expand Up @@ -78030,7 +78031,8 @@ dictionary <dfn>DragEventInit</dfn> : <span>MouseEventInit</span> {
</ol>

<p>To <dfn data-x="creating a new browsing context">create a new browsing context</dfn>, given
null or a <code>Document</code> object <var>creator</var>:</p>
null or a <code>Document</code> object <var>creator</var>, and <span>browsing context group</span>
<var>group</var>:</p>

<ol>
<li><p>Let <var>browsingContext</var> be a new <span>browsing context</span>.</p></li>
Expand All @@ -78052,9 +78054,13 @@ dictionary <dfn>DragEventInit</dfn> : <span>MouseEventInit</span> {
<li><p>Let <var>featurePolicy</var> be the result of <span>creating a feature policy</span>
given <var>browsingContext</var> and <var>origin</var>. <ref spec="FEATUREPOLICY"></p></li>

<li><p>Let <var>agent</var> be the result of<span
data-x="obtain-similar-origin-window-agent">obtaining a similar-origin window agent</span> given
<var>origin</var>, and <var>group</var>.</p></li>

<li>
<p>Let <var>realm execution context</var> be the result of <span>creating a new JavaScript
realm</span> with the following customizations:</p>
realm</span> provided <var>agent</var> with the following customizations:</p>

<ul>
<li><p>For the global object, create a new <code>Window</code> object.</p></li>
Expand Down Expand Up @@ -78111,15 +78117,17 @@ dictionary <dfn>DragEventInit</dfn> : <span>MouseEventInit</span> {
context</dfn>, given a <span>browsing context</span> <var>opener</var>:</p>

<ol>
<li><p>Let <var>browsingContext</var> be the result of <span>creating a new browsing
context</span> with <var>opener</var>'s <span>active document</span>.</p></li>
<li><p>Let <var>group</var> be <var>opener</var>'s <span>top-level browsing context</span>'s
<span data-x="tlbc group">group</span></p></li>

<li><p>Assert: <var>group</var> is non-null, as <span data-x="navigate">navigating</span> invokes
this directly.</p></li>

<li><p>Assert: <var>opener</var>'s <span>top-level browsing context</span>'s <span data-x="tlbc
group">group</span> is non-null, as <span data-x="navigate">navigating</span> invokes this
directly.</p></li>
<li><p>Let <var>browsingContext</var> be the result of <span>creating a new browsing
context</span> with <var>opener</var>'s <span>active document</span>, and <var>group</var>.</p></li>

<li><p><span data-x="bcg append">Append</span> <var>browsingContext</var> to <var>opener</var>'s
<span>top-level browsing context</span>'s <span data-x="tlbc group">group</span>.</p></li>
<li><p><span data-x="bcg append">Append</span> <var>browsingContext</var> to
<var>group</var>.</p></li>

<li><p>Set <var>browsingContext</var>'s <span>opener browsing context</span> to
<var>opener</var>.</p></li>
Expand Down Expand Up @@ -78147,7 +78155,8 @@ dictionary <dfn>DragEventInit</dfn> : <span>MouseEventInit</span> {

<ol>
<li><p>Let <var>browsingContext</var> be the result of <span>creating a new browsing
context</span> with <var>element</var>'s <span>node document</span>.</p></li>
context</span> with <var>element</var>'s <span>node document</span>, and <var>element</var>'s
<span>top-level browsing context</span>'s <span data-x="tlbc group">group</span></p></li>

<li><p>Set <var>element</var>'s <span>nested browsing context</span> to
<var>browsingContext</var>.</p></li>
Expand Down Expand Up @@ -78624,8 +78633,11 @@ console.assert(iframeWindow.frameElement === null);
<li><p><span data-x="set append">Append</span> <var>group</var> to the user agent's
<span>browsing context group set</span>.</p></li>

<li><p><span data-x="bcg append">Append</span> the result of <span>creating a new browsing
context</span> with null to <var>group</var>.</p></li>
<li><p>Let <var>browsingContext</var> be the result of <span>creating a new browsing
context</span> with null, and <var>group</var>.</p></li>

<li><p><span data-x="bcg append">Append</span> <var>browsingContext</var> to
<var>group</var>.</p></li>

<li><p>Return <var>group</var>.</p></li>
</ol>
Expand Down Expand Up @@ -81330,8 +81342,6 @@ interface <dfn>BarProp</dfn> {
<var>navigationResource</var>'s <span>forced sandboxing flag set</span>.</p></li>
</ul>



<h3 split-filename="history" id="history">Session history and navigation</h3>

<h4>The session history of browsing contexts</h4>
Expand Down Expand Up @@ -83699,9 +83709,15 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
<p>Otherwise:</p>

<ol>

<li><p>Let <var>agent</var> be the result of <span
data-x="obtain-similar-origin-window-agent">obtaining a similar-origin window agent</span> given
<var>origin</var>, and <var>browsingContext</var>'s <span data-x="tlbc
group">group</span>.</p></li>

<li>
<p>Let <var>realm execution context</var> be the result of <span>creating a new JavaScript
realm</span> with the following customizations:</p>
realm</span> provided <var>agent</var> with the following customizations:</p>

<ul>
<li><p>For the global object, create a new <code>Window</code> object.</p></li>
Expand Down Expand Up @@ -90284,45 +90300,11 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
data-x="concept-global-object-realm">realms</span> that can synchronously access each other, and
thus needs to run in a single execution thread.</p>

<p>To determine whether a <code>Window</code> object <var>A</var> and a <code>Window</code> object
<var>B</var> are considered <dfn>same-agent <code>Window</code> objects</dfn>, run
these steps:</p>

<ol>
<li>
<p>If <var>A</var>'s <span>relevant settings object</span>'s <span>responsible browsing
context</span>'s <span>top-level browsing context</span>'s <span data-x="tlbc
group">group</span> is not <var>B</var>'s <span>relevant settings object</span>'s
<span>responsible browsing context</span>'s <span>top-level browsing context</span>'s <span
data-x="tlbc group">group</span>, then return false.</p>

<p class="XXX">Unfortunately this model falls apart the moment a <span>browsing context</span>
is <span data-x="a browsing context is discarded">discarded</span>. <a
href="https://github.com/whatwg/html/issues/4361">Issue #4361</a> sketches a setup that could
improve this situation.</p>
</li>

<li><p>Let <var>originA</var> be <var>A</var>'s <span>relevant settings object</span>'s <span
data-x="concept-settings-object-origin">origin</span> and <var>originB</var> be <var>B</var>'s
<span>relevant settings object</span>'s <span
data-x="concept-settings-object-origin">origin</span>.</p></li>

<li><p>If <var>originA</var> is <span>same origin</span> with <var>originB</var>, then return
true.</p></li>

<li><p>If <var>originA</var> or <var>originB</var> is not a <span
data-x="concept-origin-tuple">tuple origin</span>, then return false.</p></li>

<li><p>If <var>originA</var>'s <span data-x="concept-origin-scheme">scheme</span> is not
<var>originB</var>'s <span data-x="concept-origin-scheme">scheme</span>, then return
false.</p></li>

<li><p>If <var>originA</var>'s <span data-x="concept-origin-host">host</span> is <span>same
site</span> with <var>originB</var>'s <span data-x="concept-origin-host">host</span>, then return
true.</p></li>

<li><p>Return false.</p></li>
</ol>
<p><code>Window</code> object <var>A</var> and a <code>Window</code> object <var>B</var> are
considered <dfn>same-agent <code>Window</code> objects</dfn> if <var>A</var>'s <span>relevant
settings object</span>'s <span>realm execution context</span>'s <span>agent</span> is the same object as
<var>B</var>'s <span>relevant settings object</span>'s <span>realm execution context</span>'s
<span>agent</span>.</p>

<p class="note">All <span>same-agent <code>Window</code> objects</span> together represent a group
of <code>Window</code> objects that can synchronously access each other, though sometimes only
Expand All @@ -90332,10 +90314,6 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
<p>Until such a time that this standard has a better handle on lifetimes, it defines five types of
<span data-x="agent">agents</span> that user agents must allocate at the appropriate time.</p>

<p class="note">In the future, this standard hopes to define exactly when <span
data-x="agent">agents</span> and <span data-x="agent cluster">agent clusters</span> are
created.</p>

<dl>
<dt><dfn data-export="">Similar-origin window agent</dfn></dt>
<dd>
Expand Down Expand Up @@ -90397,6 +90375,68 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
in particular among which <span data-x="agent">agents</span> the backing data of
<code>SharedArrayBuffer</code> objects can be shared.</p>

<p>A <span>browsing context group</span> has associated <dfn data-export="">shared agent
clusters</dfn> (a <span data-x="ordered map">map</span> of <span>agent cluster key</span> to
<span>agent cluster</span>).</p>

<p>A <dfn data-export="">scheme-and-site</dfn> is a tuple of a <span
data-x="concept-url-scheme">scheme</span> and a <span data-x="concept-domain">domain</span>.</p>

<p>An <dfn data-export="">agent cluster key</dfn> is an <span>origin</span> or a
<span>scheme-and-site</span>.</p>

<p>An <span>agent cluster</span> has an associated <dfn>window agent</dfn>.</p>

<p>To obtain an <span>agent cluster key</span>, given an origin <var>origin</var>, run these
steps:</p>

<ol>

<li><p>If <var>origin</var> is an <span data-x="concept-origin-opaque">opaque origin</span>, then
return <var>origin</var>.</p></li>

<li><p>If <var>origin</var>'s host's <span data-x="host-registrable-domain">registrable
domain</span> is null, then return <var>origin</var>.</p></li>

<li><p>Return (<var>origin</var>'s <span data-x="concept-url-scheme">scheme</span>,
<var>origin</var>'s <span data-x="host-registrable-domain">registrable
domain</span>).</p></li>

</ol>

<p>To obtain a <dfn data-export="" data-x="obtain-similar-origin-window-agent">similar-origin
window agent</dfn>, given an <span>origin</span> <var>origin</var>, and <span>browsing context
group</span> <var>group</var>, run these steps:</p>

<ol>

<li><p>Let <var>clusterKey</var> be the result of obtaining an <span>agent cluster key</span>
given <var>origin</var>.</p></li>

<li><p>Let <var>agentCluster</var> be the result of obtaining a <span>browsing context agent
cluster</span> with <var>group</var> and <var>clusterKey</var>.</p></li>

<li><p>If <var>agentCluster</var> does not contain a <span>window agent</span>, then add a
new <span>similar-origin window agent</span> to it.</p></li>

<li><p>Return <var>agentCluster</var>'s <span>window agent</span>.</p></li>

</ol>

<p>To obtain a <dfn data-export="">browsing context agent cluster</dfn>, given a <span>browsing
context group</span> <var>group</var> and <span>agent cluster key</span> <var>key</var>, run these
steps:</p>

<ol>

<li><p>If <var>group</var>'s <span>shared agent clusters</span>[<var>key</var>] does not exist,
then set <var>group</var>'s <span>shared agent clusters</span>[<var>key</var>] to a new agent
cluster.</p></li>

<li><p>Return <var>group</var>'s <span>shared agent clusters</span>[<var>key</var>].</p></li>

</ol>

<p class="note">Conceptually, the <span>agent cluster</span> concept is an
architecture-independent, idealized "process boundary" that groups together multiple "threads"
(<span data-x="agent">agents</span>). The <span data-x="agent cluster">agent clusters</span>
Expand Down

0 comments on commit 4fdf5bd

Please sign in to comment.