You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -117,7 +123,7 @@ which leaks for the cases of syntactically undeniable Realm-specific intrinsics
117
123
like the `AsyncFunction` constructor and prototype, and requires the
118
124
implementer to be vigilant to the extent that they graft every intrinsic from
119
125
one realm to another.
120
-
We have found such arrangements to be fragile and leaky.
126
+
We have found such arrangements to be fragile and leaky. Also costly in memory efficiency and developer time.
121
127
122
128
New `Global` provide an alternate solution: evaluate modules or scripts in a
123
129
separate global scope with shared intrinsics.
@@ -172,6 +178,24 @@ TC53][tc53], do not have an origin on which to build a same-origin-policy, and
172
178
have elected to build their security model on isolated evaluators, through the
173
179
high-level Compartment interface.
174
180
181
+
### Isolating unreliable code
182
+
183
+
The way modern software is composed has already undermined the validity of the assumption that every author participating has their intentions well aligned for the benefit of the software working correctly. A whole new level of unreliability is now added with the popularity of _coding agents_ and _vibe coding_ where creating syntactically valid but effectively unpredictable JavaScript and integrating it into existing software to check whether it seems to implement the desired functionality is becoming a popular way of building software.
184
+
185
+
It is not an entirely new concern, as test runners have been concerned with isolating test cases to avoid them relying on global side-effects of other test cases. It is now a concern for a much wider audience with more at stake.
186
+
187
+
With `Global` constructor comes the ability to isolate fragments of the application in a way that unreliable code cannot rely on shared global state without the maintainer of the software knowing about it.
188
+
AI generated sources from independently working agents can come with colliding names for global variables to use and may need separate global scopes to collaborate or coexist. Similarly a misguided attempt at an inline polyfill by an AI or a package author could be prevented by freezing the contents of a new global in which the unreliable code subsequently runs.
189
+
Using a new global instead of a new Realm avoids the issues like identity discontinuity impeding the composition of software where function calls need to happen across the isolated and non-isolated code.
190
+
191
+
### Incremental or in-context execution
192
+
193
+
There are tools that currently use much more complex and costly mechanisms (similar to the ones described in [Domain Specific Languages](#domain-specific-languages) among other) to provide the ability to execute fragments of JavaScript code in a very specific context of the tool.
194
+
195
+
That includes REPLs, inline code execution results in editors (eg. [Quokka.js](https://quokkajs.com/)) and various use cases of IDEs in the browser.
196
+
197
+
Maintaining the global state between executions of user-provided code snippets would benefit from a `Global` constructor.
198
+
175
199
## Intersection Semantics
176
200
177
201
### Shared Structs
@@ -184,7 +208,7 @@ share any undeniable mutable state.
184
208
185
209
## Design Questions
186
210
187
-
### prototype chain in the browser
211
+
### rototype chain in the browser
188
212
189
213
`globalThis` in the browser has a non-trivial prototype chain for some Window
190
214
API functionality and events.
@@ -196,13 +220,13 @@ API functionality and events.
196
220
to invoke it.
197
221
198
222
```js
199
-
globalThis.constructor===Window
200
-
constg1=newGlobal()
223
+
globalThis.constructor===Window;
224
+
constg1=newGlobal();
201
225
202
-
g1.globalThis.constructor=== Global // would need to be true I suppose
203
-
g1.globalThis.constructor===g1.globalThis.Global// definitely not
0 commit comments