Omar Mainegra
07/23/2020, 7:47 PMkotlin.Number : Cannot read property 'prototype' of undefined
This is the code (generated JS):
BigDecimal.prototype = Object.create(Number_0.prototype)
And Number_0 :
var Number_0 = Kotlin.kotlin.Number;Omar Mainegra
07/23/2020, 7:49 PMval jsMain by getting {
dependsOn(commonMain)
dependencies {
implementation(kotlin("stdlib-js"))
}
}
val jsTest by getting {
dependsOn(jsMain)
dependencies {
implementation(kotlin("test-js"))
}
}turansky
07/23/2020, 9:47 PMOmar Mainegra
07/23/2020, 10:29 PMOmar Mainegra
07/23/2020, 10:31 PMclass BigDecimal : Number() {
override fun toByte(): Byte = 0
override fun toChar(): Char = '0'
override fun toDouble(): Double = 0.0
override fun toFloat(): Float = 0f
override fun toInt(): Int = 0
override fun toLong(): Long = 0L
override fun toShort(): Short = 0
}Omar Mainegra
07/23/2020, 10:31 PMRobert Jaros
07/23/2020, 10:42 PMRobert Jaros
07/23/2020, 10:44 PMRobert Jaros
07/23/2020, 10:45 PMOmar Mainegra
07/23/2020, 10:55 PMRobert Jaros
07/23/2020, 10:58 PMOmar Mainegra
07/23/2020, 11:04 PMturansky
07/24/2020, 12:12 AMBigDecimal ?Robert Jaros
07/24/2020, 12:16 AMRobert Jaros
07/24/2020, 12:19 AMimplementation(npm("webpack-inject-plugin")) to your dependencies in build.gradle.kts
2. Put inject.js file into your webpack.config.d dir with the following content:
;(function() {
const InjectPlugin = require('webpack-inject-plugin').default;
config.plugins.push(
new InjectPlugin(function() {
return "arguments[2]('../../packages_imported/kotlin/1.3.72/kotlin.js').kotlin.Number = Number;"
})
);
})();Robert Jaros
07/24/2020, 12:19 AMRobert Jaros
07/24/2020, 12:22 AMRobert Jaros
07/24/2020, 12:59 AM;(function() {
const InjectPlugin = require('webpack-inject-plugin').default;
config.plugins.push(
new InjectPlugin(function() {
return "require('kotlin').kotlin.Number = Number;"
})
);
})();Omar Mainegra
07/24/2020, 2:45 PMOmar Mainegra
07/24/2020, 4:10 PMwebpack-inject-plugin, I know the configuration is being applied (it's copied to karma.conf.js and prints)Omar Mainegra
07/24/2020, 4:12 PMOmar Mainegra
07/24/2020, 4:12 PMRobert Jaros
07/24/2020, 4:12 PMOmar Mainegra
07/24/2020, 4:13 PMOmar Mainegra
07/24/2020, 4:14 PMRobert Jaros
07/24/2020, 4:16 PMOmar Mainegra
07/24/2020, 4:16 PM./gradlew jsBrowserTestRobert Jaros
07/24/2020, 4:17 PMRobert Jaros
07/24/2020, 4:18 PMOmar Mainegra
07/24/2020, 4:21 PMOmar Mainegra
07/24/2020, 4:21 PMOmar Mainegra
07/24/2020, 4:33 PMturansky
07/24/2020, 11:23 PMdependsOn are redundant hereturansky
07/24/2020, 11:24 PMkotlin("multiplatform") plugin?Omar Mainegra
07/25/2020, 2:45 AMOmar Mainegra
07/27/2020, 3:33 PMjsBrowserTest) so I can patch the generated JS file before runnig the tests/packaging?turansky
07/27/2020, 3:34 PMturansky
07/27/2020, 3:37 PMturansky
07/27/2020, 3:41 PMturansky
07/27/2020, 3:41 PMOmar Mainegra
07/27/2020, 3:42 PMOmar Mainegra
07/27/2020, 6:02 PMkotlin.js before running the teststuransky
07/27/2020, 8:06 PMturansky
07/27/2020, 8:07 PMcompileTestKotlinJs can be finalized with patchturansky
07/27/2020, 8:09 PMconfigure is redundant, invoke call it insideOmar Mainegra
07/27/2020, 8:32 PMOmar Mainegra
07/27/2020, 8:38 PMexpect class BigDecimal : Number {
...
}
this fails in JS but passes in JVM and iOS:
@Test
fun is_a_Number() {
assertTrue { BigDecimal(1) is Number }
}Omar Mainegra
07/27/2020, 8:41 PMBigDecimal(1) as Number I got: ClassCastException: Illegal castturansky
07/27/2020, 8:44 PMturansky
07/27/2020, 8:46 PMclass BigDecimal extends Number {
constructor(value) {
super(value)
}
}turansky
07/27/2020, 8:48 PMOmar Mainegra
07/27/2020, 8:49 PMBigDecimal part in JS?Omar Mainegra
07/27/2020, 8:49 PMturansky
07/27/2020, 8:51 PM1.3.72 ?Omar Mainegra
07/27/2020, 8:51 PMturansky
07/27/2020, 8:53 PMturansky
07/27/2020, 8:53 PMOmar Mainegra
07/27/2020, 8:54 PMOmar Mainegra
07/27/2020, 8:54 PMturansky
07/27/2020, 8:55 PMOmar Mainegra
07/27/2020, 8:55 PMturansky
07/27/2020, 8:55 PMturansky
07/27/2020, 8:56 PMOmar Mainegra
07/27/2020, 8:59 PMturansky
07/27/2020, 9:20 PMBigDecimal as ES6 class works
2. You can fix constructor generated by Kotlin with jsPatch task
3. PROFITOmar Mainegra
07/27/2020, 10:14 PMis Number expression work in JSOmar Mainegra
07/27/2020, 10:15 PMactual class BigDecimal(private val raw: BigNum) : Number() but it didn't workOmar Mainegra
07/27/2020, 10:16 PMturansky
07/27/2020, 10:30 PMturansky
07/27/2020, 10:32 PMjsPatch can do it tooOmar Mainegra
07/28/2020, 12:44 AMjsPatch to "override" Kotlin.isNumber , I added
_.isNumber = function (a) { return typeof a == 'number' || a instanceof Kotlin.Long || a.constructor.name == 'BigDecimal'; };
And the test (assertTrue { BigDecimal(1) is Number }) is passingOmar Mainegra
07/28/2020, 12:44 AMa instanceof Kotlin.BigDecimal it was complaining the right side is not an objectturansky
07/28/2020, 7:10 AMa instanceof BigDecimal - my expectation (without Kotlin.)turansky
07/28/2020, 7:11 AMBigDecimal is your custom class, isn’t it?Omar Mainegra
07/28/2020, 3:06 PMOmar Mainegra
07/28/2020, 3:12 PMReferenceError: BigDecimal is not definedOmar Mainegra
07/28/2020, 3:12 PMturansky
07/28/2020, 3:32 PMOmar Mainegra
07/28/2020, 3:33 PMBigDecimal.prototype = Object.create(Number_0.prototype);
BigDecimal.prototype.constructor = BigDecimal;Omar Mainegra
07/28/2020, 3:33 PMvar Number_0 = Kotlin.kotlin.Number;turansky
07/29/2020, 8:20 PMfunction BigDecimal ?Omar Mainegra
07/29/2020, 8:23 PMfunction BigDecimal(raw) {
BigDecimal$Companion_getInstance();
Number_0.call(this);
this.raw_0 = raw;
}turansky
07/29/2020, 8:28 PMinstanceof must work in that caseOmar Mainegra
07/29/2020, 8:36 PMturansky
07/29/2020, 11:46 PMOmar Mainegra
07/31/2020, 4:23 PMturansky
07/31/2020, 4:27 PMjsPatch in plain js (sideeffect mode)Omar Mainegra
07/31/2020, 4:28 PM