Skip to content

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

Merged
ljharb merged 1 commit into
tc39:mainfrom
rbuckton:explicit-resource-management
Jun 24, 2026
Merged

Normative: Add using and await using Declarations, SuppressedError, DisposableStack, and AsyncDisposableStack#3000
ljharb merged 1 commit into
tc39:mainfrom
rbuckton:explicit-resource-management

Conversation

@rbuckton

@rbuckton rbuckton commented Jan 23, 2023

Copy link
Copy Markdown
Member

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
Copy Markdown
Member 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

jmdyck commented Jan 24, 2023

Copy link
Copy Markdown
Collaborator

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

@rbuckton

Copy link
Copy Markdown
Member 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

bakkot commented Jan 25, 2023

Copy link
Copy Markdown
Member

@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.

Comment thread spec.html Outdated
Comment thread spec.html Outdated
@rbuckton

Copy link
Copy Markdown
Member 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
Copy Markdown
Member 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.

Comment thread spec.html Outdated
@rbuckton

Copy link
Copy Markdown
Member 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
Copy Markdown
Member 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.

Comment thread spec.html Outdated
@rbalicki2

This comment was marked as duplicate.

Comment thread spec.html Outdated
@rbuckton

Copy link
Copy Markdown
Member Author

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

@rbuckton

Copy link
Copy Markdown
Member 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
Copy Markdown
Member 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.

@ljharb ljharb 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 May 19, 2026
@michaelficarra michaelficarra added editor call to be discussed in the next editor call ready to merge Editors believe this PR needs no further reviews, and is ready to land. and removed editor call to be discussed in the next editor call labels May 27, 2026
Comment thread spec.html Outdated
Comment thread spec.html Outdated
Comment thread spec.html Outdated
@michaelficarra michaelficarra added ready to merge Editors believe this PR needs no further reviews, and is ready to land. and removed ready to merge Editors believe this PR needs no further reviews, and is ready to land. labels May 28, 2026
@ljharb

ljharb commented Jun 2, 2026

Copy link
Copy Markdown
Member

This needs to be rebased before it can be merged, and it's not a trivial one.

@ljharb ljharb removed the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Jun 7, 2026
@rbuckton rbuckton force-pushed the explicit-resource-management branch 2 times, most recently from c06512e to f2e685b Compare June 14, 2026 14:44
@rbuckton

Copy link
Copy Markdown
Member Author

Squashed and rebased to simplify history and make things easier.

@rbuckton rbuckton force-pushed the explicit-resource-management branch from f2e685b to 1ae839f Compare June 14, 2026 22:09
jmdyck
jmdyck previously requested changes Jun 16, 2026

@jmdyck jmdyck left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just some rebase-related updates.

Comment thread spec.html Outdated
Comment thread spec.html Outdated
Comment thread spec.html Outdated
Comment thread spec.html Outdated
@rbuckton

Copy link
Copy Markdown
Member Author

Just some rebase-related updates.

Updated. Can you take another look?

@jmdyck

jmdyck commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Looks like that resolves all my nits.

@michaelficarra michaelficarra added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Jun 18, 2026
@michaelficarra michaelficarra force-pushed the explicit-resource-management branch from bcb9acd to d7e588c Compare June 18, 2026 15:22
@rbuckton

Copy link
Copy Markdown
Member Author

Looks like that resolves all my nits.

Mind approving then? It shows you as having open requested changes.

