quickjs-kt icon indicating copy to clipboard operation
quickjs-kt copied to clipboard

Crash when trying to close QuickJs while evaluating on iOS

Open keyflare opened this issue 9 months ago • 1 comments

Steps to reproduce (use iOS device or simulator):

  1. create QuickJs instance
  2. run evaluation of some long running code (for example await of some long running async code)
  3. 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()

keyflare avatar Mar 11 '25 14:03 keyflare

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?:)

TimofeyVolovatov avatar Mar 11 '25 15:03 TimofeyVolovatov