dokar3 / quickjs-kt

A QuickJS binding for idiomatic Kotlin, with Async/DSL/ES Modules support.
Apache License 2.0
49 stars 4 forks source link

com.dokar.quickjs.QuickJsException: No such type converter to convert 'long (Kotlin reflection is not available)' to 'int (Kotlin reflection is not available)' #97

Closed TelephoneTan closed 5 months ago

TelephoneTan commented 5 months ago

Kotlin:

asyncFunction<Int, Unit>(it) {
    res.send(it)
}

JS:

protoOf(JSImpl).version = function (res) { res(15); }

I pass the asyncFunction defined to version function in JS, then this exception is thrown

dokar3 commented 5 months ago

Changing Int to Long should solve this problem. But this is supposed to work too, I probably forgot to add auto casting for typed parameters.

Will fix this.

TelephoneTan commented 5 months ago

It will violate the interface in Kotlin code which declares this method should return Int if I simply change Int to Long. 😂

TelephoneTan commented 5 months ago

Hi, maybe we can map js number type to any suitable kotlin number type.

For example, if js number is smaller than Int.MAX_VALUE, the kotlin code can use Byte, Short, Long, if the kotlin code use Short type, only throw convertion exception when js value is bigger than Short.MAX_VALUE.

dokar3 commented 5 months ago

Good idea, might add this as part of the built-in type conversions.

TelephoneTan commented 4 months ago

@dokar3 Could you please change the README to state the latest type conversion behavior? ;-)

dokar3 commented 4 months ago

Updated!