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

Normative: Add JSON modules #3391

Merged
merged 1 commit into from
Feb 19, 2025
Merged

Normative: Add JSON modules #3391

merged 1 commit into from
Feb 19, 2025

Conversation

nicolo-ribaudo
Copy link
Member

This pull request builds on top of #3057.

I mostly ported the spec text as-is, taking care of integrating editorial changes from the PRs open in the repo, but I have a few comments / questions for the editors.

</emu-clause>

<emu-clause id="sec-smr-module-record-methods">
<h1>Implementation of Module Record abstract methods</h1>
Copy link
Member Author

Choose a reason for hiding this comment

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

Quoting a note from the original authors of the proposal:

I find having this wrapping sub-clause cleaner and suggest we do the same for Source Text Module Records in the main spec.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, they should match.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to open a PR to align Source Text Module Record to this, but I'll do it after that the import attributes PR is merged to avoid indentation conflicts.

@nicolo-ribaudo nicolo-ribaudo added pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4. labels Aug 14, 2024
@nicolo-ribaudo nicolo-ribaudo changed the title Add Import Attributes proposal Normative: Add JSON modules Aug 14, 2024
@nicolo-ribaudo nicolo-ribaudo added has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text labels Aug 14, 2024
spec.html Outdated
</dl>

<emu-alg>
1. Let _json_ be ? Call(%JSON.parse%, *undefined*, « _source_ »).
Copy link
Member Author

@nicolo-ribaudo nicolo-ribaudo Aug 14, 2024

Choose a reason for hiding this comment

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

Should steps 2-9 of JSON.parse be extracted to a new AO that we can call here, or is this ok?

Related: #1012 and https://infra.spec.whatwg.org/#parse-a-json-string-to-a-javascript-value

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mildly prefer the AO (after #3394 lands), but that refactoring can happen after this PR.

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Sep 24, 2024

@tc39/ecma262-editors Remember that this is going for stage 4 at the next meeting :)

@nicolo-ribaudo nicolo-ribaudo added has stage 4 This PR represents a proposal that has achieved stage 4, and is ready to merge. and removed pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. labels Oct 9, 2024
Copy link
Member

@michaelficarra michaelficarra left a comment

Choose a reason for hiding this comment

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

LGTM otherwise.

spec.html Outdated
<tr>
<td>[[EvaluationSteps]]</td>
<td>an Abstract Closure</td>
<td>The initialization logic to perform upon evaluation of the module, taking the Synthetic Module Record as its sole argument. These will usually set up the exported values, by using SetSyntheticModuleExport. It must not modify [[ExportNames]]. It may return an abrupt completion.</td>
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the use case for returning an abrupt completion?

Copy link
Member Author

@nicolo-ribaudo nicolo-ribaudo Feb 13, 2025

Choose a reason for hiding this comment

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

One would be, for example, for import "./x.cjs" Node.js: this would return a throw completion when the CommonJS module throws.

Note that even if we remove this possibility, you can emulate any synthetic module record with a Source Text Module Record by dynamically creating the source:

export let ...list of names...;

[[EvaluationSteps]]();

so whether it's there or not doesn't really affect host capabilities.

Both JSON modules and CSS modules always return a normal completion here.


Edit: The Node.js implementation of import "./foo.cjs" is at https://github.com/nodejs/node/blob/79f96b6e84428eb8ca5b9d4433e64bea31986628/lib/internal/modules/esm/translators.js#L200, with evaluationCallback being the [[EvaluationSteps]]. wrapModuleLoad(filename, null, isMain) is the call that actually loads/runs the module, and can throw.

@nicolo-ribaudo
Copy link
Member Author

Note: CI is failing just because this PR is based on the import-attributes branch in this repo, which is quite old. I'll rebase this PR properly on top of main once the import attributes PR is merged.

jmdyck
jmdyck previously requested changes Feb 14, 2025
@bakkot bakkot added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Feb 18, 2025
@ljharb ljharb changed the base branch from import-attributes to main February 19, 2025 00:44
@ljharb ljharb dismissed jmdyck’s stale review February 19, 2025 00:45

changes addressed

@nicolo-ribaudo nicolo-ribaudo mentioned this pull request Feb 19, 2025
2 tasks
@ljharb ljharb closed this Feb 19, 2025
@ljharb ljharb reopened this Feb 19, 2025
@ljharb ljharb merged commit 3feb1ba into tc39:main Feb 19, 2025
8 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the json-modules branch February 19, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has stage 4 This PR represents a proposal that has achieved stage 4, and is ready to merge. has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4. ready to merge Editors believe this PR needs no further reviews, and is ready to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants