Skip to content

Commit

Permalink
Add motivating example for host defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Jun 10, 2022
1 parent ce4c4e5 commit 54c2c13
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,35 @@ interface Compartment {
}
```

### Design Rationales
## Motivating Examples and Design Rationales

### Multiple-instantiation

This example illustrates the use of a new compartment to support multiple
instantiation of modules, reusing the host's compartment and static module record
memos as a cache.
This example creates five instances of the example module and its transitive
dependencies.

```js
for (let i = 0; i < 5; i += 1) {
new Compartment().import('https://example.com/example.js');
}
```

Assuming that the language separately adopted hypothetical `import static`
syntax to defer execution but load a module and its transitive dependencies, a
bundler would be able to observe the need to capture the example module and its
transitive dependencies, such that the *only* instances are in guest compartments.

```js
import static 'https://example.com/example.js';
for (let i = 0; i < 5; i += 1) {
new Compartment().import('https://example.com/example.js');
}
```

### Thenable Module Hazard

An exported value named `then` can be statically imported, but dynamic import
confuses the module namespace for a thenable object.
Expand Down

0 comments on commit 54c2c13

Please sign in to comment.