Skip to content

Commit 916c911

Browse files
committed
Incumbent
1 parent c105071 commit 916c911

File tree

1 file changed

+77
-80
lines changed

1 file changed

+77
-80
lines changed

source

Lines changed: 77 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -106119,23 +106119,23 @@ new PaymentRequest(…); // Allowed to use
106119106119
callback">cleaning up after running a callback</span>, this value will be incremented and
106120106120
decremented.</p>
106121106121

106122-
<p>Every <span>event loop</span> has an associated <dfn>backup incumbent settings object
106123-
stack</dfn>, initially empty. Roughly speaking, it is used to determine the <span>incumbent
106124-
settings object</span> when no author code is on the stack, but author code is responsible for the
106125-
current algorithm having been run in some way. The process of <span data-x="prepare to run a
106126-
callback">preparing to run a callback</span> and <span data-x="clean up after running a
106127-
callback">cleaning up after running a callback</span> manipulate this stack. <ref>WEBIDL</ref></p>
106122+
<p>Every <span>event loop</span> has an associated <dfn>backup incumbent realm stack</dfn>,
106123+
initially empty. Roughly speaking, it is used to determine the <span
106124+
data-x="concept-incumbent-realm">incumbent realm</span> when no author code is on the stack, but
106125+
author code is responsible for the current algorithm having been run in some way.
106126+
The process of <span data-x="prepare to run a callback">preparing to run a callback</span> and
106127+
<span data-x="clean up after running a callback">cleaning up after running a callback</span>
106128+
manipulate this stack. <ref>WEBIDL</ref></p>
106128106129

106129106130
<p>When Web IDL is used to <span data-x="es-invoking-callback-functions">invoke</span> author
106130106131
code, or when <span>HostEnqueuePromiseJob</span> invokes a promise job, they use the following
106131-
algorithms to track relevant data for determining the <span>incumbent settings object</span>:</p>
106132+
algorithms to track relevant data for determining the <span
106133+
data-x="concept-incumbent-realm">incumbent realm</span>:</p>
106132106134

106133-
<p>To <dfn export>prepare to run a callback</dfn> with an <span>environment settings object</span>
106134-
<var>settings</var>:</p>
106135+
<p>To <dfn export>prepare to run a callback</dfn> with a <span>realm</span> <var>realm</var>:</p>
106135106136

106136106137
<ol>
106137-
<li><p>Push <var>settings</var> onto the <span>backup incumbent settings object
106138-
stack</span>.</p></li>
106138+
<li><p>Push <var>realm</var> onto the <span>backup incumbent realm stack</span>.</p></li>
106139106139

106140106140
<li><p>Let <var>context</var> be the <span>topmost script-having execution
106141106141
context</span>.</p></li>
@@ -106144,8 +106144,8 @@ new PaymentRequest(&hellip;); // Allowed to use
106144106144
<span>skip-when-determining-incumbent counter</span>.</p></li>
106145106145
</ol>
106146106146

106147-
<p>To <dfn export>clean up after running a callback</dfn> with an <span>environment settings
106148-
object</span> <var>settings</var>:</p>
106147+
<p>To <dfn export>clean up after running a callback</dfn> with a <span>realm</span>
106148+
<var>realm</var>:</p>
106149106149

106150106150
<ol>
106151106151
<li>
@@ -106159,19 +106159,18 @@ new PaymentRequest(&hellip;); // Allowed to use
106159106159
<li><p>If <var>context</var> is not null, decrement <var>context</var>'s
106160106160
<span>skip-when-determining-incumbent counter</span>.</p></li>
106161106161

106162-
<li><p><span>Assert</span>: the topmost entry of the <span>backup incumbent settings object
106163-
stack</span> is <var>settings</var>.</p></li>
106162+
<li><p><span>Assert</span>: the topmost entry of the <span>backup incumbent realm stack</span> is
106163+
<var>realm</var>.</p></li>
106164106164

