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 Jul 29, 2019
1 parent 2a397f6 commit 752de10
Showing 1 changed file with 111 additions and 72 deletions.
183 changes: 111 additions & 72 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-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 @@ -78029,7 +78030,11 @@ 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>

<!-- Note: Do not append the new browsing context to group as we might be creating a nested browsing
context and not a top level browsing context -->

<ol>
<li><p>Let <var>browsingContext</var> be a new <span>browsing context</span>.</p></li>
Expand All @@ -78051,11 +78056,19 @@ 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>

<ul>
<li><p>For the agent, use <var>agent</var>. <span class="XXX">This pointer is not yet defined
in the JavaScript specification; see <a
href="https://github.com/tc39/ecma262/issues/1357">tc39/ecma262#1357</a>.</span></p></li>

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

<li><p>For the global <b>this</b> binding, use <var>browsingContext</var>'s
Expand Down Expand Up @@ -78110,15 +78123,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>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>Assert: <var>group</var> is non-null, as <span data-x="navigate">navigating</span> invokes
this directly.</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>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>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 @@ -78146,7 +78161,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 @@ -78623,8 +78639,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 @@ -83698,11 +83717,20 @@ 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>

<ul>
<li><p>For the agent, use <var>agent</var>. <span class="XXX" data-x="">This pointer is not
yet defined in the JavaScript specification; see <a
href="https://github.com/tc39/ecma262/issues/1357">tc39/ecma262#1357</a>.</span></p></li>

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

<li><p>For the global <b>this</b> binding, use <var>browsingContext</var>'s
Expand Down Expand Up @@ -90283,71 +90311,14 @@ 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>
<p class="note">Two <code>Window</code> objects that have the same <span>agent</span> does not
indicate they can directly access all objects created in each others realms. Two windows might be
required to be in <span>same origin-domain</span>, see <span>IsPlatformObjectSameOrigin</span>.</p>

<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 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
after setting the <code data-x="dom-document-domain">document.domain</code> attribute
(in)appropriately.</p>

<p>Until such a time that this standard has a better handle on lifetimes, it defines five types of
<p>Until such a time that this standard has a better handle on lifetimes, it defines four 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>
<p>An <span>agent</span> whose [[CanBlock]] is false and whose set of <span
data-x="JavaScript realm">realms</span> consists of all <span
data-x="concept-global-object-realm">realms</span> of all <span>same-agent <code>Window</code>
objects</span>.</p>

<p class="note">Two <code>Window</code> objects that are <span>same origin</span> can be in
different <span data-x="similar-origin window agent">similar-origin window agents</span>, for
instance if they are each in their own <span>browsing context group</span>.</p>
</dd>

<dt><dfn data-export="">Dedicated worker agent</dfn></dt>
<dd><p>An <span>agent</span> whose [[CanBlock]] is true and whose set of <span data-x="JavaScript
realm">realms</span> consists of a single <code>DedicatedWorkerGlobalScope</code> object's <span
Expand Down Expand Up @@ -90396,6 +90367,74 @@ 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>agent cluster map</dfn> (a weak <span
data-x="ordered map">map</span> of <span>agent cluster key</span> to <span>agent
cluster</span>). User agents are responsible for collecting them when it is deemed that nothing
can access them anymore.</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>To <dfn data-x="obtain-agent-cluster-key">obtain an agent cluster key</dfn>, 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>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>registrable domain</span>).</p></li>
</ol>

<p>To <dfn data-x="obtain-similar-origin-window-agent">obtain a 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 <span
data-x="obtain-agent-cluster-key">obtaining an agent cluster key</span> given
<var>origin</var>.</p></li>

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

<li><p>Return <var>agentCluster</var>'s <span>similar-origin window agent</span>.</p></li>
</ol>

<p>A <dfn data-export="">similar-origin window agent</dfn> is an <span>agent</span> whose
[[CanBlock]] is false. </p>

<p class="note">All global objects that use this agent all have the a similar <span>origin</span>
and are allocated via the <span data-x="obtain-similar-origin-window-agent">obtain similar-origin
window agent</span> algorithm.</p>

<p>To <dfn data-x="obtain-browsing-agent-cluster">obtain a 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>agent cluster map</span>[<var>key</var>] <span data-x="map
exists">does not exist:</span></p>
<ol>
<li><p>Let <var>agentCluster</var> be a new <span>agent cluster</span>.</p></li>
<li><p>Set <var>agentCluster</var>'s <span>similar-origin window agent</span> be a new
<span>similar-origin window agent</span>.</p></li>
<li><p>Set <var>group</var>'s <span>agent cluster map</span>[<var>key</var>] to
<var>agentCluster</var>.</p></li>
</ol>
</li>

<li><p>Return <var>group</var>'s <span>agent cluster map</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 752de10

Please sign in to comment.