tc39 / proposal-shadowrealm

ECMAScript Proposal, specs, and reference implementation for Realms
https://tc39.es/proposal-shadowrealm/
1.43k stars 67 forks source link

Informal meeting notes from breakout session about Realms #52

Closed caridy closed 4 years ago

caridy commented 7 years ago

Attendies: @dherman @erights @wycats @caridy

Notes

The formalization of the realm concept (tiling process from @dherman):

Realm's Configuration:

Realm's Responsibilities:

Realm's Features:

Examples

Some of the configuration

const r = new Realm({
  intrinsics: "inherit", // or maybe "parent"
  importHook: "inherit",
  importMetaHook: "inherit",
  evalHook: "inherit",
  isDirectEval: "inherit",
});

In the previous example, the Realm instance r is effectible a new scope since it will inherit all the hooks and all the intrinsics from the parent realm, but creates a new global object and a new this value, and allow evaluations bound to those values without introducing identity discontinuity, and delegating to the HOST behavior for import() calls.

Similarity, each of those configurations can be customized:

Open questions

caridy commented 7 years ago

Open questions

caridy commented 7 years ago

adbf4b088b89c8aea1ed8f37e3d4dac604a7ec06 implements the intrinsics option and the "inherit" value for all hooks.

erights commented 6 years ago

"inherits" or not

Experience with the realms shim shows that piecemeal control of inherit-vs-make on individual issues is not a coherent start point. Rather, we need an explicit distinction between "root realms" vs "compartments" as some realm concepts must be per-root-realm and some must be per-compartment.

intrinsics

A terrible way to customize as cross realm leakage is too accident prone. A better starting mechanism is to run shim strings within each root realm on initialization, as the shim now does. This does leave the residual problem of endowments coming on from the defenseless feral world, which still needs good support for taming. See @ihab 's taming membrane at https://github.com/google/caja/tree/master/src/com/google/caja/apitaming .

importMetaHook

By the current design, realms does not deal directly with the issues of evaluating module code, but rather provides only a bridge to a separate module api. import.meta can only appear in module code. Thus, the importMetaHook should move from realms into this hypothetical but coupled module evaluation api.

evalHook

Should be renamed directEvalHook or something, so that it clearly applies only to direct eval. The current name caused much confusion. Also, the make should reflect that the hook is called to translate rather than to evaluate.

all are implementation limits for shim anyway

Just noting that none of these hooks can reasonably be implemented by the shim without an accurate parser, which would make the shim tremendously larger and more fragile. Rather, they should all be considered implementation limits of the shim as compared to the proposal. Nevertheless, without these, the shim is sufficient for most of the use cases that motivated the creations of the realms proposal.

erights commented 6 years ago

Missed:

importHook

Since this applies only to the import expression as evaluated in non-module code, it should have a name that is less confusing.

caridy commented 4 years ago

Most of the information here is about hooks, which are now features of the evaluator.