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);
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.
This issue is fixed by https://github.com/graalvm/graaljs/commit/358c10fe8557dbefe021bfc262e87507992fbfa3.
Most helpful comment
Thank out for the bug report. I can confirm that the mentioned test-case works in
rc14but does not work inrc15. This bug is an unwanted consequence of the introduction of a new API for language interoperability. I will fix it.