Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kriskowal
Copy link
Member

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.

@@ -41,7 +42,7 @@ scaffold(
);
},
4,
{ knownFailure: true },
{ knownArchiveFailure: true },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not a polite way to say you should, just a note)
If you want to assert for both behaviors you could pass an assertion to scaffold that uses testCategoryHint to decide what to assert instead of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compartment support for dynamic import and importMetaHook
2 participants