Skip to content

Normative: Define Module Source object identity instead of source text registry identity#58

Open
guybedford wants to merge 4 commits intomainfrom
module-object-identity
Open

Normative: Define Module Source object identity instead of source text registry identity#58
guybedford wants to merge 4 commits intomainfrom
module-object-identity

Conversation

@guybedford
Copy link
Copy Markdown
Collaborator

@guybedford guybedford commented Mar 3, 2026

The current specification specifies that import(source1) and import(source2) must return the same instance whenever the URL key matches and ALSO the [[SourceText]] matches between these sources.

This design was justified based on:

  1. Defining a concept of instance identity that applies between realms (with an eye to structs proposal)
  2. Ensuring that transferring the same module source multiple times to the same agent and importing it would obtain the same instance every time

(2) is not actually such an important aspect of the design - in many cases with separate module source identities (such as sources created via transfer and structured clone), the better design is to support separate instancing and not to unify the instance. In addition it's kind of strange that two module declarations with exactly the same source text will always return the same instance namespace despite being different module declarations.

Given that (1) is not longer a design goal at this point, it is worth reconsidering if we still need this invariant or can instead simplify to this new model.

Previously for eval modules and the module declarations case we discussed ways of associating evaluation indexes for disambiguation between module sources created via eval paths, which would need to be used in coordination with the existing invariants. This complexity is hard to build test coverage on and therefore becomes an implementation risk as well.

By unifying on a simpler source object instancing model here (effectively treating the JS object identity of the source phase as the source key instead of the source text) that does not perform source text equality I think this provides a more intuitive and streamlined design that is less prone to implementation bugs.

In addition we fully define the source keying property that import(source) followed by import(id) where id is the string ID pointing to the same underlying module source as import(source) must return the same module instance. This is a key property, which requires the host invariant refactoring work in #59 to be able to define this based on the concept of a Canonical ModuleRequest Record.

// cc @nicolo-ribaudo

@guybedford guybedford changed the base branch from main to module-source March 3, 2026 20:58
@guybedford guybedford force-pushed the module-object-identity branch from 9db9e28 to 04af421 Compare March 3, 2026 21:12
@guybedford guybedford force-pushed the module-source branch 3 times, most recently from 00475a3 to 88811d7 Compare March 4, 2026 23:11
@guybedford guybedford force-pushed the module-object-identity branch 7 times, most recently from 85f5b89 to c9974d0 Compare March 5, 2026 01:27
@guybedford guybedford force-pushed the module-object-identity branch from c9974d0 to cb1a594 Compare March 5, 2026 02:34
guybedford added a commit to guybedford/test262 that referenced this pull request Mar 5, 2026
guybedford added a commit to guybedford/test262 that referenced this pull request Mar 5, 2026
guybedford added a commit to guybedford/test262 that referenced this pull request Mar 5, 2026
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.

I think this reasonable, and probably easier to implement.

@guybedford guybedford force-pushed the module-object-identity branch from cb1a594 to 5737c81 Compare March 10, 2026 15:56
Base automatically changed from module-source to main March 24, 2026 15:22
@guybedford guybedford force-pushed the module-object-identity branch from 5737c81 to 356538b Compare March 24, 2026 15:35
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