Search in sources :

Example 11 with HostAccess

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);
}
Also used : HostAccess(org.graalvm.polyglot.HostAccess) Test(org.junit.Test)

Example 12 with HostAccess

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);
}
Also used : HostAccess(org.graalvm.polyglot.HostAccess) URLClassLoader(java.net.URLClassLoader) Value(org.graalvm.polyglot.Value) URLClassLoader(java.net.URLClassLoader) PolyglotException(org.graalvm.polyglot.PolyglotException) Test(org.junit.Test)

Example 13 with HostAccess

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);
    }
}
Also used : Context(org.graalvm.polyglot.Context) HostAccess(org.graalvm.polyglot.HostAccess) Test(org.junit.Test)

Example 14 with HostAccess

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);
    }
}
Also used : HostAccess(org.graalvm.polyglot.HostAccess)

Example 15 with HostAccess

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());
}
Also used : HostAccess(org.graalvm.polyglot.HostAccess)

Aggregations

HostAccess (org.graalvm.polyglot.HostAccess)35 Test (org.junit.Test)30 Context (org.graalvm.polyglot.Context)25 Value (org.graalvm.polyglot.Value)25 LanguageContext (com.oracle.truffle.api.test.polyglot.ProxyLanguage.LanguageContext)13 PolyglotException (org.graalvm.polyglot.PolyglotException)6 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)6 Export (org.graalvm.polyglot.HostAccess.Export)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 ValueAssert.assertValue (com.oracle.truffle.tck.tests.ValueAssert.assertValue)2 Field (java.lang.reflect.Field)2 URLClassLoader (java.net.URLClassLoader)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Function (java.util.function.Function)2 TypeLiteral (org.graalvm.polyglot.TypeLiteral)2 ProxyArray (org.graalvm.polyglot.proxy.ProxyArray)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2