endojs / endo

Endo is a distributed secure JavaScript sandbox, based on SES
Apache License 2.0
831 stars 72 forks source link

feat(ses,module-source): Dynamic import #2639

Closed kriskowal closed 9 hours ago

kriskowal commented 6 days ago

Closes: #291

Description

This change adds support for dynamic import to ses and @endo/module-source, such that import(x) in the scope of a module loaded from source (using ModuleSource in a Compartment module loading hook).

Security Considerations

This change builds on prior work to ensure that dynamic import is facilitated by a hidden lexical name injected by ses. The dynamic import mechanism is isolated to the surrounding compartment and specifiers are resolved on the surrounding module.

Scaling Considerations

This change introduces a static analysis for the presence of a dynamic import in the module source, which it communicates on the module source, even if marshaled through JSON, to ses that it should create an import closure bound to the calling module’s base specifier. This avoids an allocation for most modules.

Documentation Considerations

Only news included. Dynamic import is a language feature that is expected to work in general and documented where JavaScript is documented as a language.

Testing Considerations

This change includes a minimal happy path test that verifies that dynamic import produces a promise that settles on a module namespace object. Note that dynamic import does not box namespaces regardless of the __noNamespaceBox__ compartment option.

Compatibility Considerations

Backward compatible.

Upgrade Considerations

None.