use of org.graalvm.polyglot.proxy.ProxyExecutable in project graal by oracle.
the class PolyglotExceptionTest method testLanguageExceptionUnwrapping.
@Test
public void testLanguageExceptionUnwrapping() {
Context context = Context.create();
Value throwError = context.asValue(new ProxyExecutable() {
public Object execute(Value... arguments) {
throw new RuntimeException();
}
});
VerifyErrorTruffleObject checkErrorObj = new VerifyErrorTruffleObject();
Value checkError = context.asValue(checkErrorObj);
checkErrorObj.verifyError = (e) -> {
Assert.assertTrue(e instanceof TruffleException);
Assert.assertEquals("HostException", e.getClass().getSimpleName());
};
Assert.assertTrue(checkError.execute(throwError).asBoolean());
context.close();
}
use of org.graalvm.polyglot.proxy.ProxyExecutable in project graal by oracle.
the class ProxySPITest method testProxyExecutable.
@Test
public void testProxyExecutable() throws Throwable {
Context context = Context.create();
ProxyExecutable proxyOuter = new ProxyExecutable() {
public Object execute(Value... t) {
return t[0].asInt();
}
};
eval(context, proxyOuter, (proxyInner) -> {
assertEquals(true, Message.IS_EXECUTABLE, proxyInner);
assertEquals(42, Message.createExecute(0), proxyInner, 42);
assertUnsupported(Message.createNew(0), proxyInner, 42);
assertUnsupported(Message.AS_POINTER, proxyInner);
assertUnsupported(Message.GET_SIZE, proxyInner);
assertEmpty(Message.KEYS, proxyInner);
assertUnsupported(Message.READ, proxyInner);
assertUnsupported(Message.WRITE, proxyInner);
assertUnsupported(Message.TO_NATIVE, proxyInner);
assertUnsupported(Message.UNBOX, proxyInner);
assertUnsupported(Message.createInvoke(0), proxyInner);
assertEquals(false, Message.IS_INSTANTIABLE, proxyInner);
assertEquals(false, Message.IS_BOXED, proxyInner);
assertEquals(false, Message.IS_NULL, proxyInner);
assertEquals(false, Message.HAS_KEYS, proxyInner);
assertEquals(false, Message.HAS_SIZE, proxyInner);
assertEquals(false, Message.IS_POINTER, proxyInner);
assertEquals(0, Message.KEY_INFO, proxyInner);
return null;
});
}
use of org.graalvm.polyglot.proxy.ProxyExecutable in project sulong by graalvm.
the class LLVMInteropTest method test009.
@Test
public void test009() {
try (Runner runner = new Runner("interop009")) {
runner.export(new ProxyExecutable() {
@Override
public Object execute(Value... t) {
return t[0].asInt() + t[1].asInt();
}
}, "foreign");
Assert.assertEquals(42, runner.run());
}
}
use of org.graalvm.polyglot.proxy.ProxyExecutable in project sulong by graalvm.
the class LLVMInteropTest method test011.
@Test
public void test011() {
try (Runner runner = new Runner("interop011")) {
runner.export(new ProxyExecutable() {
@Override
public Object execute(Value... t) {
return t[0].asFloat() + t[1].asFloat();
}
}, "foreign");
Assert.assertEquals(42.0, runner.run(), 0.1);
}
}
use of org.graalvm.polyglot.proxy.ProxyExecutable in project sulong by graalvm.
the class LLVMInteropTest method testConstruct001.
@Test
public void testConstruct001() {
final StringBuilder buf;
try (Runner runner = new Runner("construct001")) {
buf = new StringBuilder();
runner.export(new ProxyExecutable() {
@Override
public Object execute(Value... t) {
Assert.assertEquals("argument count", 1, t.length);
if (t[0].isString()) {
buf.append(t[0].asString());
} else {
Assert.fail("unexpected value type");
}
return 0;
}
}, "callback");
runner.load();
Assert.assertEquals("construct\n", buf.toString());
}
Assert.assertEquals("construct\ndestruct\n", buf.toString());
}
Aggregations