Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe object model of module block instances. #2

Merged
merged 1 commit into from
Oct 9, 2020

Conversation

littledan
Copy link
Member

Also clarify some other minor points

Also clarify some other minor points
Copy link
Member

@surma surma left a comment

Choose a reason for hiding this comment

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

LGTM (but one Q for clarification)

@@ -76,6 +76,12 @@ addEventListener("message", async ({data}) => {
});
```

## `ModuleBlock` object model

A module block expression `module { }` evaluates to an instance of a `ModuleBlock` class. Instances are frozen, and the same instance is returned each time for a particular Parse Node, like tagged template literals. `Module` instances have an internal slot [[ModuleBlockHostData]]. This internal slot is filled in by the host in a new host hook called when parsing each module block. (Alternative: A fresh, mutable `ModuleBlock` is returned each time the `module { }` is evaluated, with the same [[ModuleBlockHostData]] each time.) In `import()`, if the parameter has a [[ModuleBlockHostData]] internal slot, it is passed up as is to the dynamic import host hook, and ToString is only called on other values without this slot.
Copy link
Member

Choose a reason for hiding this comment

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

Question: Which, if any, of these assertions throw?

const arr = new Array(2);
for(i = 0; i < arr.length; i++) {
  arr[i] = module {export default 4};
}
console.assert(arr[0] == arr[1]); // ?
console.assert(await import(arr[0]) == await import(arr[1])); // ?

const m1 = module {export default 4};
const m2 = module {export default 4};
console.assert(m1 == m2); // ?
console.assert(await import(m1) == await import(m2)); // ?

Copy link
Member

Choose a reason for hiding this comment

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

(and should we add this code sample to clarify?)

Copy link
Member Author

Choose a reason for hiding this comment

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

With the main option, the last two asserts would throw. With the alternate, the first assertion would throw as well. But all agree that the second assertion does not throw.

Code samples could be great here. Do you think you could push the appropriate clarifications to all of this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Strong preference for no caching behavior, i.e. each module { } evaluation resulting in a new instance.

@surma surma merged commit f8d3d42 into tc39:master Oct 9, 2020
@littledan littledan mentioned this pull request Oct 16, 2020
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.

3 participants