oracle / graaljs

GraalJS – A high-performance, ECMAScript compliant, and embeddable JavaScript runtime for Java
https://www.graalvm.org/javascript/
Universal Permissive License v1.0
1.82k stars 191 forks source link

Promise then/catch not working #865

Closed Strydom closed 3 weeks ago

Strydom commented 3 weeks ago

I'm not sure what is going on, but the promise then/catch is not working. Weirdly it was working at some point then seems to have stopped. If i put breakpoints within the functions they don't stop either, like they are never being called.

running on graalvm-jdk-22, kotlin 2.0.10 & kotlin.test

@Test
fun `Graalvm promise execution`() {
    val context = Context
        .newBuilder("js")
        .allowAllAccess(true)
        .allowHostAccess(HostAccess.ALL)
        .allowIO(IOAccess.ALL)
        .build()

    context
        .eval("js", "async function render(x) { return x }")

    val response = context
        .getBindings("js")
        .getMember("render")
        .execute(10)

    println(response)

    val then = response
        .invokeMember("then", { value: Value ->
            println(value)
        })
        .invokeMember("catch", { value: Value ->
            println(value)
        })

    println(then)
}

Output:

Promise{[[PromiseStatus]]: "resolved", [[PromiseValue]]: 10}
Promise{[[PromiseStatus]]: "resolved", [[PromiseValue]]: 10}
Strydom commented 3 weeks ago

Ah I removed the Consumer, it should be

.invokeMember("then", Consumer<Any> { value: Any ->
    println(value)
})