Skip to content

Normative: **Non-injective** ModuleSource identity#62

Open
guybedford wants to merge 2 commits into
mainfrom
module-object-identity-non-injective
Open

Normative: **Non-injective** ModuleSource identity#62
guybedford wants to merge 2 commits into
mainfrom
module-object-identity-non-injective

Conversation

@guybedford
Copy link
Copy Markdown
Collaborator

#58 formalizes the module source identity requirement as presented at the last meeting, based on the host invariant formalization in #59.

This is a follow-on PR that removes the injective behaviour of module sources.

This was an early design decision for module source transfer, that if we had a module source for a module at /foo.js, passing that module source into a worker, and importing its source object, would allow it to be imported by URL afterwards to get the same instance:

const fooSource = receiveSourceFromMainThread();
const instance = await import(fooSource);
await import('/foo.js') === instance // TRUE

The way this works is that importing the source object performs an injection into the module registry of the worker, provided no URL was previously defined at that key.

The reason this was designed from the start was to ensure cycles, for example if /foo.js imports /bar.js and /bar.js then imports back to /foo.js. If the URL was not present in the registry (only the source object), then we would get two instances for foo - one for the foo source, and one for the /foo.js URL fetched from the worker separately to the one transferred and serialized.

In recent conversations and at the last module harmony meeting it was brought up that we should make sure we have talked through this constraint one last time.

The injective behaviour is racy - if the URL already existed, it would not be injected, and you would have separate instances for import(fooSource) and import('/foo.js') in the worker context.

This PR shows that the spec change also leads to a simplification on the host normative constraint as it doesn't then need to specify the injective ordered behaviours.

We have not yet come to a conclusion over which behaviour would be preferable, so I wanted to post this for further discussion.

@guybedford guybedford force-pushed the module-object-identity-non-injective branch 2 times, most recently from 6a9233e to 0a162de Compare April 25, 2026 01:02
@guybedford guybedford force-pushed the module-object-identity-non-injective branch from 0a162de to c8436c4 Compare April 25, 2026 01:06
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me, as discussed in the modules harmony meeting I am ok with this different resolution to the trade off between raciness and cycles handling.

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

Successfully merging this pull request may close these issues.

2 participants