use of org.graalvm.polyglot.proxy.ProxyExecutable in project sulong by graalvm.
the class LLVMInteropTest method test008.
@Test
public void test008() {
try (Runner runner = new Runner("interop008")) {
runner.export(new ProxyExecutable() {
@Override
public Object execute(Value... t) {
return t[0].asByte() + t[1].asByte();
}
}, "foreign");
Assert.assertEquals(42, runner.run());
}
}
use of org.graalvm.polyglot.proxy.ProxyExecutable in project sulong by graalvm.
the class LLVMInteropTest method testConstruct002.
@Test
public void testConstruct002() {
final StringBuilder buf;
try (Runner runner = new Runner("construct002")) {
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\natexit\ndestruct\n", buf.toString());
}
use of org.graalvm.polyglot.proxy.ProxyExecutable in project graal by oracle.
the class PolyglotEngineOptionsTest method installSLBuiltin.
private static void installSLBuiltin(Context context, NodeFactory<? extends SLBuiltinNode> builtin) {
context.eval("sl", "function installBuiltin(e) { return e(); }");
context.getBindings("sl").getMember("installBuiltin").execute(new ProxyExecutable() {
@Override
public Object execute(Value... t) {
SLContext.getCurrent().installBuiltin(builtin);
return true;
}
});
}
use of org.graalvm.polyglot.proxy.ProxyExecutable in project graal by oracle.
the class SLExceptionTest method assertException.
private void assertException(boolean failImmediately, String source, String... expectedFrames) {
boolean initialExecute = true;
try {
Value value = ctx.eval("sl", source);
initialExecute = false;
if (failImmediately) {
Assert.fail("Should not reach here.");
}
ProxyExecutable proxy = (args) -> args[0].execute();
value.execute(proxy);
Assert.fail("Should not reach here.");
} catch (PolyglotException e) {
Assert.assertEquals(failImmediately, initialExecute);
assertFrames(failImmediately, e, expectedFrames);
}
}
use of org.graalvm.polyglot.proxy.ProxyExecutable in project graal by oracle.
the class SLExceptionTest method assertHostException.
private void assertHostException(String source, String... expectedFrames) {
boolean initialExecute = true;
RuntimeException[] exception = new RuntimeException[1];
try {
Value value = ctx.eval("sl", source);
initialExecute = false;
ProxyExecutable proxy = (args) -> {
throw exception[0] = new RuntimeException();
};
value.execute(proxy);
Assert.fail("Should not reach here.");
} catch (PolyglotException e) {
Assert.assertFalse(initialExecute);
Assert.assertTrue(e.asHostException() == exception[0]);
assertFrames(false, e, expectedFrames);
}
}
Aggregations