Skip to content

Add using and await using Declarations, SuppressedError, DisposableStack, and AsyncDisposableStack#3000

Open
rbuckton wants to merge 73 commits intotc39:mainfrom
rbuckton:explicit-resource-management
Open

Add using and await using Declarations, SuppressedError, DisposableStack, and AsyncDisposableStack#3000
rbuckton wants to merge 73 commits intotc39:mainfrom
rbuckton:explicit-resource-management

Conversation

@rbuckton
Copy link

@rbuckton rbuckton commented Jan 23, 2023

This PR contains the Stage 3 specification text for Explicit Resource Management.

@rbuckton rbuckton force-pushed the explicit-resource-management branch from b7b82d5 to 17e0bc0 Compare January 23, 2023 23:33
@rbuckton
Copy link
Author

I'm not quite sure how to address the remaining esmeta issues.

@ljharb ljharb added normative change Affects behavior required to correctly evaluate some ECMAScript source text needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 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 Jan 24, 2023
@jmdyck
Copy link
Collaborator

jmdyck commented Jan 24, 2023

Rather than suggest changes here, I've made a PR against this PR's branch: rbuckton#2

@rbuckton
Copy link
Author

This last commit adds a few UpdateEmpty calls that aren't strictly necessary, but esmeta doesn't quite understand what's happening without it. I also had to switch AO parameters typed : a function object to : an ECMAScript language value since IsCallable doesn't seem to act as a type guard.

@ljharb ljharb marked this pull request as draft January 25, 2023 22:30
@bakkot
Copy link
Member

bakkot commented Jan 25, 2023

@rbuckton Sorry about that - esmeta is still a little imprecise. You should feel free to write the spec text you want and not worry about esmeta's errors, and we can update esmeta or the ignore file.

@rbuckton
Copy link
Author

@rbuckton Sorry about that - esmeta is still a little imprecise. You should feel free to write the spec text you want and not worry about esmeta's errors, and we can update esmeta or the ignore file.

I replaced the UpdateEmpty calls with a few asserts that seem to be accurate. For example, in ForIn/OfBodyEvaluation, if status is abrupt going in to DisposeResources, it should still be abrupt on the way out. Likewise, ForBodyEvaluation won't return a normal completion for empty, so DisposeResources shouldn't produce one either.

@rbuckton
Copy link
Author

Please note, I've created rbuckton#3 as a separate PR against this one containing the additional specification changes that would be necessary to support https://github.com/tc39/proposal-async-explicit-resource-management, should it advance to Stage 3.

@rbuckton
Copy link
Author

I found an issue with the change in e4f2d05 to use an EE to restrict binding patterns, in that it results in an ambiguous parse of using[x] before the EE can be applied, which was not intended.

I've filed tc39/proposal-explicit-resource-management#152 against the proposal spec, and will update this PR in due time.

@rbuckton
Copy link
Author

I found an issue with the change in e4f2d05 to use an EE to restrict binding patterns, in that it results in an ambiguous parse of using[x] before the EE can be applied, which was not intended.

I've filed tc39/proposal-explicit-resource-management#152 against the proposal spec, and will update this PR in due time.

tc39/proposal-explicit-resource-management#152 has merged, and I've amended this PR to match as part of 3044fd9.

@rbalicki2

This comment was marked as duplicate.

@rbuckton
Copy link
Author

This now includes the await using declaration and AsyncDisposableStack, per prior consensus (incl. the March 2023 plenary).

@rbuckton
Copy link
Author

Note to implementers: There is a typo in GetDisposeMethod that will be addressed by tc39/proposal-explicit-resource-management#217. The typo was introduced as part of a normative change that reached consensus in July 2023, but fixing it is also a potentially a normative change and may require additional consensus.

@rbuckton
Copy link
Author

This is also missing the consensus change to use await using as the syntactic head for the asynchronous form of the using declaration. That will be up shortly.

@jmdyck
Copy link
Collaborator

jmdyck commented Mar 12, 2026

Oh, also, the things in Annex A should parallel how they appear in the main body.

Are you referring to the placement of the "Supplemental Syntax" section, or something else?

The placement of the two new Supplemetal Syntaxes, for UnaryExpression and AwaitUsingDeclaration pieces would mostly account for the differences I'm seeing.

Also, in the latter, the main body says "When processing an instance...", but Annex A says " In certain circumstances when processing an instance..."

@rbuckton
Copy link
Author

Oh, also, the things in Annex A should parallel how they appear in the main body.

Are you referring to the placement of the "Supplemental Syntax" section, or something else?

The placement of the two new Supplemetal Syntaxes, for UnaryExpression and AwaitUsingDeclaration pieces would mostly account for the differences I'm seeing.

Also, in the latter, the main body says "When processing an instance...", but Annex A says " In certain circumstances when processing an instance..."

UnaryExpression was certainly off as I needed to move the supplemental syntax from where it was at one point under Async Functions. Other than the wording for AwaitUsingDeclaration the Annex A position of seems correct to me, so I'm not clear on what's wrong there. In the main body the grammar goes LexicalDeclaration, LetOrConst, UsingDeclaration, and then AwaitUsingDeclaration, which is the same order in the annex.

@rbuckton rbuckton force-pushed the explicit-resource-management branch from ce12f16 to 2701bff Compare March 12, 2026 15:37
@ljharb ljharb added has test262 tests and removed needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Mar 12, 2026
@jmdyck
Copy link
Collaborator

jmdyck commented Mar 12, 2026

UnaryExpression was certainly off as I needed to move the supplemental syntax from where it was at one point under Async Functions. Other than the wording for AwaitUsingDeclaration the Annex A position of seems correct to me, so I'm not clear on what's wrong there.

I'll have another look at some point.

There's also some weirdness in the SDO coverage, but it might be my code, so that'll take a while to investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.