dokar3 / quickjs-kt

A QuickJS binding for idiomatic Kotlin, with Async/DSL/ES Modules support.
Apache License 2.0
31 stars 3 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 3 weeks ago

TelephoneTan commented 1 month 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 1 month 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 1 month 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 1 month 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 4 weeks ago

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

TelephoneTan commented 3 weeks ago

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

dokar3 commented 3 weeks ago

Updated!