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

Spec compliance: finally block of sync generator should not execute if used in async loop while yielding rejected promise #11043

Open
vadzim opened this issue Jan 22, 2020 · 1 comment

Comments

@vadzim
Copy link

@vadzim vadzim commented Jan 22, 2020

Bug Report

Current Behavior
According to the spec the code

function* generator() {
   try {
      yield Promise.resolve(2)
      yield Promise.reject(new Error(3))
   } finally {
      print("finally")
   }
}

// 1)
async function () {
   for (const x of generator()) consume(await x)
}

// 2)
async function () {
   for await (const x of generator()) consume(x)
}

// 3)
async function* () {
   yield* generator()
}

should print "finally" only in the 1) case.

In the cases 2) and 3) finally block of the generator should not be executed.

Node@10 and above, current firefox and chromium have spec compliant behavior.

Babel when transpiling not node@8 has wrong behavior according to spec.

Now a lot of code is transpiled by people to the node@8 js version, and so async generators are transpiled by babel in the non-spec complained way. When the node@8 becomes obsolete and that code will be transpiled to node@10 then it can start to behave in a different way.

I suggest this should be fixed in the spec, not in the babel, though I think it's worth to make spec-compliance in some way.

Refs:
tc39/ecma262#1849
https://bugzilla.mozilla.org/show_bug.cgi?id=1610315#c1

@babel-bot

This comment has been minimized.

Copy link
Collaborator

@babel-bot babel-bot commented Jan 22, 2020

Hey @vadzim! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.