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

Receive the module instance in importMetaHook? #13

Open
Jack-Works opened this issue May 24, 2020 · 7 comments
Open

Receive the module instance in importMetaHook? #13

Jack-Works opened this issue May 24, 2020 · 7 comments

Comments

@Jack-Works
Copy link
Member

Jack-Works commented May 24, 2020

Example:

const x = new Compartment({
    // ...
    importMetaHook(fullSpec, meta, moduleInsance) {
        meta.url = fullSpec
        meta.self = moduleInstance
    }
})
await x.import("/index")
// {url: "/index", self: Module }
@erights
Copy link
Collaborator

erights commented May 24, 2020

See https://github.com/tc39/proposal-realms/issues/244#issuecomment-633180485

The Compartment proposal has an importMetaHook. This hook is expected to stay in the Compartment proposal, as it relates (loosely) to importing.

@leobalter leobalter transferred this issue from tc39/proposal-shadowrealm May 28, 2020
@Jack-Works Jack-Works changed the title HostFinalizeImportMeta hook Receive the module instance in importMetaHook? Jun 9, 2022
@Jack-Works
Copy link
Member Author

I have updated the issue to reflect the latest compartment API.

@kriskowal
Copy link
Member

Do you mean ModuleExportsNamespace? What’s a motivating use-case? That is, how would this feature be used?

@Jack-Works
Copy link
Member Author

Example:

const x = new Compartment({
    // ...
    importMetaHook(fullSpec, meta, moduleInsance) {
        meta.url = fullSpec
        meta.self = moduleInstance
    }
})
await x.import("/index")
// {url: "/index", self: Module }

This is my motivating use case although it is not common.

@kriskowal
Copy link
Member

Do you mean to build a Map of all the compartment’s instances by their full specifier? Do you need a reified instance or do you need the module exports namespace?

@kriskowal
Copy link
Member

kriskowal commented Jun 10, 2022

The case seems incomplete, since the object resolved by import is the module exports namespace (so presumably the module in question exports url and self, like export const url = import.meta.url). So, I’ll infer that you do in fact need a reified module instance object. To my knowledge, the only use you’d have for that would be to get the namespace or maybe the environment record.

What would you go on to do with these objects?

@Jack-Works
Copy link
Member Author

const x = new Compartment({
    // ...
    importMetaHook(fullSpec, meta, moduleInsance) {
        meta.url = fullSpec
        meta.self = moduleInstance
    }
})
await x.import("/index")

/index

export const x = 1
import.meta.self.x = 1;
(await import('/index')) === import.meta.self

Yes, I agree this use case does not look so compelling so maybe we can ignore it.

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