use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class LateBindNFITest method testLateBind.
private static void testLateBind(CallTarget callTarget, Object symbol, Object signature) {
TruffleObject increment;
try {
increment = (TruffleObject) ForeignAccess.sendRead(Message.READ.createNode(), testLibrary, symbol);
} catch (InteropException e) {
throw new AssertionError(e);
}
Object ret = callTarget.call(increment, signature, 41);
Assert.assertThat("return value", ret, is(instanceOf(Integer.class)));
Assert.assertEquals("return value", 42, (int) (Integer) ret);
}
use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class JavaInteropTest method testException2.
@Test
public void testException2() throws InteropException {
TruffleObject hashMapClass = JavaInterop.asTruffleObject(HashMap.class);
try {
ForeignAccess.sendNew(Message.createNew(0).createNode(), hashMapClass, -1);
fail("expected an exception but none was thrown");
} catch (InteropException ex) {
throw ex;
} catch (Exception ex) {
assertTrue("expected HostException but was: " + ex.getClass(), JavaInterop.isHostException(ex));
assertThat(JavaInterop.asHostException(ex), CoreMatchers.instanceOf(IllegalArgumentException.class));
}
try {
ForeignAccess.sendNew(Message.createNew(0).createNode(), hashMapClass, "");
fail("expected an exception but none was thrown");
} catch (UnsupportedTypeException ex) {
}
}
use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.
the class JavaInteropTest method testException.
@Test
public void testException() throws InteropException {
TruffleObject iterator = JavaInterop.asTruffleObject(Collections.emptyList().iterator());
try {
ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), iterator, "next");
fail("expected an exception but none was thrown");
} catch (InteropException ex) {
throw ex;
} catch (Exception ex) {
assertTrue("expected HostException but was: " + ex.getClass(), JavaInterop.isHostException(ex));
assertThat(JavaInterop.asHostException(ex), CoreMatchers.instanceOf(NoSuchElementException.class));
}
}
use of com.oracle.truffle.api.interop.InteropException in project sulong by graalvm.
the class LLVMPolyglotImport method doImport.
@Specialization
protected Object doImport(Object name, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
String symbolName = readString.executeWithTarget(name);
LLVMContext ctx = ctxRef.get();
try {
Object ret = ForeignAccess.sendRead(read, (TruffleObject) ctx.getEnv().getPolyglotBindings(), symbolName);
return toLLVM.executeWithTarget(ret);
} catch (InteropException ex) {
throw ex.raise();
}
}
Aggregations