Skip to content

await using normative updates - #16537

Merged
JLHwung merged 10 commits into
babel:mainfrom
JLHwung:await-using-normative-updates
Jul 22, 2024
Merged

JLHwung merged 10 commits into
babel:mainfrom
JLHwung:await-using-normative-updates

Conversation

@JLHwung

@JLHwung JLHwung commented May 30, 2024 •

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

babel-bot commented May 30, 2024 •

Copy link
Copy Markdown
Collaborator

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

@JLHwung
JLHwung force-pushed the await-using-normative-updates branch from e60eacb to 2aa75eb Compare May 30, 2024 05:42
Comment on lines +36 to +76
if (isAwait) {
var inner = dispose;
}

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

JLHwung commented Jun 24, 2024

Copy link
Copy Markdown
Contributor Author

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.

@JLHwung
JLHwung requested a review from nicolo-ribaudo July 2, 2024 18:31

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

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;

@JLHwung JLHwung Jul 3, 2024 •

Copy link
Copy Markdown
Contributor Author

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.

@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 22, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue 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.

4 participants