commonMain.com.dokar.quickjs.converter.builtinTypes.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quickjs-kt Show documentation
Show all versions of quickjs-kt Show documentation
A QuickJS binding for idiomatic Kotlin, with Async/DSL/ES Modules support.
The newest version!
package com.dokar.quickjs.converter
import com.dokar.quickjs.binding.JsObject
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.typeOf
@OptIn(ExperimentalContracts::class)
@PublishedApi
internal fun canConvertReturnInternally(instance: Any?): Boolean {
contract {
returns(false) implies (instance != null)
}
instance ?: return true
return typeOfInstance(instance) != null
}
@OptIn(ExperimentalUnsignedTypes::class)
@PublishedApi
internal fun typeOfClass(typeConverters: TypeConverters, cls: KClass<*>): KType {
return when (cls) {
Unit::class -> typeOf()
Int::class -> typeOf()
Long::class -> typeOf()
Float::class -> typeOf()
Double::class -> typeOf()
Boolean::class -> typeOf()
String::class -> typeOf()
ByteArray::class -> typeOf()
UByteArray::class -> typeOf()
Array::class -> typeOf>()
List::class -> typeOf>()
Set::class -> typeOf>()
JsObject::class -> typeOf()
Map::class -> typeOf