-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
Description: Finally block in sync generator in try-finally statement is ignored and is not executed if that generator yields rejected promise and is iterated over with for-await-of loop.
void async function() {
try {
for await (const x of function*() {
try { yield Promise.reject("reject") }
finally { console.log("finally after reject") }
}()) {
console.log(await x)
}
} catch (e) {
console.log(e)
}
}()
eshost Output:
$ eshost -s -x 'void async function() {
try {
for await (const x of function*() {
try { yield Promise.reject("reject") }
finally { console.log("finally after reject") }
}()) {
console.log(await x)
}
} catch (e) {
console.log(e)
}
}()'
#### sm, v8
reject
I expect the following output:
finally after reject
reject
If the generator is async then finally block is executed as expected.
If for-await-of loop is transpiled with babel then finally block is executed as expected.
There is a comment about that bug and spec compliance in firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1610315#c1
Update.
This bug causes the next two code fragments to behave differently:
1.
for (const _x of function*() {
try { yield Promise.reject("reject") }
finally { console.log("finally after reject") }
}()){
const x = await _x
....
}
for await (const x of function*() {
try { yield Promise.reject("reject") }
finally { console.log("finally after reject") }
}()){
...
}
The first loop executes finally block, but the second one doesn't, though both of them resolves promises before assigning them to x
.
Metadata
Metadata
Assignees
Labels
No labels