use of com.oracle.truffle.api.test.polyglot.HostAccessTest.MyEquals in project graal by oracle.
the class HostAccessExamplesTest method banAccessToReflection.
@Test
public void banAccessToReflection() throws Exception {
// @formatter:off
HostAccess config = HostAccess.newBuilder().allowPublicAccess(true).denyAccess(Class.class).denyAccess(Method.class).denyAccess(Field.class).denyAccess(Proxy.class).denyAccess(Object.class, false).build();
try (Context context = Context.newBuilder().allowHostAccess(config).build()) {
Value readValue = context.eval("sl", "" + "function readValue(x, y) {\n" + " return x.equals(y);\n" + "}\n" + "function main() {\n" + " return readValue;\n" + "}\n");
MyEquals myEquals = new MyEquals();
assertTrue("MyEquals.equals method is accessible", readValue.execute(myEquals, myEquals).asBoolean());
Value res;
try {
res = readValue.execute(new Object());
} catch (PolyglotException ex) {
return;
}
fail("expecting no result: " + res);
}
}
Aggregations