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
event handlers
  • Loading branch information
Ms2ger committed Nov 26, 2024
commit 0f65b040ee228014eb33885a679721bf23054b2e
23 changes: 20 additions & 3 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -111444,12 +111444,29 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
<pre><code class="idl">[Global]
interface <dfn interface>ShadowRealmGlobalScope</dfn> : <span>EventTarget</span> {
readonly attribute <span>ShadowRealmGlobalScope</span> <span data-x="dom-ShadowRealmGlobalScope-self">self</span>;
attribute <span>OnErrorEventHandler</span> <span data-x="handler-ShadowRealmGlobalScope-onerror">onerror</span>;
attribute <span>EventHandler</span> <span data-x="handler-WorkerGlobalScope-onrejectionhandled">onrejectionhandled</span>;
attribute <span>EventHandler</span> <span data-x="handler-WorkerGlobalScope-onunhandledrejection">onunhandledrejection</span>;
};</code></pre>

<p>The <dfn for="ShadowRealmGlobalScope" attribute><code
data-x="dom-ShadowRealmGlobalScope-self">self</code></dfn> getter steps are to return
<span>this</span>.</p>

<p>The following are the <span>event handlers</span> (and their corresponding <span data-x="event
handler event type">event handler event types</span>) <span w-nodev>that must be</span> supported,
Copy link
Contributor

@shannonbooth shannonbooth Nov 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally preferred the old steps for global object creation before dc9fddc as the steps if followed explicitly were more easily implementable without needing to add web specific changes into the javascript implementation. There is no clear hook for InitializeHostDefinedRealm to say that it is being invoked in the ShadowRealm constructor.

I think this type of customization should ideally be explicitly stated at the call site of HostInitializeShadowRealm, similar to how https://whatpr.org/html/9893/webappapis.html#creating-a-new-javascript-realm does where it is used like:

Let realm execution context be the result of creating a new realm given agent and the following customizations:

For the global object, create a new Window object.

For the global this binding, use browsingContext's WindowProxy object.

What makes this awkward is that HostInitializeShadowRealm is being invoked in JS spec, where we would like to make that customization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not great in terms of layering. I'm hoping tc39/ecma262#3497 and tc39/ecma262#3274 will get us somewhere better, and then we can do an editorial change to adjust to that.

as <span>event handler IDL attributes</span>, by objects implementing the
<code>ShadowRealmGlobalScope</code> interface:</p>

<table>
<thead>
<tr><th><span data-x="event handlers">Event handler</span> <th><span>Event handler event type</span>
<tbody>
<tr><td><dfn attribute for="ShadowRealmGlobalScope"><code data-x="handler-ShadowRealmGlobalScope-onerror">onerror</code></dfn> <td> <code data-x="event-error">error</code>
<tr><td><dfn attribute for="ShadowRealmGlobalScope"><code data-x="handler-ShadowRealmGlobalScope-onrejectionhandled">onrejectionhandled</code></dfn> <td> <code data-x="event-rejectionhandled">rejectionhandled</code>
<tr><td><dfn attribute for="ShadowRealmGlobalScope"><code data-x="handler-ShadowRealmGlobalScope-onunhandledrejection">onunhandledrejection</code></dfn> <td> <code data-x="event-unhandledrejection">unhandledrejection</code>
</table>

<h6>Creating a Shadow Realm</h6>

<p>When performing <span data-x="js-InitializeHostDefinedRealm">InitializeHostDefinedRealm</span>
Expand Down Expand Up @@ -113240,9 +113257,9 @@ interface <dfn interface>ShadowRealmGlobalScope</dfn> : <span>EventTarget</span>
<li><p>Let <var>special error event handling</var> be true if <var>event</var> is an
<code>ErrorEvent</code> object, <var>event</var>'s <code data-x="dom-Event-type">type</code> is
"<code data-x="event-error">error</code>", and <var>event</var>'s <code
data-x="dom-Event-currentTarget">currentTarget</code> implements the
<code>WindowOrWorkerGlobalScope</code> mixin. Otherwise, let <var>special error event
handling</var> be false.</p></li>
data-x="dom-Event-currentTarget">currentTarget</code> implements either the
<code>WindowOrWorkerGlobalScope</code> mixin or the <code>ShadowRealmGlobalScope</code>
interface. Otherwise, let <var>special error event handling</var> be false.</p></li>

<li>
<p>Process the <code>Event</code> object <var>event</var> as follows:</p>
Expand Down