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

Non-normative layering fix for #59 #62

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 layering would be the preferable approach to the spec boundaries.

This change satisfies the branding requirement, while resolving the implementation feedback.

The new host hook provided to implement this new check is HostGetModuleSourceName which takes a module source object and returns its string value, throwing if it is not a module source object.

The strong branding of toStringTag is then retained by calling this hook.

nicolo-ribaudo commented 5 months ago

@guybedford I was thinking about what the host implementation of this hook would look like, and it introduces much more complexity than the current spec because it forces us to answer the question of "given a user-created WebAssembly.Module not coming from the module loader, what is the corresponding module record?". While answering this question might be possible (even though we probably don't agree yet on what the answer should be, not even in the modules harmony group), it requires discussing with multiple parties.

It might be better to keep this 1:1 with the current spec and instead have a HostGetModuleSourceClassName that just returns a string. We can keep the discussion of how to build a module record from an arbitrary source in the other proposal, that will need to do it.

guybedford commented 5 months ago

Thanks @nicolo-ribaudo for the excellent point here. Yes let's match the existing behaviour for now and tackle the larger questions for ESM source phase layering in due course.