mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
Fix complex catch blocks with multiple catch
This commit is contained in:
parent
5013f2f819
commit
f8a79c16e0
@ -1251,10 +1251,11 @@ class BranchManager {
|
||||
|
||||
// Create a block/end structure for every CATCH without the first CATCH
|
||||
BranchNode node = catchNode;
|
||||
TryCatchFinally tryCurrent = tryCatch;
|
||||
for( int i = catches.size()-1; i > 0; i-- ) {
|
||||
TryCatchFinally tryCat = catches.get( i );
|
||||
|
||||
if( tryCatch.getHandler() == tryCat.getHandler() ) {
|
||||
if( tryCurrent.getHandler() == tryCat.getHandler() ) {
|
||||
// multiple exception in catch block like "catch ( ArrayIndexOutOfBoundsException | IllegalArgumentException ex )"
|
||||
continue;
|
||||
}
|
||||
@ -1277,7 +1278,10 @@ class BranchManager {
|
||||
node = block;
|
||||
|
||||
int instrPos = findIdxOfCodePos( tryCat.getHandler() ) + 1;
|
||||
assert (instructions.get( instrPos ) instanceof WasmLoadStoreInstruction) && ((WasmLoadStoreInstruction)instructions.get( instrPos )).getOperator() == VariableOperator.set : "Catch block does not start with astore instruction " + instructions.get( instrPos );
|
||||
instructions.remove( instrPos ); // every catch block store the exception from the stack but in WASM we can do this only once for all exceptions
|
||||
|
||||
tryCurrent = tryCat;
|
||||
}
|
||||
|
||||
// calculate branch operations inside the CATCH/FINALLY blocks
|
||||
|
@ -57,6 +57,7 @@ public class Exceptions extends AbstractBaseTest {
|
||||
addParam( list, script, "emptyCatch" );
|
||||
addParam( list, script, "multiCatch" );
|
||||
addParam( list, script, "multiCatch2" );
|
||||
addParam( list, script, "multiCatch3" );
|
||||
addParam( list, script, "serialCatch" );
|
||||
addParam( list, script, "tryReturn" );
|
||||
addParam( list, script, "whileTrueTryFinally" );
|
||||
@ -241,6 +242,18 @@ public class Exceptions extends AbstractBaseTest {
|
||||
return r;
|
||||
}
|
||||
|
||||
@Export
|
||||
public static int multiCatch3() throws Throwable {
|
||||
try {
|
||||
new Throwable();
|
||||
return 42;
|
||||
} catch( IllegalStateException x ) {
|
||||
} catch( IllegalArgumentException | NullPointerException x ) {
|
||||
throw new Throwable( x );
|
||||
}
|
||||
return 13;
|
||||
}
|
||||
|
||||
@Export
|
||||
static int serialCatch() {
|
||||
int r = 42;
|
||||
|
Loading…
x
Reference in New Issue
Block a user