106165-
<li><p>Remove <var>settings</var> from the <span>backup incumbent settings object
106166-
stack</span>.</p></li>
106165+
<li><p>Remove <var>realm</var> from the <span>backup incumbent realm stack</span>.</p></li>
106167106166
</ol>
106168106167

106169106168
<p>Here, the <dfn>topmost script-having execution context</dfn> is the topmost entry of the
106170106169
<span>JavaScript execution context stack</span> that has a non-null ScriptOrModule component, or
106171106170
null if there is no such entry in the <span>JavaScript execution context stack</span>.</p>
106172106171

106173-
<p>With all this in place, the <dfn export>incumbent settings object</dfn> is determined as
106174-
follows:</p>
106172+
<p>With all this in place, the <dfn export data-x="concept-incumbent-realm">incumbent realm</dfn>
106173+
is determined as follows:</p>
106175106174

106176106175
<ol>
106177106176
<li><p>Let <var>context</var> be the <span>topmost script-having execution
@@ -106183,32 +106182,30 @@ new PaymentRequest(&hellip;); // Allowed to use
106183106182

106184106183
<ol>
106185106184
<li>
106186-
<p><span>Assert</span>: the <span>backup incumbent settings object stack</span> is not
106187-
empty.</p>
106188-
106189-
<p class="note">This assert would fail if you try to obtain the <span>incumbent settings
106190-
object</span> from inside an algorithm that was triggered neither by <a
106191-
href="#calling-scripts">calling scripts</a> nor by Web IDL <span
106192-
data-x="es-invoking-callback-functions">invoking</span> a callback. For example, it would
106193-
trigger if you tried to obtain the <span>incumbent settings object</span> inside an algorithm
106194-
that ran periodically as part of the <span>event loop</span>, with no involvement of author
106195-
code. In such cases the <span data-x="concept-incumbent-everything">incumbent</span> concept
106196-
cannot be used.</p>
106185+
<p><span>Assert</span>: the <span>backup incumbent realm stack</span> is not empty.</p>
106186+
106187+
<p class="note">This assert would fail if you try to obtain the <span
106188+
data-x="concept-incumbent-realm">incumbent realm</span> from inside an algorithm that was
106189+
triggered neither by <a href="#calling-scripts">calling scripts</a> nor by Web IDL <span
106190+
data-x="es-invoking-callback-functions">invoking</span> a callback.
106191+
For example, it would trigger if you tried to obtain the <span
106192+
data-x="concept-incumbent-realm">incumbent realm</span> inside an algorithm that ran
106193+
periodically as part of the <span>event loop</span>, with no involvement of author code.
106194+
In such cases the <span data-x="concept-incumbent-everything">incumbent</span> concept cannot
106195+
be used.</p>
106197106196
</li>
106198106197

106199-
<li><p>Return the topmost entry of the <span>backup incumbent settings object
106200-
stack</span>.</p></li>
106198+
<li><p>Return the topmost entry of the <span>backup incumbent realm stack</span>.</p></li>
106201106199
</ol>
106202106200
</li>
106203106201

106204-
<li><p>Return <var>context</var>'s Realm component's <span
106205-
data-x="concept-principal-realm-of-realm">principal realm</span>'s <span
106206-
data-x="concept-realm-settings-object">settings object</span>.</p></li>
106202+
<li><p>Return <var>context</var>'s Realm component.</p></li>
106207106203
</ol>
106208106204

106209-
<p>Then, the <dfn export data-x="concept-incumbent-realm">incumbent realm</dfn> is the <span
106210-
data-x="environment settings object's realm">realm</span> of the <span>incumbent settings
106211-
object</span>.</p>
106205+
<p>Then, the <dfn export>incumbent settings object</dfn> is the
106206+
<span data-x="concept-incumbent-realm">incumbent realm</span>'s
106207+
<span data-x="concept-principal-realm-of-realm">principal realm</span>'s
106208+
<span data-x="concept-realm-settings-object">settings object</span>.</p>
106212106209

