Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript ShadowRealm proposal integration #9893

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
afc1353
Editorial: make 'module type allowed' take a realm
Ms2ger Sep 19, 2024
002d9fa
Editorial: replace the settings object field in scripts by a realm field
Ms2ger Sep 19, 2024
3d1c1f2
Editorial: redefine scripting enabled/disabled in terms of realms
Ms2ger Nov 16, 2023
b49562c
Editorial: create CSS/JSON modules with realm
Ms2ger Nov 16, 2023
f1dbdc6
Editorial: create JS modules with realm
Ms2ger Nov 16, 2023
50f5d5c
Editorial: create WebAssembly modules with realm
Ms2ger Sep 20, 2024
e14e94d
Editorial: use a realm in resolve a module specifier
Ms2ger Nov 18, 2024
d5286dc
Editorial: pass a realm to 'creating a classic script'
Ms2ger Feb 7, 2024
9e9543b
Editorial: use realms in check if we can run script
Ms2ger Sep 25, 2024
1beeb82
Editorial: don't go through the settings object to report an exceptio…
Ms2ger Sep 26, 2024
84c282f
Editorial: use realms in prepare to run script/clean up after running…
Ms2ger Sep 25, 2024
698addf
Editorial: use realms around 'incumbent'
Ms2ger Sep 25, 2024
eba56c6
Editorial: use realm in HostPromiseRejectionTracker
Ms2ger Sep 26, 2024
dbd4eef
JavaScript ShadowRealm proposal integration
Ms2ger Sep 25, 2024
e976653
Fetch modules directly for ShadowRealms
Ms2ger Nov 16, 2023
8131d27
Start defining ShadowRealmGlobalObject
Ms2ger Dec 13, 2023
4fc8be2
Add link
Ms2ger Dec 15, 2023
5990402
Review
Ms2ger Jan 18, 2024
6e859ee
Better layering for the mutable global prototype chain
Ms2ger Dec 20, 2023
06b190b
Rephrase
Ms2ger Jan 11, 2024
f788ca6
Add context argument to HostInitializeShadowRealm
Ms2ger Jan 31, 2024
097b31b
Rename ShadowRealmGlobalObject
Ms2ger Jan 18, 2024
8f37b91
Add atob, btoa, structuredClone to shadow realms
Ms2ger Jan 18, 2024
d8e1594
Add queueMicrotask
Ms2ger Feb 7, 2024
20bae79
Indentation
Ms2ger Feb 7, 2024
b1021fe
Rename WindowOrWorkerOrShadowRealmGlobalScope to UniversalGlobalScope
Ms2ger Sep 24, 2024
01e83bb
review
Ms2ger Oct 8, 2024
0dc0ee4
Review
Ms2ger Oct 22, 2024
9e48745
review
Ms2ger Oct 22, 2024
ea3c573
Restructure HostInitializeShadowRealm
Ms2ger Nov 4, 2024
7660208
Indentation
Ms2ger Nov 18, 2024
f5194b0
Fix
Ms2ger Nov 19, 2024
873cd6d
Remove unnecessary concept
Ms2ger Nov 19, 2024
f896319
queueing
Ms2ger Nov 20, 2024
eff546f
Better guidance and sectioning
Ms2ger Nov 21, 2024
dc9fddc
Improve the global object creation
Ms2ger Nov 21, 2024
f0e4ee6
Rephrase
nicolo-ribaudo Nov 21, 2024
c8d1b45
address comment
Ms2ger Nov 21, 2024
a12d85e
Note
Ms2ger Nov 21, 2024
2039fa1
link ShadowRealmGlobalScope
Ms2ger Nov 26, 2024
0f65b04
event handlers
Ms2ger Nov 26, 2024
9aece76
Add reportError
Ms2ger Nov 26, 2024
8cf3150
isSecureContext
Ms2ger Nov 26, 2024
acb7665
Fix base url in module specifier resolution
Ms2ger Nov 27, 2024
7449ee0
Fix HostInitializeShadowRealm
Ms2ger Nov 27, 2024
a2fe477
relevant principal *
Ms2ger Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Editorial: use realms around 'incumbent'
  • Loading branch information
Ms2ger committed Nov 18, 2024
commit 698addf13c2287899c3bb466833c968373420fc4
154 changes: 75 additions & 79 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -106766,23 +106766,23 @@ new PaymentRequest(…); // Allowed to use
callback">cleaning up after running a callback</span>, this value will be incremented and
decremented.</p>

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

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

<p>To <dfn export>prepare to run a callback</dfn> with an <span>environment settings object</span>
<var>settings</var>:</p>
<p>To <dfn export>prepare to run a callback</dfn> with a <span>realm</span> <var>realm</var>:</p>

