use of org.graalvm.polyglot.HostAccess in project graal by oracle.
the class HostAccessTest method testBufferAccessEnabledHostAccessCloned.
@Test
public void testBufferAccessEnabledHostAccessCloned() {
HostAccess hostAccess = HostAccess.newBuilder().allowBufferAccess(true).build();
setupEnv(HostAccess.newBuilder(hostAccess));
assertBufferAccessEnabled(context);
}
use of org.graalvm.polyglot.HostAccess in project graal by oracle.
the class HostAccessTest method banAccessToOverwrittenLoadClass.
@Test
public void banAccessToOverwrittenLoadClass() throws Exception {
// @formatter:off
HostAccess config = HostAccess.newBuilder().allowPublicAccess(true).denyAccess(ClassLoader.class).build();
// @formatter:on
setupEnv(config);
Value loadClass = context.eval("sl", "" + "function loadClass(x) {\n" + " return x.loadClass(\"java.lang.String\");\n" + "}\n" + "function main() {\n" + " return loadClass;\n" + "}\n");
URLClassLoader loader = new MyClassLoader(new URL[0]);
Value res;
try {
res = loadClass.execute(loader);
} catch (PolyglotException ex) {
return;
}
fail("expecting no result: " + res);
}
use of org.graalvm.polyglot.HostAccess in project graal by oracle.
the class HostAccessTest method useOneHostAccessByTwoContexts.
@Test
public void useOneHostAccessByTwoContexts() throws Exception {
HostAccess config = HostAccess.newBuilder().allowAccess(OK.class.getField("value")).build();
try (Context c1 = Context.newBuilder().allowHostAccess(config).build();
Context c2 = Context.newBuilder().allowHostAccess(config).build()) {
assertAccess(c1);
assertAccess(c2);
}
}
use of org.graalvm.polyglot.HostAccess in project graal by oracle.
the class HostAccessTest method setupEnv.
private void setupEnv(HostAccess.Builder builder) {
tearDown();
if (builder != null) {
builder.allowImplementationsAnnotatedBy(FunctionalInterface.class);
builder.allowImplementationsAnnotatedBy(HostAccess.Implementable.class);
builder.allowAccessAnnotatedBy(HostAccess.Export.class);
HostAccess access = builder.build();
verifyObjectImpl(access);
setupEnv(access);
}
}
use of org.graalvm.polyglot.HostAccess in project graal by oracle.
the class HostAccessTest method verifyObjectImpl.
private static void verifyObjectImpl(HostAccess access) {
HostAccess otherAccess = HostAccess.newBuilder(access).build();
assertNotSame(access, otherAccess);
assertEquals(access, otherAccess);
assertEquals(access.hashCode(), otherAccess.hashCode());
assertNotNull(access.toString());
}
Aggregations