106213106210
<p>Similarly, the <dfn export data-x="concept-incumbent-global">incumbent global object</dfn> is
106214106211
the <span data-x="concept-settings-object-global">global object</span> of the <span>incumbent
@@ -106228,10 +106225,10 @@ new PaymentRequest(&hellip;); // Allowed to use
106228106225
frames[0].postMessage("some data", "*");
106229106226
&lt;/script></code></pre>
106230106227

106231-
<p>There are two interesting <span data-x="environment settings object">environment settings
106232-
objects</span> here: that of <code data-x="">window</code>, and that of <code
106233-
data-x="">frames[0]</code>. Our concern is: what is the <span>incumbent settings object</span> at
106234-
the time that the algorithm for <code data-x="dom-window-postMessage">postMessage()</code>
106228+
<p>There are two interesting <span data-x="realm">realms</span> here: that of
106229+
<code data-x="">window</code>, and that of <code data-x="">frames[0]</code>.
106230+
Our concern is: what is the <span data-x="concept-incumbent-realm">incumbent realm</span> at the
106231+
time that the algorithm for <code data-x="dom-window-postMessage">postMessage()</code>
106235106232
executes?</p>
106236106233

106237106234
<p>It should be that of <code data-x="">window</code>, to capture the intuitive notion that the
@@ -106281,15 +106278,15 @@ new PaymentRequest(&hellip;); // Allowed to use
106281106278
<p>This time, the result involves more complicated mechanisms:</p>
106282106279

106283106280
<p>When <code data-x="">bound</code> is <span data-x="concept-idl-convert">converted</span> to a
106284-
Web IDL callback type, the <span>incumbent settings object</span> is that corresponding to <code
106285-
data-x="">window</code> (in the same manner as in our starter example above). Web IDL stores this
106286-
as the resulting callback value's <span>callback context</span>.</p>
106281+
Web IDL callback type, the <span data-x="concept-incumbent-realm">incumbent realm</span> is that
106282+
corresponding to <code data-x="">window</code> (in the same manner as in our starter example
106283+
above). Web IDL stores this as the resulting callback value's <span>callback context</span>.</p>
106287106284

106288106285
<p>When the <span data-x="concept-task">task</span> posted by <code
106289106286
data-x="dom-setTimeout">setTimeout()</code> executes, the algorithm for that task uses Web IDL to
106290106287
<span data-x="es-invoking-callback-functions">invoke</span> the stored callback value. Web IDL in
106291106288
turn calls the above <span>prepare to run a callback</span> algorithm. This pushes the stored
106292-
<span>callback context</span> onto the <span>backup incumbent settings object stack</span>. At
106289+
<span>callback context</span> onto the <span>backup incumbent realm stack</span>. At
106293106290
this time (inside the timer task) there is no author code on the stack, so the <span>topmost
106294106291
script-having execution context</span> is null, and nothing gets its
106295106292
<span>skip-when-determining-incumbent counter</span> incremented.</p>
@@ -106304,11 +106301,12 @@ new PaymentRequest(&hellip;); // Allowed to use
106304106301
data-x="dom-window-postMessage">postMessage()</code>, with no <span
106305106302
data-x="js-ScriptEvaluation">ScriptEvaluation</span> context or similar below it.</p>
106306106303

106307-
<p>This is where we fall back to the <span>backup incumbent settings object stack</span>. As
106308-
noted above, it will contain as its topmost entry the <span>relevant settings object</span> of
106309-
<code data-x="">window</code>. So that is what is used as the <span>incumbent settings
106310-
object</span> while executing the <code data-x="dom-window-postMessage">postMessage()</code>
106311-
algorithm.</p>
106304+
<p>This is where we fall back to the <span>backup incumbent realm stack</span>.
106305+
As noted above, it will contain as its topmost entry the <span
106306+
data-x="concept-relevant-realm">relevant realm</span> of <code data-x="">window</code>.
106307+
So its <span data-x="concept-realm-settings-object">settings object</span> is what is used as the
106308+
<span>incumbent settings object</span> while executing the <code
106309+
data-x="dom-window-postMessage">postMessage()</code> algorithm.</p>
106312106310
</div>
106313106311

