Open
Description
Hey folks,
After reading the Graal 22 announcement I was excited to pick up the new methodScoping
feature, unfortunately when I did some of my tests started to fail with ArrayIndexOutOfBoundsException
. It seems to be an issue with how "parameters" are counted with varArgs being grouped together into a single argument but treated as separate parameters when being added to the scope.
I've put together a minimal repro to demonstrate the broken behaviour and hopefully help you guys fix it.
public class ScopeAccessRepro {
@Test
void scopedHostAccess() {
Context ctx = createContext(HostAccess.SCOPED);
Value function = ctx.eval("js", "(host => host.scopedVarArgs(" + "\"hello\"," + "{}," + "{} " + "))");
assertThatThrownBy(() -> function.execute(new HostClass()).as(Void.class))
.isInstanceOf(PolyglotException.class)
.hasMessageContaining("java.lang.ArrayIndexOutOfBoundsException");
}
@Test
void nonScopedHostAccess() {
Context ctx = createContext(
HostAccess.newBuilder(HostAccess.SCOPED).methodScoping(false).build());
Value function = ctx.eval("js", "(host => host.scopedVarArgs(" + "\"hello\"," + "{}," + "{} " + "))");
function.execute(new HostClass()).as(Void.class);
}
private static Context createContext(HostAccess hostAccess) {
return Context.newBuilder()
.engine(Engine.newBuilder().build())
.allowHostAccess(hostAccess)
.build();
}
public final class HostClass {
HostClass() {}
@Export
public void scopedVarArgs(String value1, Value... varArgs) {}
}
}