JS backend: support for Throwable.getMessage
This commit is contained in:
@@ -1,30 +1,28 @@
|
|||||||
package java.lang
|
package java.lang
|
||||||
|
|
||||||
import java.io.IOException
|
library
|
||||||
|
open public class Exception(message: String? = null): Throwable(message) {}
|
||||||
native("Error")
|
|
||||||
open public class Exception(message: String? = null): Throwable() {}
|
|
||||||
|
|
||||||
library
|
library
|
||||||
open public class RuntimeException(message: String? = null) : Exception(message) {}
|
open public class RuntimeException(message: String? = null) : Exception(message) {}
|
||||||
|
|
||||||
library
|
library
|
||||||
public class IllegalArgumentException(message: String? = null) : Exception() {}
|
public class IllegalArgumentException(message: String? = null) : RuntimeException(message) {}
|
||||||
|
|
||||||
library
|
library
|
||||||
public class IllegalStateException(message: String? = null) : Exception() {}
|
public class IllegalStateException(message: String? = null) : RuntimeException(message) {}
|
||||||
|
|
||||||
native("RangeError")
|
|
||||||
public class IndexOutOfBounds(message: String? = null) : Exception(message) {}
|
|
||||||
|
|
||||||
native("RangeError")
|
|
||||||
public class IndexOutOfBoundsException(message: String? = null) : Exception(message) {}
|
|
||||||
|
|
||||||
library
|
library
|
||||||
public class UnsupportedOperationException(message: String? = null) : Exception() {}
|
public class IndexOutOfBoundsException(message: String? = null) : RuntimeException(message) {}
|
||||||
|
|
||||||
library
|
library
|
||||||
public class NumberFormatException(message: String? = null) : Exception() {}
|
public class UnsupportedOperationException(message: String? = null) : RuntimeException(message) {}
|
||||||
|
|
||||||
|
library
|
||||||
|
public class NumberFormatException(message: String? = null) : RuntimeException(message) {}
|
||||||
|
|
||||||
|
library
|
||||||
|
public class NullPointerException(message: String? = null) : RuntimeException(message) {}
|
||||||
|
|
||||||
library
|
library
|
||||||
public trait Runnable {
|
public trait Runnable {
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ public class TryCatchTest extends AbstractExpressionTest {
|
|||||||
checkFooBoxIsOk();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testTryCatchExpressionWithMessage() throws Exception {
|
||||||
|
checkFooBoxIsOk();
|
||||||
|
}
|
||||||
|
|
||||||
public void testMultipleCatchBlocks() throws Exception {
|
public void testMultipleCatchBlocks() throws Exception {
|
||||||
checkFooBoxIsOk();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -34,6 +34,7 @@ import java.util.List;
|
|||||||
public abstract class CompositeFIF implements FunctionIntrinsicFactory {
|
public abstract class CompositeFIF implements FunctionIntrinsicFactory {
|
||||||
@NotNull
|
@NotNull
|
||||||
public static final FunctionIntrinsic LENGTH_PROPERTY_INTRINSIC = new BuiltInPropertyIntrinsic("length");
|
public static final FunctionIntrinsic LENGTH_PROPERTY_INTRINSIC = new BuiltInPropertyIntrinsic("length");
|
||||||
|
public static final FunctionIntrinsic MESSAGE_PROPERTY_INTRINSIC = new BuiltInPropertyIntrinsic("message");
|
||||||
public static final FunctionIntrinsic IS_EMPTY_INTRINSIC = new FunctionIntrinsic() {
|
public static final FunctionIntrinsic IS_EMPTY_INTRINSIC = new FunctionIntrinsic() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
@@ -167,6 +167,8 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
|
|
||||||
add(pattern("kotlin.js", "Json", "get"), ArrayFIF.GET_INTRINSIC);
|
add(pattern("kotlin.js", "Json", "get"), ArrayFIF.GET_INTRINSIC);
|
||||||
add(pattern("kotlin.js", "Json", "set"), ArrayFIF.SET_INTRINSIC);
|
add(pattern("kotlin.js", "Json", "set"), ArrayFIF.SET_INTRINSIC);
|
||||||
|
|
||||||
|
add(pattern("kotlin", "Throwable", "getMessage"), MESSAGE_PROPERTY_INTRINSIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract static class NativeMapGetSet extends CallParametersAwareFunctionIntrinsic {
|
private abstract static class NativeMapGetSet extends CallParametersAwareFunctionIntrinsic {
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
|
||||||
|
var s: String = ""
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw Exception("Exception")
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
s = "Throwable:" + e.getMessage()!!
|
||||||
|
}
|
||||||
|
assertEquals("Throwable:Exception", s)
|
||||||
|
|
||||||
|
s = ""
|
||||||
|
try {
|
||||||
|
throw Exception("Exception")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
s = "Exception:" + e.getMessage()!!
|
||||||
|
}
|
||||||
|
assertEquals("Exception:Exception", s)
|
||||||
|
|
||||||
|
s = ""
|
||||||
|
try {
|
||||||
|
throw RuntimeException("RuntimeException")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
s = "Exception:" + e.getMessage()!!
|
||||||
|
}
|
||||||
|
assertEquals("Exception:RuntimeException", s)
|
||||||
|
|
||||||
|
s = ""
|
||||||
|
try {
|
||||||
|
throw NullPointerException("NullPointerException")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
s = "Exception:" + e.getMessage()!!
|
||||||
|
}
|
||||||
|
assertEquals("Exception:NullPointerException", s)
|
||||||
|
|
||||||
|
s = ""
|
||||||
|
try {
|
||||||
|
throw IndexOutOfBoundsException("IndexOutOfBoundsException")
|
||||||
|
} catch (e: NullPointerException) {
|
||||||
|
s = "NullPointerException:" + e.getMessage()!!
|
||||||
|
} catch (e: RuntimeException) {
|
||||||
|
s = "RuntimeException:" + e.getMessage()!!
|
||||||
|
} catch (e: Exception) {
|
||||||
|
s = "Exception:" + e.getMessage()!!
|
||||||
|
}
|
||||||
|
assertEquals("RuntimeException:IndexOutOfBoundsException", s)
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw RuntimeException()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
assertEquals(null, e.getMessage())
|
||||||
|
}
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -164,16 +164,28 @@
|
|||||||
return new Kotlin.Progression(from, to, -1);
|
return new Kotlin.Progression(from, to, -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
Kotlin.RuntimeException = Kotlin.createClassNow();
|
Kotlin.Exception = Error;
|
||||||
Kotlin.NullPointerException = Kotlin.createClassNow();
|
|
||||||
Kotlin.NoSuchElementException = Kotlin.createClassNow();
|
|
||||||
Kotlin.IllegalArgumentException = Kotlin.createClassNow();
|
|
||||||
Kotlin.IllegalStateException = Kotlin.createClassNow();
|
|
||||||
Kotlin.UnsupportedOperationException = Kotlin.createClassNow();
|
|
||||||
Kotlin.IOException = Kotlin.createClassNow();
|
|
||||||
|
|
||||||
Kotlin.throwNPE = function () {
|
function createClassNowWithMessage(base) {
|
||||||
throw new Kotlin.NullPointerException();
|
return Kotlin.createClassNow(base,
|
||||||
|
/** @constructs */
|
||||||
|
function (message) {
|
||||||
|
this.message = (message !== undefined) ? message : null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Kotlin.RuntimeException = createClassNowWithMessage(Kotlin.Exception);
|
||||||
|
Kotlin.NullPointerException = createClassNowWithMessage(Kotlin.RuntimeException);
|
||||||
|
Kotlin.NoSuchElementException = createClassNowWithMessage(Kotlin.RuntimeException);
|
||||||
|
Kotlin.IllegalArgumentException = createClassNowWithMessage(Kotlin.RuntimeException);
|
||||||
|
Kotlin.IllegalStateException = createClassNowWithMessage(Kotlin.RuntimeException);
|
||||||
|
Kotlin.UnsupportedOperationException = createClassNowWithMessage(Kotlin.RuntimeException);
|
||||||
|
Kotlin.IndexOutOfBoundsException = createClassNowWithMessage(Kotlin.RuntimeException);
|
||||||
|
Kotlin.IOException = createClassNowWithMessage(Kotlin.Exception);
|
||||||
|
|
||||||
|
Kotlin.throwNPE = function (message) {
|
||||||
|
throw new Kotlin.NullPointerException(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
function throwAbstractFunctionInvocationError(funName) {
|
function throwAbstractFunctionInvocationError(funName) {
|
||||||
@@ -468,7 +480,7 @@
|
|||||||
},
|
},
|
||||||
checkRange: function (index) {
|
checkRange: function (index) {
|
||||||
if (index < 0 || index >= this.array.length) {
|
if (index < 0 || index >= this.array.length) {
|
||||||
throw new RangeError();
|
throw new Kotlin.IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user