106314106312
<div class="example" id="example-incumbent-3">
@@ -106333,21 +106331,21 @@ document.querySelector("button").addEventListener("click", bound);
106333106331
};
106334106332
&lt;/script></code></pre>
106335106333

106336-
<p>Again there are two interesting <span data-x="environment settings object">environment
106337-
settings objects</span> in play: that of <code data-x="">a.html</code>, and that of <code
106338-
data-x="">b.html</code>. When the <code data-x="dom-location-assign">location.assign()</code>
106339-
method triggers the <span><code>Location</code>-object navigate</span> algorithm, what will be
106340-
the <span>incumbent settings object</span>? As before, it should intuitively be that of <code
106341-
data-x="">a.html</code>: the <code data-x="event-click">click</code> listener was originally
106342-
scheduled by <code data-x="">a.html</code>, so even if something involving <code
106343-
data-x="">b.html</code> causes the listener to fire, the <span
106344-
data-x="concept-incumbent-everything">incumbent</span> responsible is that of <code
106345-
data-x="">a.html</code>.</p>
106334+
<p>Again there are two interesting <span data-x="realm">realms</span> in play: that of
106335+
<code data-x="">a.html</code>, and that of <code data-x="">b.html</code>.
106336+
When the <code data-x="dom-location-assign">location.assign()</code> method triggers the
106337+
<span><code>Location</code>-object navigate</span> algorithm, what will be the <span
106338+
data-x="concept-incumbent-realm">incumbent realm</span>?
106339+
As before, it should intuitively be that of <code data-x="">a.html</code>: the <code
106340+
data-x="event-click">click</code> listener was originally scheduled by <code
106341+
data-x="">a.html</code>, so even if something involving <code data-x="">b.html</code> causes the
106342+
listener to fire, the <span data-x="concept-incumbent-everything">incumbent</span> responsible is
106343+
that of <code data-x="">a.html</code>.</p>
106346106344

106347106345
<p>The callback setup is similar to the previous example: when <code data-x="">bound</code> is
106348-
<span data-x="concept-idl-convert">converted</span> to a Web IDL callback type, the
106349-
<span>incumbent settings object</span> is that corresponding to <code data-x="">a.html</code>,
106350-
which is stored as the callback's <span>callback context</span>.</p>
106346+
<span data-x="concept-idl-convert">converted</span> to a Web IDL callback type, the <span
106347+
data-x="concept-incumbent-realm">incumbent realm</span> is that corresponding to <code
106348+
data-x="">a.html</code>, which is stored as the callback's <span>callback context</span>.</p>
106351106349

106352106350
<p>When the <code data-x="dom-click">click()</code> method is called inside <code
106353106351
data-x="">b.html</code>, it <span data-x="concept-event-dispatch">dispatches</span> a <code
@@ -106356,17 +106354,16 @@ document.querySelector("button").addEventListener("click", bound);
106356106354
executes as part of event dispatch, there <em>is</em> author code on the stack; the <span>topmost
106357106355
script-having execution context</span> is that of the <code data-x="">onLoad</code> function,
106358106356
whose <span>skip-when-determining-incumbent counter</span> gets incremented. Additionally, <code
106359-
data-x="">a.html</code>'s <span>environment settings object</span> (stored as the
106360-
<code>EventHandler</code>'s <span>callback context</span>) is pushed onto the
106361-
<span>backup incumbent settings object stack</span>.</p>
106357+
data-x="">a.html</code>'s <span>realm</span> (stored as the <code>EventHandler</code>'s
106358+
<span>callback context</span>) is pushed onto the <span>backup incumbent realm stack</span>.</p>
106362106359

