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

Layer 0: Replace importMeta object with importMetaHook function #77

Closed
nicolo-ribaudo opened this issue Aug 19, 2022 · 3 comments
Closed

Comments

@nicolo-ribaudo
Copy link
Member

ECMA-262 exposes two host hooks to initialize import.meta: HostGetImportMetaProperties and HostFinalizeImportMeta.

  • HostGetImportMetaProperties doesn't receives any parameter and returns a list of properties, that ECMA-262 will copy on the import.meta object
  • HostFinalizeImportMeta receives the import.meta object, and can modify it as it wants

The second host hook is enough to cover all the use cases of the first hook, but not the other way around.

This proposal currently implements HostGetImportMetaProperties: the importMeta parameter of the Module constructor is equivalent to the list of properties returned by the hook. However, this is not enough to replicate the behavior of the various hosts:

With importMetaHook, both behaviors would be possible:

new Module(source, {
  importMetaHook(importMeta) {
    importMeta.url = someURL;
    Object.freeze(importMeta);
  }
});
new Module(source, {
  importMetaHook(importMeta) {
    importMeta.url = someURL;
    Object.setPrototypeOf(importMeta, ImportMetaPrototype);
  }
});

This has the same serializability implications of importHook: modules with a non-default importMetaHook would not be serializable.

@caridy
Copy link
Collaborator

caridy commented Aug 19, 2022

Few clarifications needed:

  1. is the argument passed into importMetaHook an ordinary object created by the engine, empty at first, and passed into the hook?
  2. If the answer to 1 is "yes", then what's the __proto__ of the importMeta object argument?
  3. how many times is this hook called? once and then cached as it is today for the host hooks?

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Aug 19, 2022

  1. yes
  2. I propose null, which is what is already happening with the host hook (so that by default import.meta objects have a null prototype): step 4.a of https://tc39.es/ecma262/#sec-meta-properties-runtime-semantics-evaluation
  3. Yes, it's cached per-module and only called when import.meta is evaluated the first time.

@caridy
Copy link
Collaborator

caridy commented Aug 19, 2022

I'm fine with this proposal.

@caridy caridy closed this as completed in b7899d1 Sep 23, 2022
caridy added a commit that referenced this issue Sep 23, 2022
fixes #77: importMetaHook and handler for options bag
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

No branches or pull requests

2 participants