mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
fix cascaded try catch blocks
This commit is contained in:
parent
bba6c79fd2
commit
b457f4aaf0
@ -156,7 +156,7 @@ class BranchManger {
|
|||||||
*/
|
*/
|
||||||
void calculate() {
|
void calculate() {
|
||||||
addLoops();
|
addLoops();
|
||||||
Collections.sort( allParsedOperations, (a,b) -> Integer.compare( a.startPosition, b.startPosition ) );
|
Collections.sort( allParsedOperations );
|
||||||
calculate( root, 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.
|
* 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;
|
private JavaBlockOperator op;
|
||||||
|
|
||||||
int startPosition;
|
int startPosition;
|
||||||
@ -1133,6 +1133,15 @@ class BranchManger {
|
|||||||
this.nextPosition = nextPosition;
|
this.nextPosition = nextPosition;
|
||||||
this.lineNumber = lineNumber;
|
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;
|
private final TryCatchFinally tryCatch;
|
||||||
|
|
||||||
TryCatchParsedBlock( 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;
|
this.tryCatch = tryCatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ public class Exceptions extends AbstractBaseTest {
|
|||||||
addParam( list, script, "tryFinally2" );
|
addParam( list, script, "tryFinally2" );
|
||||||
addParam( list, script, "complex" );
|
addParam( list, script, "complex" );
|
||||||
addParam( list, script, "sync" );
|
addParam( list, script, "sync" );
|
||||||
|
addParam( list, script, "syncWithInnerTryCatch" );
|
||||||
addParam( list, script, "emptyCatch" );
|
addParam( list, script, "emptyCatch" );
|
||||||
addParam( list, script, "multiCatch" );
|
addParam( list, script, "multiCatch" );
|
||||||
}
|
}
|
||||||
@ -172,6 +173,20 @@ public class Exceptions extends AbstractBaseTest {
|
|||||||
return v;
|
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
|
@Export
|
||||||
static int emptyCatch() {
|
static int emptyCatch() {
|
||||||
int h = 127; // variable slot 0
|
int h = 127; // variable slot 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user