fix(scripting): setField java object unwrap

This commit is contained in:
rhunk 2023-10-11 23:38:46 +02:00
parent 3cd628f7cf
commit 9d7556eafd

View File

@ -39,7 +39,12 @@ class JSModule(
moduleObject.putFunction("setField") { args ->
val obj = args?.get(0) as? NativeJavaObject ?: return@putFunction Undefined.instance
val name = args[1].toString()
val value = args[2]
val value = args[2].let {
when (it) {
is Wrapper -> it.unwrap()
else -> it
}
}
val field = obj.unwrap().javaClass.declaredFields.find { it.name == name } ?: return@putFunction Undefined.instance
field.isAccessible = true
field.set(obj.unwrap(), value.toPrimitiveValue(lazy { field.type.name }))