tc39 / proposal-compartments

Compartmentalization of host behavior hooks for JS
MIT License
122 stars 10 forks source link

fixes #77: importMetaHook #78

Closed caridy closed 2 years ago

caridy commented 2 years ago

This PR removes the referral in favor of using handler argument, which is similar to a proxy handler, and can contain multiple hooks (only 2 for now, importHook and importMetaHook - we probably need better names).

This PR also implements the concepts of the default hooks, so the handler argument becomes optional.

This PR also covers https://github.com/tc39/proposal-compartments/issues/75

caridy commented 2 years ago

cc @nicolo-ribaudo

kriskowal commented 2 years ago

Notes from SES meeting today. Please consult the recording for context.

type handler = {
  // referrer?: string,
  importHook?: (specifier: string) => Module,
}
Module(source, handler)
Module[[Context]][[ImportHook]] provides the default importHook

In web page https://example.com:

<html>
<script type="module">
  new Module(`
    import 'foo.js'; // https://example.com/foo.js on the web
  `, {
    importHook: undefined // use default
  });
</script>
caridy commented 2 years ago

@nicolo-ribaudo thanks for the review... the changes are in.

caridy commented 2 years ago

@kriskowal now that this is merged, can you update the explainers and examples?

kriskowal commented 2 years ago

Absolutely. Forthcoming.