Skip to content

Commit 8d70e26

Browse files
authored
Slide refinement (#8)
1 parent 6c74e9a commit 8d70e26

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

slides/slides.md

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,40 @@ Minimal addition to the spec sufficient for implementing various ideas around li
2020

2121
---
2222

23-
## Differences with other approaches
24-
25-
_Compared to Shadow Realm or exposing an Isolate factory_
26-
27-
<!-- - not introducing a new category of a global object, but allowing replicating the existing one -->
28-
29-
- minimize intersection with the web standards
30-
- enables isolation that doesn't undermine synchronous communication and shared prototypes
31-
- avoids adding new concepts, reuses existing `Global` concept, allows replicas.
32-
- 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-
3623
## Motivation
3724

3825
- Domain Specific Languages
3926
- Test runners
27+
- Shim builtin modules
4028
- Principle of Least Authority (Compartment)
4129
- Emulating another host
4230
- Isolation of unreliable code (AI)
4331

4432
---
4533

34+
## Tentative design
35+
36+
```js
37+
const newGlobal = new globalThis.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+
4657
### Example - DSL
4758

4859
```js
@@ -156,9 +167,9 @@ We are bringing up the details for feedback
156167

157168
### Details
158169

159-
- allows mutating `(new Global()).globalThis` before evaluation
170+
- allows mutating `new globalThis.Global()` before evaluation
160171
- 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.
162173

163174
```js
164175
Reflect.getIntrinsic("%AsyncFunction%") !==
@@ -249,9 +260,15 @@ fs1 === fs2; // if present
249260

250261
### Intersection semantics with Content Security Policy
251262

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.
253264

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.
266+
267+
```js
268+
globalThis.import(source);
269+
// to be equivalent to
270+
globalThis.eval('s => import(s)')(source);
271+
```
255272

256273
---
257274

@@ -279,14 +296,34 @@ const fs = await newGlobal.eval('import("node:fs"))');
279296

280297
---
281298

299+
#### Import hook on ModuleSource
300+
301+
```js
302+
const source = new ModuleSource(`
303+
import "node:fs";
304+
`, {
305+
importHook(specifier, attributes) {
306+
const specifier = new URL(importSpecifier, this.url).href;
307+
return import.source(specifier);
308+
// or
309+
return import(specifier);
310+
// or
311+
return new ModuleSource('');
312+
},
313+
url: import.meta.url;
314+
});
315+
```
316+
317+
---
318+
282319
```js
283-
const globalThat = new Global({
320+
const newGlobal = new Global({
284321
importHook(specifier) {
285322
log(`global ${specifier}`);
286323
return new ModuleSource("");
287324
},
288325
});
289-
const source = new globalThat.ModuleSource(
326+
const source = new ModuleSource(
290327
`
291328
import 'static-import'; // local static-import
292329
eval('import("direct-eval-import")'); // local direct-eval-import
@@ -296,8 +333,9 @@ const source = new globalThat.ModuleSource(
296333
{
297334
importHook(specifier) {
298335
log(`local ${specifier}`);
336+
return new ModuleSource("");
299337
},
300338
}
301339
);
302-
await import(source);
340+
await newGlobal.eval('s => import(s)')(source);
303341
```

slides/slides.pdf

-87.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)