feat(ses,module-source): Dynamic import #2639
Open
+74
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #291
Description
This change adds support for dynamic
import
toses
and@endo/module-source
, such thatimport(x)
in the scope of a module loaded from source (usingModuleSource
in aCompartment
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, toses
that it should create animport
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.