From 1435bdb7c77c7021e601f606a4cc6298a7c738bc Mon Sep 17 00:00:00 2001 From: develar Date: Thu, 8 Aug 2013 19:51:49 +0400 Subject: [PATCH] JS backend: made some exceptions more JS idiomatic -- translate Exception to Error, IndexOutOfBounds and IndexOutOfBoundsException to RangeError. --- js/js.libraries/src/core/javalang.kt | 11 +++++++---- js/js.translator/testFiles/kotlin_lib.js | 19 ++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/js/js.libraries/src/core/javalang.kt b/js/js.libraries/src/core/javalang.kt index 27a2d3b2f05..44ebefb712a 100644 --- a/js/js.libraries/src/core/javalang.kt +++ b/js/js.libraries/src/core/javalang.kt @@ -3,8 +3,8 @@ package java.lang import java.io.IOException import js.library -library -open public class Exception(message: String? = null) : Throwable() {} +native("Error") +open public class Exception(message: String? = null): Throwable() {} library open public class RuntimeException(message: String? = null) : Exception(message) {} @@ -15,8 +15,11 @@ public class IllegalArgumentException(message: String? = null) : Exception() {} library public class IllegalStateException(message: String? = null) : Exception() {} -library -public class IndexOutOfBoundsException(message: String? = null) : Exception() {} +native("RangeError") +public class IndexOutOfBounds(message: String? = null) : Exception(message) {} + +native("RangeError") +public class IndexOutOfBoundsException(message: String? = null) : Exception(message) {} library public class UnsupportedOperationException(message: String? = null) : Exception() {} diff --git a/js/js.translator/testFiles/kotlin_lib.js b/js/js.translator/testFiles/kotlin_lib.js index 25effe55ea0..236a74cc3fa 100644 --- a/js/js.translator/testFiles/kotlin_lib.js +++ b/js/js.translator/testFiles/kotlin_lib.js @@ -72,16 +72,13 @@ String.prototype.contains = function (s) { Kotlin.modules = {}; - Kotlin.Exception = Kotlin.$createClass(); - Kotlin.RuntimeException = Kotlin.$createClass(Kotlin.Exception); - Kotlin.IndexOutOfBounds = Kotlin.$createClass(Kotlin.Exception); - Kotlin.NullPointerException = Kotlin.$createClass(Kotlin.Exception); - Kotlin.NoSuchElementException = Kotlin.$createClass(Kotlin.Exception); - Kotlin.IllegalArgumentException = Kotlin.$createClass(Kotlin.Exception); - Kotlin.IllegalStateException = Kotlin.$createClass(Kotlin.Exception); - Kotlin.IndexOutOfBoundsException = Kotlin.$createClass(Kotlin.Exception); - Kotlin.UnsupportedOperationException = Kotlin.$createClass(Kotlin.Exception); - Kotlin.IOException = Kotlin.$createClass(Kotlin.Exception); + Kotlin.RuntimeException = Kotlin.$createClass(); + Kotlin.NullPointerException = Kotlin.$createClass(); + Kotlin.NoSuchElementException = Kotlin.$createClass(); + Kotlin.IllegalArgumentException = Kotlin.$createClass(); + Kotlin.IllegalStateException = Kotlin.$createClass(); + Kotlin.UnsupportedOperationException = Kotlin.$createClass(); + Kotlin.IOException = Kotlin.$createClass(); Kotlin.throwNPE = function () { throw Kotlin.$new(Kotlin.NullPointerException)(); @@ -263,7 +260,7 @@ String.prototype.contains = function (s) { }, checkRange: function(index) { if (index < 0 || index >= this.$size) { - throw new Kotlin.IndexOutOfBoundsException(); + throw new RangeError(); } } });