-
-
Notifications
You must be signed in to change notification settings - Fork 741
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
finally
block isn't executed if try
/catch
has control flow statements
#2338
Comments
Thanks for tracking this down!
Is it any control flow statements, like if/whole/do/for/etc, or literally just |
@gfwilliams It seems that // Not reaching finally block
(() => {
try {
console.log("testing return...");
return;
} finally {
console.log("return success");
}
})();
(() => {
do {
try {
console.log("testing break...");
break;
} finally {
console.log("break success");
}
} while (false);
})();
(() => {
do {
try {
console.log("testing continue...");
continue;
} finally {
console.log("continue success");
}
} while (false);
})(); And these are cases where it is executed correctly // Reaching finally block
(() => {
try {
console.log("testing if...");
let someVariable = 0;
if (true) {
someVariable = 1;
}
if (false) {
someVariable = 0;
}
} finally {
console.log("if success");
}
})();
(() => {
try {
console.log("testing while...");
let i = 0;
while (i < 1) {
i++;
}
} finally {
console.log("while success");
}
})();
(() => {
try {
console.log("testing do-while...");
let i = 0;
do {
i++;
} while (i < 2);
} finally {
console.log("do-while success");
}
})();
(() => {
try {
console.log("testing for...");
for (let i = 0; i < 1; i++) {
}
} finally {
console.log("for success");
}
})();
(() => {
try {
console.log("testing throw...");
throw new Error();
} catch (e) {
throw new Error();
} finally {
console.log("throw success");
}
})(); I've confirmed all of them are executed expected in chrome |
Thanks! I'm pretty sure that's now fixed. |
@gfwilliams thanks! confirmed to be working here as well :) |
First time here, first of all - this is an awesome project!!
I'm trying to play around with transpiling async/await code to ES5, and in my attempts I encountered a behavior that's not according to spec.
It seems that a
finally
block are only executed if thetry
/catch
block had no control flow statements in them.For example, in the following code, the
finally
block should be executed even though thetry
block had areturn
statement in itRunning this in node/chrome behaves correctly. MDN and the spec confirm this is indeed the desired behavior.
The text was updated successfully, but these errors were encountered: