[JS IR] Fix stack trace capturing in secondary constructors (KT-37563)

Call captureStack in primary constructors and generated factories
This commit is contained in:
Svyatoslav Kuzmich
2020-06-10 11:59:17 +03:00
parent dfdc1e9c4f
commit 6792779281
11 changed files with 171 additions and 13 deletions
@@ -79,11 +79,9 @@ internal fun getStringHashCode(str: String): Int {
internal fun identityHashCode(obj: Any?): Int = getObjectHashCode(obj)
internal fun captureStack(instance: Throwable) {
internal fun captureStack(instance: Throwable, constructorFunction: Any) {
if (js("Error").captureStackTrace != null) {
// TODO Why we generated get kclass for throwable in original code?
js("Error").captureStackTrace(instance, instance.asDynamic().constructor)
// js("Error").captureStackTrace(instance, instance::class.js)
js("Error").captureStackTrace(instance, constructorFunction)
} else {
instance.asDynamic().stack = js("new Error()").stack
}
@@ -110,7 +108,6 @@ internal fun setPropertiesToThrowableInstance(this_: dynamic, message: String?,
this_.cause = cause
}
this_.name = JsObject.getPrototypeOf(this_).constructor.name
captureStack(this_)
}
@JsName("Object")