mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
fix cascaded try catch blocks
This commit is contained in:
parent
bba6c79fd2
commit
b457f4aaf0
@ -156,7 +156,7 @@ class BranchManger {
|
||||
*/
|
||||
void calculate() {
|
||||
addLoops();
|
||||
Collections.sort( allParsedOperations, (a,b) -> Integer.compare( a.startPosition, b.startPosition ) );
|
||||
Collections.sort( allParsedOperations );
|
||||
calculate( root, allParsedOperations );
|
||||
}
|
||||
|
||||
@ -1115,7 +1115,7 @@ class BranchManger {
|
||||
/**
|
||||
* Description of single block/branch from the parsed Java byte code. The parsed branches are plain.
|
||||
*/
|
||||
private static class ParsedBlock {
|
||||
private static class ParsedBlock implements Comparable<ParsedBlock> {
|
||||
private JavaBlockOperator op;
|
||||
|
||||
int startPosition;
|
||||
@ -1133,6 +1133,15 @@ class BranchManger {
|
||||
this.nextPosition = nextPosition;
|
||||
this.lineNumber = lineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int compareTo( ParsedBlock o ) {
|
||||
return startPosition < o.startPosition ? -1 : startPosition > o.startPosition ? 1 : // first order on the start position
|
||||
-Integer.compare( endPosition, o.endPosition ); // then reverse on the end position that outer blocks occur first
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1230,7 +1239,7 @@ class BranchManger {
|
||||
private final TryCatchFinally tryCatch;
|
||||
|
||||
TryCatchParsedBlock( TryCatchFinally tryCatch ) {
|
||||
super( JavaBlockOperator.TRY, tryCatch.getStart(), 0, tryCatch.getStart(), -1 );
|
||||
super( JavaBlockOperator.TRY, tryCatch.getStart(), tryCatch.getEnd() - tryCatch.getStart(), tryCatch.getStart(), -1 );
|
||||
this.tryCatch = tryCatch;
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ public class Exceptions extends AbstractBaseTest {
|
||||
addParam( list, script, "tryFinally2" );
|
||||
addParam( list, script, "complex" );
|
||||
addParam( list, script, "sync" );
|
||||
addParam( list, script, "syncWithInnerTryCatch" );
|
||||
addParam( list, script, "emptyCatch" );
|
||||
addParam( list, script, "multiCatch" );
|
||||
}
|
||||
@ -172,6 +173,20 @@ public class Exceptions extends AbstractBaseTest {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Export
|
||||
static int syncWithInnerTryCatch() {
|
||||
int result;
|
||||
Object obj = new Object();
|
||||
synchronized( obj ) {
|
||||
try {
|
||||
result = 13;
|
||||
} catch( Exception x ) {
|
||||
result = 42;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Export
|
||||
static int emptyCatch() {
|
||||
int h = 127; // variable slot 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user