106363106360
<p>Now, when the <span><code>Location</code>-object navigate</span> algorithm looks up the
106364-
<span>incumbent settings object</span>, the <span>topmost script-having execution
106365-
context</span> is still that of the <code data-x="">onLoad</code> function (due to the fact we
106366-
are using a bound function as the callback). Its <span>skip-when-determining-incumbent
106367-
counter</span> value is one, however, so we fall back to the <span>backup incumbent settings
106368-
object stack</span>. This gives us the <span>environment settings object</span> of <code
106369-
data-x="">a.html</code>, as expected.</p>
106361+
<span data-x="concept-incumbent-global">incumbent global object</span>, the <span>topmost
106362+
script-having execution context</span> is still that of the <code data-x="">onLoad</code>
106363+
function (due to the fact we are using a bound function as the callback).
106364+
Its <span>skip-when-determining-incumbent counter</span> value is one, however, so we fall back
106365+
to the <span>backup incumbent realm stack</span>.
106366+
This gives us the <span>realm</span> of <code data-x="">a.html</code>, as expected.</p>
106370106367

106371106368
<p>Note that this means that even though it is the <code>iframe</code> inside <code
106372106369
data-x="">a.html</code> that navigates, it is <code data-x="">a.html</code> itself that is used
@@ -109569,14 +109566,14 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
109569109566
<ref>JAVASCRIPT</ref></p>
109570109567

109571109568
<ol>
109572-
<li><p>Let <var>incumbent settings</var> be
109573-
<var>callback</var>.[[HostDefined]].[[IncumbentSettings]].</p></li>
109569+
<li><p>Let <var>incumbent realm</var> be
109570+
<var>callback</var>.[[HostDefined]].[[IncumbentRealm]].</p></li>
109574109571

109575109572
<li><p>Let <var>script execution context</var> be
109576109573
<var>callback</var>.[[HostDefined]].[[ActiveScriptContext]].</li>
109577109574

109578109575
<li>
109579-
<p><span>Prepare to run a callback</span> with <var>incumbent settings</var>.</p>
109576+
<p><span>Prepare to run a callback</span> with <var>incumbent realm</var>.</p>
109580109577

109581109578
<p class="note">This affects the <span data-x="concept-incumbent-everything">incumbent</span>
109582109579
concept while the callback runs.</p>
@@ -109597,8 +109594,7 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
109597109594
pop">pop</span> <var>script execution context</var> from the <span>JavaScript execution context
109598109595
stack</span>.</p></li>
109599109596

109600-
<li><p><span>Clean up after running a callback</span> with <var>incumbent
109601-
settings</var>.</p></li>
109597+
<li><p><span>Clean up after running a callback</span> with <var>incumbent realm</var>.</p></li>
109602109598

109603109599
<li><p>Return <var>result</var>.</p></li>
109604109600
</ol>
@@ -109788,7 +109784,8 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
109788109784
<ref>JAVASCRIPT</ref></p>
109789109785

109790109786
<ol>
109791-
<li><p>Let <var>incumbent settings</var> be the <span>incumbent settings object</span>.</p></li>
109787+
<li><p>Let <var>incumbent realm</var> be the <span data-x="concept-incumbent-realm">incumbent
109788+
realm</span>.</p></li>
109792109789

109793109790
<li><p>Let <var>active script</var> be the <span>active script</span>.</p></li>
109794109791

@@ -109841,7 +109838,7 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
109841109838
</li>
109842109839

109843109840
<li><p>Return the <span>JobCallback Record</span> { [[Callback]]: <var>callable</var>,
109844-
[[HostDefined]]: { [[IncumbentSettings]]: <var>incumbent settings</var>, [[ActiveScriptContext]]:
109841+
[[HostDefined]]: { [[IncumbentRealm]]: <var>incumbent realm</var>, [[ActiveScriptContext]]:
109845109842
<var>script execution context</var> } }.</p></li>
109846109843
</ol>
109847109844

0 commit comments

Comments
 (0)