fix CONTINUE in a CATCH block

This commit is contained in:
Volker Berlin 2022-07-24 14:29:32 +02:00
parent 4722445f24
commit 855713a519
No known key found for this signature in database
GPG Key ID: 988423EF815BE4CB
2 changed files with 22 additions and 1 deletions

View File

@ -1246,6 +1246,7 @@ class BranchManager {
calculate( tryNode, parsedOperations.subList( 0, idx ) ); calculate( tryNode, parsedOperations.subList( 0, idx ) );
BranchNode catchNode = new BranchNode( catchPos, endPos, WasmBlockOperator.CATCH, WasmBlockOperator.END, 0 ); BranchNode catchNode = new BranchNode( catchPos, endPos, WasmBlockOperator.CATCH, WasmBlockOperator.END, 0 );
catchNode.tryPos = startPos;
parent.add( catchNode ); parent.add( catchNode );
// Create a block/end structure for every CATCH without the first CATCH // Create a block/end structure for every CATCH without the first CATCH
@ -1419,7 +1420,7 @@ class BranchManager {
int startPos = parent.startPos; int startPos = parent.startPos;
while( parent != null && parent.endPos < gotoEndPos ) { while( parent != null && parent.endPos < gotoEndPos ) {
deep++; deep++;
startPos = parent.startPos; startPos = parent.startOp == WasmBlockOperator.CATCH ? parent.tryPos : parent.startPos;
parent = parent.parent; parent = parent.parent;
} }
@ -1727,6 +1728,10 @@ class BranchManager {
*/ */
private int startIdx; private int startIdx;
/**
* Position of related TRY block for CATCH block.
*/
private int tryPos;
/** /**
* Create a new description. * Create a new description.

View File

@ -60,6 +60,7 @@ public class Exceptions extends AbstractBaseTest {
addParam( list, script, "tryReturn" ); addParam( list, script, "tryReturn" );
addParam( list, script, "whileTrueTryFinally" ); addParam( list, script, "whileTrueTryFinally" );
addParam( list, script, "ifMultipleInFinally" ); addParam( list, script, "ifMultipleInFinally" );
addParam( list, script, "catchWithContinue" );
} }
rule.setTestParameters( list ); rule.setTestParameters( list );
rule.setProperty( JWebAssembly.WASM_USE_EH, "true" ); rule.setProperty( JWebAssembly.WASM_USE_EH, "true" );
@ -292,6 +293,21 @@ public class Exceptions extends AbstractBaseTest {
return pos; return pos;
} }
@Export
static private int catchWithContinue() {
int val = 0;
for( int i = 0; i < 10; i++ ) {
try {
val = 42;
} catch( Throwable ex ) {
continue;
}
val = 13;
}
return val;
}
// @Export // @Export
// static int npe() { // static int npe() {
// Object obj = new NullPointerException(); // Object obj = new NullPointerException();