Skip to content

Commit 9b71022

Browse files
committed
[MERGE #5849 @boingoing] Fix async function and generator when await/yield is used inside a catch statement with no argument binding
Merge pull request #5849 from boingoing:fix_async_catch_no_binding
2 parents aabee01 + 590b08b commit 9b71022

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11749,17 +11749,20 @@ void Emit(ParseNode *pnode, ByteCodeGenerator *byteCodeGenerator, FuncInfo *func
1174911749
EmitAssignment(nullptr, pnode1, location, byteCodeGenerator, funcInfo);
1175011750
byteCodeGenerator->EndStatement(pnodeCatch);
1175111751
}
11752-
else if (pnodeCatch->HasParam())
11752+
else
1175311753
{
11754-
Symbol *sym = pnodeCatch->GetParam()->AsParseNodeName()->sym;
11755-
ParamTrackAndInitialization(sym, true /*initializeParam*/, location);
11756-
if (scope->GetMustInstantiate())
11754+
if (pnodeCatch->HasParam())
1175711755
{
11758-
sym->SetIsGlobalCatch(true);
11756+
Symbol *sym = pnodeCatch->GetParam()->AsParseNodeName()->sym;
11757+
ParamTrackAndInitialization(sym, true /*initializeParam*/, location);
11758+
if (scope->GetMustInstantiate())
11759+
{
11760+
sym->SetIsGlobalCatch(true);
11761+
}
11762+
byteCodeGenerator->Writer()->RecordCrossFrameEntryExitRecord(true);
1175911763
}
11760-
byteCodeGenerator->Writer()->RecordCrossFrameEntryExitRecord(true);
1176111764

11762-
// Allow a debugger to stop on the 'catch (e)'
11765+
// Allow a debugger to stop on the 'catch'
1176311766
byteCodeGenerator->StartStatement(pnodeCatch);
1176411767
byteCodeGenerator->Writer()->Empty(Js::OpCode::Nop);
1176511768
byteCodeGenerator->EndStatement(pnodeCatch);

test/EH/optional-catch-binding.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ var tests = [
106106
assert.areEqual(f()(), 2);
107107
},
108108
},
109+
{
110+
name: "Async function with catch block with no binding",
111+
body: function() {
112+
async function foo() {
113+
try { throw "anything" } catch { await 5;}
114+
}
115+
assert.isTrue(foo() instanceof Promise, "await returns a promise");
116+
}
117+
},
118+
{
119+
name: "Async function with catch block with no binding",
120+
body: function() {
121+
function* foo() {
122+
try { throw "anything" } catch { yield 5;}
123+
}
124+
assert.areEqual(5, foo().next().value, "generator returns an object with yielded value");
125+
}
126+
},
109127
];
110128

111129
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)