JS: fix rethrowing uncaught exception

See #394
This commit is contained in:
Alexey Andreev 2019-05-29 21:37:34 +03:00
parent d17b459ecc
commit 1ca635fac6
2 changed files with 19 additions and 1 deletions

View File

@ -1483,7 +1483,7 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor {
} }
if (!defaultHandlerOccurred) { if (!defaultHandlerOccurred) {
writer.ws().append("else").ws().append("{").indent().softNewLine(); writer.ws().append("else").ws().append("{").indent().softNewLine();
writer.append("throw $$je;").softNewLine(); writer.append("throw $$e;").softNewLine();
writer.outdent().append("}").softNewLine(); writer.outdent().append("}").softNewLine();
} else { } else {
writer.softNewLine(); writer.softNewLine();

View File

@ -18,6 +18,7 @@ package org.teavm.vm;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.junit.Test; import org.junit.Test;
@ -488,4 +489,21 @@ public class VMTest {
interface ScriptExecutionWrapper { interface ScriptExecutionWrapper {
Object wrap(Supplier<Object> execution); Object wrap(Supplier<Object> execution);
} }
@Test
public void uncaughtExceptionRethrown() {
boolean exceptionCaught = false;
try {
try {
throw new NullPointerException("ok");
} catch (IndexOutOfBoundsException e) {
fail("Should not get there");
}
fail("Should not get there");
} catch (NullPointerException e) {
assertEquals("ok", e.getMessage());
exceptionCaught = true;
}
assertTrue("Exception was not caught", exceptionCaught);
}
} }