Crash when trying to close QuickJs while evaluating on iOS
Steps to reproduce (use iOS device or simulator):
- create QuickJs instance
- run evaluation of some long running code (for example await of some long running async code)
- while evaluation is still in progress call QuickJs.close()
Result: application crush.
Error: Unfortunately there is no any readable error, but the problem can be localized as I see.
Can't show file for stack frame : <DBGLLDBStackFrame: 0x1094d3550> - stackNumber:4 - name:JS_FreeRuntime. The file path does not exist on the file system: /Users/runner/work/quickjs-kt/quickjs-kt/quickjs/native/quickjs/quickjs.c
Code for quick reproduction: Test class in Kotlin:
public class Test {
private val scope = MainScope()
private val quickJs = QuickJs
.create(Dispatchers.Main)
.bindKotlinFunctions()
private var evalJob: Job? = null
public fun test() {
scope.launch {
evalJob = scope.launch {
quickJs.evaluate<Any?>(
"""
for (let i = 0; i < 10000; i++) {
console.log('ping');
await delay(500);
}
""".trimIndent()
)
}
delay(3000)
quickJs.close() // here is the crash
}
}
private fun QuickJs.bindKotlinFunctions(): QuickJs {
define("console") {
function("log") { args ->
println(args)
}
}
asyncFunction("delay") { args ->
delay(args[0] as Long)
}
return this
}
}
Use this class in Swift:
Test().test()
Can't show file for stack frame : <DBGLLDBStackFrame: 0x1094d3550> - stackNumber:4 - name:JS_FreeRuntime. The file path does not exist on the file system: /Users/runner/work/quickjs-kt/quickjs-kt/quickjs/native/quickjs/quickjs.c
Finally... somebody has the same situation! Could you please help us to solve this issue?:)