use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class ProxySPITest method assertEmpty.
private static void assertEmpty(Message message, TruffleObject proxyInner) {
try {
TruffleObject values = (TruffleObject) ForeignAccess.send(message.createNode(), proxyInner);
Assert.assertEquals(true, ForeignAccess.sendHasSize(Message.HAS_SIZE.createNode(), values));
Assert.assertEquals(0, ((Number) ForeignAccess.sendGetSize(Message.GET_SIZE.createNode(), values)).intValue());
} catch (InteropException e) {
Assert.fail();
}
}
use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class NumericNFITest method testPingPong.
@Test
public void testPingPong(@Inject(TestPingPongNode.class) CallTarget callTarget) {
TruffleObject wrap = new TestCallback(1, (args) -> {
Assert.assertThat("argument", args[0], is(instanceOf(TruffleObject.class)));
TruffleObject fn = (TruffleObject) args[0];
TruffleObject wrapped = new TestCallback(1, (innerArgs) -> {
checkExpectedArg(6, innerArgs[0]);
try {
return ForeignAccess.sendExecute(Message.createExecute(1).createNode(), fn, unboxNumber(innerArgs[0]) * 3);
} catch (InteropException ex) {
throw new AssertionError(ex);
}
});
return wrapped;
});
Object ret = callTarget.call(wrap, 5);
checkExpectedRet(38, ret);
}
use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class ObjectNFITest method initEnv.
@BeforeClass
public static void initEnv() {
TruffleObject createNewObject = new TestCallback(0, (args) -> new TestObject());
TruffleObject readIntField = new TestCallback(2, (args) -> {
Assert.assertThat("args[0]", args[0], is(instanceOf(TestObject.class)));
Assert.assertThat("args[1]", args[1], is(instanceOf(String.class)));
return ((TestObject) args[0]).readField((String) args[1]);
});
TruffleObject writeIntField = new TestCallback(3, (args) -> {
Assert.assertThat("args[0]", args[0], is(instanceOf(TestObject.class)));
Assert.assertThat("args[1]", args[1], is(instanceOf(String.class)));
Assert.assertThat("args[2]", args[2], is(instanceOf(Integer.class)));
((TestObject) args[0]).writeField((String) args[1], (Integer) args[2]);
return null;
});
TruffleObject initializeAPI = lookupAndBind("initialize_api", "( env, ():object, (object,string):sint32, (object,string,sint32):void ) : pointer");
try {
nativeAPI = (TruffleObject) ForeignAccess.sendExecute(Message.createExecute(3).createNode(), initializeAPI, createNewObject, readIntField, writeIntField);
} catch (InteropException ex) {
throw new AssertionError(ex);
}
}
use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class AsCollectionsTest method testInvokeListOfMapProxy.
@Test
public void testInvokeListOfMapProxy() throws InteropException {
TruffleObject validator = com.oracle.truffle.api.interop.java.JavaInterop.asTruffleObject(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ProxyValidator.class }, (p, method, args) -> {
List<Map> listOfMap = (List<Map>) args[0];
assertEquals(1, listOfMap.size());
Map map = listOfMap.get(0);
assertEquals(1, map.size());
assertEquals("bar", map.get("foo"));
return true;
}));
MapBasedTO mapTO = new MapBasedTO(Collections.singletonMap("foo", "bar"));
TruffleObject listOfMapTO = new ListBasedTO(Arrays.asList(mapTO));
assertEquals(Boolean.TRUE, ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), validator, "test", listOfMapTO));
}
use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class PolyglotLanguageContext method lookupGuest.
Object lookupGuest(String symbolName) {
ensureInitialized(null);
Iterable<?> topScopes = VMAccessor.instrumentAccess().findTopScopes(env);
for (Object topScope : topScopes) {
Scope scope = (Scope) topScope;
TruffleObject variables = (TruffleObject) scope.getVariables();
int symbolInfo = ForeignAccess.sendKeyInfo(keyInfoNode, variables, symbolName);
if (KeyInfo.isExisting(symbolInfo) && KeyInfo.isReadable(symbolInfo)) {
try {
return ForeignAccess.sendRead(readNode, variables, symbolName);
} catch (InteropException ex) {
throw new AssertionError(symbolName, ex);
}
}
}
return null;
}
Aggregations