mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +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
|
// Create a block/end structure for every CATCH without the first CATCH
|
||||||
BranchNode node = catchNode;
|
BranchNode node = catchNode;
|
||||||
|
TryCatchFinally tryCurrent = tryCatch;
|
||||||
for( int i = catches.size()-1; i > 0; i-- ) {
|
for( int i = catches.size()-1; i > 0; i-- ) {
|
||||||
TryCatchFinally tryCat = catches.get( 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 )"
|
// multiple exception in catch block like "catch ( ArrayIndexOutOfBoundsException | IllegalArgumentException ex )"
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1277,7 +1278,10 @@ class BranchManager {
|
|||||||
node = block;
|
node = block;
|
||||||
|
|
||||||
int instrPos = findIdxOfCodePos( tryCat.getHandler() ) + 1;
|
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
|
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
|
// calculate branch operations inside the CATCH/FINALLY blocks
|
||||||
|
@ -57,6 +57,7 @@ public class Exceptions extends AbstractBaseTest {
|
|||||||
addParam( list, script, "emptyCatch" );
|
addParam( list, script, "emptyCatch" );
|
||||||
addParam( list, script, "multiCatch" );
|
addParam( list, script, "multiCatch" );
|
||||||
addParam( list, script, "multiCatch2" );
|
addParam( list, script, "multiCatch2" );
|
||||||
|
addParam( list, script, "multiCatch3" );
|
||||||
addParam( list, script, "serialCatch" );
|
addParam( list, script, "serialCatch" );
|
||||||
addParam( list, script, "tryReturn" );
|
addParam( list, script, "tryReturn" );
|
||||||
addParam( list, script, "whileTrueTryFinally" );
|
addParam( list, script, "whileTrueTryFinally" );
|
||||||
@ -241,6 +242,18 @@ public class Exceptions extends AbstractBaseTest {
|
|||||||
return r;
|
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
|
@Export
|
||||||
static int serialCatch() {
|
static int serialCatch() {
|
||||||
int r = 42;
|
int r = 42;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user