Graaljs: Class from anonymous function cannot instantiate

Created on 11 Apr 2019  路  2Comments  路  Source: oracle/graaljs

This example test fails on RC15. It used to work (at least on RC12). In Groovy:

@Test
void "class can instantiate"() {
    def context = Context.create("js")

    def exports = context.eval("js", """
        (function() {
            class MyClass {}
            return {
                MyClass: MyClass,
            };
        })()
    """)
    def jsClass = exports.getMember("MyClass")
    assertThat jsClass.canInstantiate() isTrue() // fails
}

We're using this mechanism so we can clear bindings, as explained in https://github.com/graalvm/graaljs/issues/146

As a workaround, jsClass.canExecute() is still true, so we can do something like:

String tempCtorRefName = "MyClassCtorRef";
Value bindings = context.getBindings("js");
bindings.putMember(tempCtorRefName, jsClass);
Value instance = context.eval("js", "new " + tempCtorRefName + "();");
bindings.removeMember(tempCtorRefName);
bug

Most helpful comment

Thank out for the bug report. I can confirm that the mentioned test-case works in rc14 but does not work in rc15. This bug is an unwanted consequence of the introduction of a new API for language interoperability. I will fix it.

All 2 comments

Thank out for the bug report. I can confirm that the mentioned test-case works in rc14 but does not work in rc15. This bug is an unwanted consequence of the introduction of a new API for language interoperability. I will fix it.

Was this page helpful?
0 / 5 - 0 ratings