<ol>
<li><p>Push <var>settings</var> onto the <span>backup incumbent settings object
stack</span>.</p></li>
<li><p>Push <var>realm</var> onto the <span>backup incumbent realm stack</span>.</p></li>

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

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

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

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

<li><p>Remove <var>settings</var> from the <span>backup incumbent settings object
stack</span>.</p></li>
<li><p>Remove <var>realm</var> from the <span>backup incumbent realm stack</span>.</p></li>
</ol>

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

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

<ol>
<li><p>Let <var>context</var> be the <span>topmost script-having execution
Expand All @@ -106830,31 +106829,29 @@ new PaymentRequest(&hellip;); // Allowed to use

<ol>
<li>
<p><span>Assert</span>: the <span>backup incumbent settings object stack</span> is not
empty.</p>

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

<p class="note">This assert would fail if you try to obtain the <span
data-x="concept-incumbent-realm">incumbent realm</span> from inside an algorithm that was
triggered neither by <a href="#calling-scripts">calling scripts</a> nor by Web IDL <span
data-x="es-invoking-callback-functions">invoking</span> a callback.
For example, it would trigger if you tried to obtain the <span
data-x="concept-incumbent-realm">incumbent realm</span> inside an algorithm that ran
periodically as part of the <span>event loop</span>, with no involvement of author code.
In such cases the <span data-x="concept-incumbent-everything">incumbent</span> concept cannot
be used.</p>
</li>

<li><p>Return the topmost entry of the <span>backup incumbent settings object
stack</span>.</p></li>
<li><p>Return the topmost entry of the <span>backup incumbent realm stack</span>.</p></li>
</ol>
</li>

<li><p>Return <var>context</var>'s Realm component's <span
data-x="concept-realm-settings-object">settings object</span>.</p></li>
<li><p>Return <var>context</var>'s Realm component.</p></li>
</ol>

<p>Then, the <dfn export data-x="concept-incumbent-realm">incumbent realm</dfn> is the <span
data-x="environment settings object's realm">realm</span> of the <span>incumbent settings
object</span>.</p>
<p>Then, the <dfn export>incumbent settings object</dfn> is the
<span data-x="concept-incumbent-realm">incumbent realm</span>'s
<span data-x="concept-realm-settings-object">settings object</span>.</p>

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

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

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

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

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

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

<div class="example" id="example-incumbent-3">
Expand All @@ -106979,21 +106977,21 @@ document.querySelector("button").addEventListener("click", bound);
};
&lt;/script></code></pre>

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

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

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

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

<p>Note that this means that even though it is the <code>iframe</code> inside <code
data-x="">a.html</code> that navigates, it is <code data-x="">a.html</code> itself that is used
Expand Down Expand Up @@ -110551,14 +110548,14 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
<ref>JAVASCRIPT</ref></p>

<ol>
<li><p>Let <var>incumbent settings</var> be
<var>callback</var>.[[HostDefined]].[[IncumbentSettings]].</p></li>
<li><p>Let <var>incumbent realm</var> be
<var>callback</var>.[[HostDefined]].[[IncumbentRealm]].</p></li>

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

<li>
<p><span>Prepare to run a callback</span> with <var>incumbent settings</var>.</p>
<p><span>Prepare to run a callback</span> with <var>incumbent realm</var>.</p>

<p class="note">This affects the <span data-x="concept-incumbent-everything">incumbent</span>
concept while the callback runs.</p>
Expand All @@ -110579,8 +110576,7 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
pop">pop</span> <var>script execution context</var> from the <span>JavaScript execution context
stack</span>.</p></li>

<li><p><span>Clean up after running a callback</span> with <var>incumbent
settings</var>.</p></li>
<li><p><span>Clean up after running a callback</span> with <var>incumbent realm</var>.</p></li>

<li><p>Return <var>result</var>.</p></li>
</ol>
Expand Down Expand Up @@ -110770,7 +110766,7 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
<ref>JAVASCRIPT</ref></p>

<ol>
<li><p>Let <var>incumbent settings</var> be the <span>incumbent settings object</span>.</p></li>
<li><p>Let <var>incumbent realm</var> be the <span>incumbent realm</span>.</p></li>

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

Expand Down Expand Up @@ -110822,7 +110818,7 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
</li>

<li><p>Return the <span>JobCallback Record</span> { [[Callback]]: <var>callable</var>,
[[HostDefined]]: { [[IncumbentSettings]]: <var>incumbent settings</var>, [[ActiveScriptContext]]:
[[HostDefined]]: { [[IncumbentRealm]]: <var>incumbent realm</var>, [[ActiveScriptContext]]:
<var>script execution context</var> } }.</p></li>
</ol>

Expand Down