…r, DisposableStack, and AsyncDisposableStack (tc39#3000)

* Spec text for proposal-explicit-resource-management
* Fix lint errors
* Run formatter
* Fix signature for DisposeResources
* Fixes for some esmeta warnings
* Fixes for some esmeta warnings
* Add missing ReturnIfAbrupt in DisposableStack.prototype.use
* More ecmarkup signature fixes
* Change DisposeResources signature to return completion record
* Order sections by property name
* Syntax of types
* id of AO clause doesn't need to include param names
* Avoid the use of `Type()`
* Use preamble conventions from PR tc39#2592
* Interface names are put in `<i>` rather than `<em>`
* A 'Slots' table should have a 'Type' column
* Add 'UsingDeclaration' to Annex A
* misc minor fixes
* add description suggestion from @jmdyck
* Add DisposeCapabilityRecord from tc39/proposal-explicit-resource-management#144
* Wrap UpdateEmpty calls in calls to Completion
* Run formatter
* Run formatter again
* Fix formatting and capitalization
* Clean up DisposeResources signature, replace UpdateEmpty with assertions
* Add 'either' in front of 'null or undefined'
* Use CreateBuiltinFunction
* Address additional editor feedback (from async PR)
* Move BindingPattern restriction for 'using' to an early error
* Fix typo in using declaration early errors
* Fix typos
* run formatter
* Remove InstallErrorCause from SuppressedError, per 2023-jan consensus
* Spec text for proposal-async-explicit-resource-management
* Run formatter
* Add 'either' in front of 'null or undefined'
* Address editor feedback
* Address additional editor feedback
* Switch back to a production parameter, update ASI note
* Remove 'await' restriction per March 2023 consensus. See tc39/proposal-explicit-resource-management#153
* Adopt consensus changes from tc39/proposal-explicit-resource-management#178
* Adopt consensus changes from tc39/proposal-explicit-resource-management#180
* Adopt typo fix from tc39/proposal-explicit-resource-management#217
* Fix typos and add temporary PR note
* Remove temporary PR note
* Remaining consensus updates from proposal repo
* Add missing undefined check in GetDisposeMethod
* Fix DisposeCapability leak
* fix formatting
* Switch to empty list
* Update text of NOTE
* Add PromiseCapability wrapper around sync dispose in an `await using`
* Fix missing lookahead restriction
* Remove superfluous ClassBody restriction
* Add entries to esmeta-ignore
* Reduce unnecessary Awaits for nullish values in blocks containing `await using`
* Add missing 'constructor' definitions
* Disallow using/await using in a switch case/default clause
* Fix formatting
* PR feedback
* minor fixes
* Switch from @@ to % in a few more places
* Update esmeta-ignore.json
* Update asyncDispose to be an async method
* avoid threading kind through all the InitializeBinding machinery
* rename _kind_ to _declarationKind_ in ForIn/OfBodyEvaluation

  since there's already _iterationKind_ and _lhsKind_
* move _declarationKind_ into the branch where that makes sense

  otherwise we're calling IsUsingDeclaration/IsAwaitUsingDeclaration on potentially an assignment target or var declaration, which they aren't defined over.

* move it back
* PR Feedback
* Some missing changes pulled from #11
* Fix some remaining suggestions from #7
* Switch to `<em>` where appropriate
* PR feedback
* Don't overwrite completion parameter in DisposeResources
* The spec usually uses lower-case for ids.
* Drop 'variants' attribute
* Changes to Annex A to make it parallel to main-body grammar
* Add subclauses to "Constructor Properties of The Global Object"
* Need to define ForDeclarationBindingInitialization for ForDeclaration
* Remove unreachable SDO rules
* Remove more unreachable SDO rules
* Remove unnecessary steps in CreateDisposableResource
* Add explicit return to algorithm
* EvaluateClassStaticBlockBody: add an Assert
* Remove 'kind' description from InitializeBinding
* CaseBlock can't have resources, so just assert
* Restore missing NOTE and fix indentation
* ContainsUsing and HasUnterminatedUsingDeclaration are identical
* Rename V to value and O to obj
* Use list shorthand for NewDisposeCapability
* Rely on NOTE rather than overwriting [[DisposableResourceStack]]
* Add type to clauses and use 'this method'
* Merge branch 'main' into explicit-resource-management
* Revert changes to esmeta-ignore.json
* PR fix type and function/method usage
* Additional editorial feedback
* Refactor out DisposeCapability
* Fix internal slot typo
* Remove unused Dispose AO
* Editorial feedback
* Remove excess argument to 'return' method
* Restore 'then' in assertion
* Restore old ids
* SuppressedError.prototype description
* Revert 'this function'->'this method'
* 'property'->'properties' in (Async)Disposable interface desc
* Other editorial feedback
* no list for mutually exclusive states
* Align aliases with tc39#3873
* PR feedback
* Symbol description wording
* Merge pull request #17 from rbuckton/excess-iter-return-argument

  Remove excess argument to 'return' method

* Revert function->method changes
@ljharb ljharb changed the title Add using and await using Declarations, SuppressedError, DisposableStack, and AsyncDisposableStack Normative: Add using and await using Declarations, SuppressedError, DisposableStack, and AsyncDisposableStack Jun 24, 2026
@ljharb ljharb force-pushed the explicit-resource-management branch from d7e588c to f792966 Compare June 24, 2026 19:01
@ljharb ljharb merged commit f792966 into tc39:main Jun 24, 2026
10 checks passed
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.