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

await using normative updates #16537

Merged
merged 10 commits into from
Jul 22, 2024
Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented May 30, 2024

Q                       A
Fixed Issues? Implements tc39/proposal-explicit-resource-management#218, tc39/proposal-explicit-resource-management#219, closes #16409
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR implements the following normative changes:

  • The promise returned by a Symbol.dispose method in an await using declaration is ignored
  • Synchronous errors thrown by a Symbol.dispose method in an await using declaration are turned into promise rejections.

Both of them are supported via a wrapper around the Symbol.dispose method.

This PR also fixes a compliance issue: When searching a dispose method, Babel will not fallback to Symbol.dispose if Symbol.asyncDispose method is null or document.all.

@JLHwung JLHwung added PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Explicit Resource Management labels May 30, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented May 30, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57425

Comment on lines +36 to +76
if (isAwait) {
var inner = dispose;
}
Copy link
Member

Choose a reason for hiding this comment

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

var inner = isAwait && dispose;
Will this be smaller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

- // size: 972, gzip size: 498
+ // size: 971, gzip size: 500

It will save one byte for plaintext but the compressed size is increased by 2.

@nicolo-ribaudo
Copy link
Member

Could you include tc39/proposal-explicit-resource-management#219 too?

@JLHwung JLHwung force-pushed the await-using-normative-updates branch 2 times, most recently from 898b27d to 631f722 Compare June 24, 2024 14:33
@JLHwung
Copy link
Contributor Author

JLHwung commented Jun 24, 2024

It seems that the CI failure on Node.js 8 is due to a platform-specific bug. I will skip the new test for Node < 10.

Copy link
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 looks correct to me, I'll make sure that we are running test262 tests though

if (resource.a) {
return Promise.resolve(disposalResult).then(next, err);
if (!resource.a && state === StateFlag.NEEDS_AWAIT) {
state = StateFlag.NONE;
Copy link
Contributor Author

@JLHwung JLHwung Jul 3, 2024

Choose a reason for hiding this comment

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

Note: If tc39/proposal-explicit-resource-management#219 (comment) gets consensus, we can simply change this line to state = StateFlag.HAS_AWAITED. Before that happens we implement the 2024-06 version as-is.

@JLHwung JLHwung force-pushed the await-using-normative-updates branch from 7a63e72 to b9602b1 Compare July 22, 2024 13:14
@JLHwung JLHwung merged commit 2def809 into babel:main Jul 22, 2024
51 checks passed
@JLHwung JLHwung deleted the await-using-normative-updates branch July 22, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Explicit Resource Management
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants