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
- while use cases may seem similar, this proposal being same-realm and avoiding duplicating large objects should allow more granular isolation/encapsulation
33
-
34
-
---
35
-
36
23
## Motivation
37
24
38
25
- Domain Specific Languages
39
26
- Test runners
27
+
- Shim builtin modules
40
28
- Principle of Least Authority (Compartment)
41
29
- Emulating another host
42
30
- Isolation of unreliable code (AI)
43
31
44
32
---
45
33
34
+
## Tentative design
35
+
36
+
```js
37
+
constnewGlobal=newglobalThis.Global();
38
+
```
39
+
40
+
Introduce a level of indirection between _Execution Context_ and _Realm_ called _Global_ that intercepts or relieves the _Realm_ of its [[GlobalObject]], [[TemplateMap]], and [[LoadedModules]] such that multiple _Globals_ can share a realm and _most_ of their [[Intrinsics]].
41
+
42
+
_This is the only remaining language mechanism necessary to isolate scripts and ESM, with the assistance of JavaScript user code._
43
+
44
+
---
45
+
46
+
## Differences with other approaches
47
+
48
+
_Compared to Shadow Realm or exposing an Isolate factory_
49
+
50
+
- minimize intersection with the web standards
51
+
- enables isolation that doesn't undermine synchronous communication and shared prototypes
52
+
- avoids introducing a new kind of global object, instead enabling the creation of shallow copies
53
+
- while use cases may seem similar, this proposal being same-realm and avoiding duplicating large objects should allow finer-grain isolation/encapsulation
54
+
55
+
---
56
+
46
57
### Example - DSL
47
58
48
59
```js
@@ -156,9 +167,9 @@ We are bringing up the details for feedback
156
167
157
168
### Details
158
169
159
-
- allows mutating `(new Global()).globalThis` before evaluation
170
+
- allows mutating `new globalThis.Global()` before evaluation
160
171
- by default copy all properties from `globalThis`
161
-
- properties: `Global` and all evaluators have their internal slots relating them to the new _global_, that includes all `*Function` slots.
172
+
- properties: `Global` and all evaluators have their internal slots relating them to the new _global_, that includes all [[\*Function]] slots.
162
173
163
174
```js
164
175
Reflect.getIntrinsic("%AsyncFunction%") !==
@@ -249,9 +260,15 @@ fs1 === fs2; // if present
249
260
250
261
### Intersection semantics with Content Security Policy
251
262
252
-
They have been resolved by ESM source phase imports proposal with `ModuleSource`.
263
+
Globals do not alter any of the mechanism established by ESM Source Phase Imports (Stage 2.7), which enables web hosts to deny evaluation of module sources.
253
264
254
-
<!-- TODO: reveal dynamic import making ModuleSource usable within a new Global without `unsafe-eval`, preferably by global.import -->
265
+
But, for `no-unsafe-eval`, we would ask to expose first-class `import` on all global objects.
0 commit comments