KJS: implement Throwable in Kotlin instead of use it as alias of JS Error

* Make it an inheritor of JS Error. Otherwise, Chakra engine doesn't fill stack trace of exception; In other engines inheritance has some good effects too.
* Copy all properties from internally created instance of JS Error

 #KT-6985 Fixed
 #KT-2328 Fixed
 #KT-8019 Fixed
 #KT-10911 Fixed
This commit is contained in:
Zalim Bashorov
2016-11-14 22:36:49 +03:00
parent 1f4d95eaa7
commit aa2a4f0794
10 changed files with 114 additions and 40 deletions
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin
import kotlin.js.internal.JsError
/**
* The base class for all errors and exceptions. Only instances of this class can be thrown or caught.
*
* @param message the detail message string.
* @param cause the cause of this throwable.
*/
public open class Throwable(open val message: String?, open val cause: Throwable?) : JsError(message) {
constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(cause?.toString(), cause)
constructor() : this(null, null)
init {
var e = JsError(message)
copyOwnProperties(e, this)
val t: dynamic = this
t.name = t.constructor.name
}
}
private fun copyOwnProperties(from: dynamic, to: dynamic) {
val names: Array<String> = js("Object").getOwnPropertyNames(from);
for (name in names) {
to[name] = from[name];
}
}
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.js.internal
@native
@JsName("Error")
public open class JsError(message: String?)
+13 -23
View File
@@ -16,38 +16,28 @@
package kotlin
open class Error(message: String? = null) : Throwable(message, null) {
init {
val self: dynamic = this
self.message = message
}
}
open class Error(message: String? = null) : Throwable(message, null)
open class Exception(message: String? = null) : Throwable(message, null) {
init {
val self: dynamic = this
self.message = message
}
}
open class Exception(message: String? = null) : Throwable(message, null)
open class RuntimeException(message: String? = null) : Exception(message) {}
open class RuntimeException(message: String? = null) : Exception(message)
open class IllegalArgumentException(message: String? = null) : RuntimeException(message) {}
open class IllegalArgumentException(message: String? = null) : RuntimeException(message)
open class IllegalStateException(message: String? = null) : RuntimeException(message) {}
open class IllegalStateException(message: String? = null) : RuntimeException(message)
open class IndexOutOfBoundsException(message: String? = null) : RuntimeException(message) {}
open class IndexOutOfBoundsException(message: String? = null) : RuntimeException(message)
open class ConcurrentModificationException(message: String? = null) : RuntimeException(message) {}
open class ConcurrentModificationException(message: String? = null) : RuntimeException(message)
open class UnsupportedOperationException(message: String? = null) : RuntimeException(message) {}
open class UnsupportedOperationException(message: String? = null) : RuntimeException(message)
open class NumberFormatException(message: String? = null) : RuntimeException(message) {}
open class NumberFormatException(message: String? = null) : RuntimeException(message)
open class NullPointerException(message: String? = null) : RuntimeException(message) {}
open class NullPointerException(message: String? = null) : RuntimeException(message)
open class ClassCastException(message: String? = null) : RuntimeException(message) {}
open class ClassCastException(message: String? = null) : RuntimeException(message)
open class AssertionError(message: String? = null) : Error(message) {}
open class AssertionError(message: String? = null) : Error(message)
open class NoSuchElementException(message: String? = null) : Exception() {}
open class NoSuchElementException(message: String? = null) : Exception()