diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 7cf1bb96f5a871e58b477d4779e57ce2b7ebc416..972c8b710b6ef544c29e414a9510f9a8342db5f0 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -825,7 +825,25 @@ void PandaGen::EmitThrow(const ir::AstNode *node) void PandaGen::EmitRethrow(const ir::AstNode *node) { - // TODO: rethrow in try-catch + RegScope rs(this); + auto *skipThrow = AllocLabel(); + auto *doThrow = AllocLabel(); + + VReg exception = AllocReg(); + StoreAccumulator(node, exception); + + VReg hole = AllocReg(); + StoreConst(node, hole, Constant::JS_HOLE); + + LoadAccumulator(node, exception); + ra_.Emit(node, hole); + sa_.Emit(node, skipThrow); + + SetLabel(node, doThrow); + LoadAccumulator(node, exception); + sa_.Emit(node); + + SetLabel(node, skipThrow); } void PandaGen::EmitReturn(const ir::AstNode *node)