leobalter / shadowrealms-polyfill

MIT License
57 stars 0 forks source link

Import for modules that have no exported bindings #15

Open mhofman opened 3 years ago

mhofman commented 3 years ago

Not all modules have exported bindings. In particular, a "regular" script can be executed as a module if it is strict mode compatible, doesn't assume a shared scope with other scripts and doesn't use a top-level this as global.

One way to support this subset of modules and scripts would be to execute them through an importBinding equivalent without a binding name. Combined with the getGlobalPropertyValue addition I suggested in https://github.com/leobalter/realms-polyfill/issues/5#issuecomment-807493424, it would also make eval unnecessary for these scripts.

Related to the open question "Should a missing binding reject the importBinding promise?", since by definition such modules wouldn't have any bindings, so rejecting would be a problem.

leobalter commented 3 years ago

The realms proposal has been historically facing some implementation challenges blocking it to advance to Stage 3.

The current low level API is good enough to have a membrane system plugged in. I'd like to explore these extensions as follow up proposals only.

The importBinding intentionally requires a binding to avoid propagation of meaningless import and without encouraging one to share values through the global.

As follow up proposals we need to explore three forms, at least:

There are open questions for all of them, and they all look like nice to have within their own complexity budget.

Setting a low level API that enables Realms to work if the first goal, and I'd love to unblock this first.