Search in sources :

Example 11 with InteropException

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);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 12 with InteropException

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) {
    }
}
Also used : UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) InteropException(com.oracle.truffle.api.interop.InteropException) InteropException(com.oracle.truffle.api.interop.InteropException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) NoSuchElementException(java.util.NoSuchElementException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 13 with InteropException

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));
    }
}
Also used : InteropException(com.oracle.truffle.api.interop.InteropException) InteropException(com.oracle.truffle.api.interop.InteropException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) NoSuchElementException(java.util.NoSuchElementException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 14 with InteropException

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();
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Aggregations

InteropException (com.oracle.truffle.api.interop.InteropException)14 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)14 Test (org.junit.Test)4 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 Specialization (com.oracle.truffle.api.dsl.Specialization)2 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)2 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)2 Node (com.oracle.truffle.api.nodes.Node)2 ValueHostInteropTest (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)2 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)2 TestCallback (com.oracle.truffle.nfi.test.interop.TestCallback)2 NoSuchElementException (java.util.NoSuchElementException)2 BeforeClass (org.junit.BeforeClass)2 Scope (com.oracle.truffle.api.Scope)1 ExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode)1 MaterializeChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode)1 MaterializedChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode)1 ForeignAccess (com.oracle.truffle.api.interop.ForeignAccess)1 Message (com.oracle.truffle.api.interop.Message)1