tc39 / proposal-source-phase-imports

Proposal to enable importing modules at the source phase
https://tc39.es/proposal-source-phase-imports/
MIT License
129 stars 9 forks source link

normative: isModuleSource, new host hook #61

Closed guybedford closed 5 months ago

guybedford commented 5 months ago

This addresses the implementation feedback in https://github.com/tc39/proposal-source-phase-imports/issues/59 that expecting an internal slot on objects that might not be defined in ECMA-262 poses implementation difficulties and that a new host hook would be the preferable approach to the spec boundaries.

This change satisfies the branding requirement, while resolving the implementation feedback. In addition, the new host hook is designed to support the latest design goals of the ESM phase imports proposal in https://github.com/tc39/proposal-esm-phase-imports, so that it can be used as a foundation for that work further.

The normative changes here are:

  1. toStringTag is no longer a defined on the AbstractModuleSource prototype but instead is a normal value on the AbstractModuleSource prototype. Subclasses can instead manage their own toStringTag (exactly as WebAssembly.Module does today).
  2. To satisfy the original branding requirement, a new static method AbstractModuleSource.isModuleSource(obj) is provided, which returns true or false if the given object is a module source instance.

Then the new host hook provided to implement this new check is HostGetModuleSourceRecord which takes a module source object and returns its original concrete module record or throws if it is not a module source object.

guybedford commented 5 months ago

Closing, since this is unnecessary given the alternative at this point.