Skip to content

Commit

Permalink
Remove importMetaHook
Browse files Browse the repository at this point in the history
Fixes #54

The importMetaHook is superfluous if static module records reveal needsImportMetaHook.  The decision of whether to build out importMeta can be made in loadHook.
  • Loading branch information
kriskowal committed Jun 14, 2022
1 parent 2a3ff79 commit e85c4c4
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ type Binding =
// The bindings correspond to the equivalent `import` and `export` declarations
// of an ECMAScript module.
type SyntheticStaticModuleRecord = {
// Indicates the import and export bindings the module has
// between its module environment record, module exports namespace,
// and its dependencies.
bindings?: Array<Binding>,

// Initializes the module if it is imported.
// Initialize may return a promise, indicating that the module uses
// the equivalent of top-level-await.
Expand All @@ -159,9 +163,11 @@ type SyntheticStaticModuleRecord = {
import?: (importSpecifier: string) => Promise<ModuleExportsNamespace>,
importMeta?: Object
}) => void,

// Indicates that initialize needs to receive a dynamic import function that
// closes over the referrer module specifier.
needsImport?: boolean,

// Indicates that initialize needs to receive an importMeta.
needsImportMeta?: boolean,
};
Expand All @@ -177,6 +183,13 @@ interface StaticModuleRecord {
// Static module records reflect their bindings for information only.
// Compartments use internal slots for the compiled code and bindings.
bindings: Array<Binding>;

// Indicates that initialize needs to receive a dynamic import function that
// closes over the referrer module specifier.
needsImport?: boolean,

// Indicates that initialize needs to receive an importMeta.
needsImportMeta?: boolean,
}

// A ModuleDescriptor captures a static module record and per-compartment metadata.
Expand All @@ -198,8 +211,6 @@ type ModuleDescriptor =
// * If the module descriptor has an `importMeta` property, the compartment
// will copy the own properties of the descriptor's `importMeta` over
// the compartment's `importMeta' using `[[Set]]`.
// * If the compartment has an `importMetaHook`, it will call
// `importMetaHook(fullSpecifier, importMeta)`.
// The compartment will then begin initializing the module.
// The compartment memoizes a promise for the module exports namespace
// that will be fulfilled at a time already defined in 262 for dynamic import.
Expand Down Expand Up @@ -346,19 +357,6 @@ type CompartmentConstructorOptions = {
// Note: This name differs from the implementation of SES shim and a
// prior revision of this proposal, where it is currently called `importHook`.
loadHook?: (fullSpecifier: string) => Promise<ModuleDescriptor?>

// A ModuleDescriptor can have an `importMeta` property.
// The compartment assigns these properties over the true `import.meta`
// object for the module instance.
// That object in turn has a null prototype.
// However some properties of `import.meta` are too expensive for a host
// to instantiate for every module, like Node.js's `import.meta.resolve`,
// which can be avoided for modules that never utter `import.meta`
// in their sources.
// This hook gets called for any module that utters `import.meta`,
// so some work can be deferred until just before the compartment
// initializes the module.
importMetaHook?: (fullSpecifier: string, importMeta: Object) => void,
};

interface Compartment {
Expand Down

0 comments on commit e85c4c4

Please sign in to comment.