@@ -10264,21 +10264,7 @@ bool BaseCompiler::emitEnd() {
10264
10264
}
10265
10265
break;
10266
10266
#ifdef ENABLE_WASM_EXCEPTIONS
10267
- case LabelKind::Try: {
10268
- // The beginning of a `try` block introduces this try note, but
10269
- // we need to remove it in case we have no handlers in this block
10270
- // as it can never be the target of an exception.
10271
- WasmTryNoteVector& tryNotes = masm.tryNotes();
10272
- // This will shift the indices of any try notes in between the `try`
10273
- // instruction and this `end`. This is fine as long as try notes are
10274
- // only accessed through ControlItems, as the shifted try notes will
10275
- // correspond only to items that are popped by this point.
10276
- tryNotes.erase(&tryNotes[controlItem().tryNoteIndex]);
10277
- if (!endBlock(type)) {
10278
- return false;
10279
- }
10280
- break;
10281
- }
10267
+ case LabelKind::Try:
10282
10268
case LabelKind::Catch:
10283
10269
case LabelKind::CatchAll:
10284
10270
if (!endTryCatch(type)) {
@@ -10797,17 +10783,23 @@ bool BaseCompiler::endTryCatch(ResultType type) {
10797
10783
uint32_t lineOrBytecode = readCallSiteLineOrBytecode();
10798
10784
10799
10785
Control& tryCatch = controlItem();
10786
+ LabelKind tryKind = iter_.controlKind(0);
10800
10787
10801
10788
if (deadCode_) {
10802
10789
fr.resetStackHeight(tryCatch.stackHeight, type);
10803
10790
popValueStackTo(tryCatch.stackSize);
10804
10791
} else {
10805
- // Since the previous block is a catch, we must handle the extra exception
10792
+ // If the previous block is a catch, we must handle the extra exception
10806
10793
// reference on the stack (for rethrow) and thus the stack size is 1 more.
10807
- MOZ_ASSERT(stk_.length() == tryCatch.stackSize + type.length() + 1);
10794
+ MOZ_ASSERT(stk_.length() == tryCatch.stackSize + type.length() +
10795
+ (tryKind == LabelKind::Try ? 0 : 1));
10808
10796
// Assume we have a control join, so place results in block result
10809
- // allocations and also handle the implicit exception reference.
10810
- popCatchResults(type, tryCatch.stackHeight);
10797
+ // allocations and also handle the implicit exception reference if needed.
10798
+ if (tryKind == LabelKind::Try) {
10799
+ popBlockResults(type, tryCatch.stackHeight, ContinuationKind::Jump);
10800
+ } else {
10801
+ popCatchResults(type, tryCatch.stackHeight);
10802
+ }
10811
10803
MOZ_ASSERT(stk_.length() == tryCatch.stackSize);
10812
10804
// Since we will emit a landing pad after this and jump over it to get to
10813
10805
// the control join, we free these here and re-capture at the join.
@@ -10824,6 +10816,8 @@ bool BaseCompiler::endTryCatch(ResultType type) {
10824
10816
}
10825
10817
10826
10818
// Create landing pad for all catch handlers in this block.
10819
+ // When used for a catchless try block, this will generate a landing pad
10820
+ // with no handlers and only the fall-back rethrow.
10827
10821
masm.bind(&tryCatch.otherLabel);
10828
10822
10829
10823
// The stack height also needs to be set not for a block result, but for the
@@ -10836,6 +10830,12 @@ bool BaseCompiler::endTryCatch(ResultType type) {
10836
10830
tryNote.entryPoint = masm.currentOffset();
10837
10831
tryNote.framePushed = masm.framePushed();
10838
10832
10833
+ // If we are in a catchless try block, then there were no catch blocks to
10834
+ // mark the end of the try note, so we need to end it here.
10835
+ if (tryKind == LabelKind::Try) {
10836
+ tryNote.end = tryNote.entryPoint;
10837
+ }
10838
+
10839
10839
RegRef exn = RegRef(WasmExceptionReg);
10840
10840
needRef(exn);
10841
10841
0 commit comments