Skip to content

Difference in Unit serialization for J2V8 and Hermes #842

Description

@tmarmer

Describe the bug
When deserialization the result of a JS function using a UnitSerializer, Hermes implementation discards the result, but J2V8 throws an error trying to deserialize the result into a Unit

To Reproduce
The following are two tests that run the same JS function and deserialize using the UnitSerializer. One is formatted to work with the J2V8 runtime, the other with Hermes. The Hermes test will pass and the J2V8 test will throw an exception:
J2V8:

@Test
fun `test unit`() {
    v8.evaluateInJSThreadBlocking(runtime) {
        val jsFunc = v8.executeObjectScript("""() => ({ "prop": "value" })""").v8Function
        val invokable = jsFunc.toInvokable(format, v8Object, format.serializer<Unit>())

        assertNotNull(invokable)
        assertEquals(Unit, invokable.invoke())
    }
}

Hermes:

@Test
fun `test unit`() {
    runtime.evaluateInJSThreadBlocking {
        val jsFunc = runtime.evaluateJavaScript("""() => ({ "prop": "value" })""").asObject(runtime).asFunction(runtime)
        val invokable = jsFunc.toInvokable(format, jsFunc, format.serializer<Unit>())

        assertNotNull(invokable)
        assertEquals(Unit, invokable.invoke())
    }
}

Expected behavior
Functionality should be the same across runtimes. Keeping the J2V8 functionality may be preferred to ensure that JS function results aren't accidentally being thrown out.

Environment:

  • OS: Android

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions