Search in sources :

Example 6 with StackFrame

use of org.graalvm.polyglot.PolyglotException.StackFrame in project graal by oracle.

the class SLExceptionTest method assertHostFrame.

private static void assertHostFrame(Iterator<StackFrame> frames, String className, String methodName) {
    assertTrue(frames.hasNext());
    StackFrame frame = frames.next();
    assertTrue(frame.isHostFrame());
    assertFalse(frame.isGuestFrame());
    assertEquals("host", frame.getLanguage().getId());
    assertEquals("Host", frame.getLanguage().getName());
    assertEquals(className + "." + methodName, frame.getRootName());
    assertNull(frame.getSourceLocation());
    assertNotNull(frame.toString());
    StackTraceElement hostFrame = frame.toHostFrame();
    assertEquals(className, hostFrame.getClassName());
    assertEquals(methodName, hostFrame.getMethodName());
    assertNotNull(hostFrame.toString());
    assertTrue(hostFrame.equals(hostFrame));
    assertNotEquals(0, hostFrame.hashCode());
}
Also used : StackFrame(org.graalvm.polyglot.PolyglotException.StackFrame)

Example 7 with StackFrame

use of org.graalvm.polyglot.PolyglotException.StackFrame in project graal by oracle.

the class PolyglotExceptionImpl method materialize.

private void materialize() {
    if (this.materializedFrames == null) {
        List<StackFrame> frames = new ArrayList<>();
        for (StackFrame frame : getPolyglotStackTrace()) {
            frames.add(frame);
        }
        this.materializedFrames = Collections.unmodifiableList(frames);
    }
}
Also used : StackFrame(org.graalvm.polyglot.PolyglotException.StackFrame) ArrayList(java.util.ArrayList)

Example 8 with StackFrame

use of org.graalvm.polyglot.PolyglotException.StackFrame in project graal by oracle.

the class ValueHostConversionTest method testExceptionFrames1.

@Test
public void testExceptionFrames1() {
    Value innerInner = context.asValue(new Function<Object, Object>() {

        public Object apply(Object t) {
            throw new RuntimeException("foobar");
        }
    });
    Value inner = context.asValue(new Function<Object, Object>() {

        public Object apply(Object t) {
            return innerInner.execute(t);
        }
    });
    Value outer = context.asValue(new Function<Object, Object>() {

        public Object apply(Object t) {
            return inner.execute(t);
        }
    });
    try {
        outer.execute(1);
        Assert.fail();
    } catch (PolyglotException e) {
        assertTrue(e.isHostException());
        assertTrue(e.asHostException() instanceof RuntimeException);
        assertEquals("foobar", e.getMessage());
        Iterator<StackFrame> frameIterator = e.getPolyglotStackTrace().iterator();
        StackFrame frame;
        for (int i = 0; i < 3; i++) {
            frame = frameIterator.next();
            assertTrue(frame.isHostFrame());
            assertEquals("apply", frame.toHostFrame().getMethodName());
            frame = frameIterator.next();
            assertTrue(frame.isHostFrame());
            assertEquals("execute", frame.toHostFrame().getMethodName());
        }
        frame = frameIterator.next();
        assertTrue(frame.isHostFrame());
        assertEquals("testExceptionFrames1", frame.toHostFrame().getMethodName());
    }
}
Also used : StackFrame(org.graalvm.polyglot.PolyglotException.StackFrame) ValueAssert.assertValue(com.oracle.truffle.api.test.polyglot.ValueAssert.assertValue) Value(org.graalvm.polyglot.Value) Iterator(java.util.Iterator) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) PolyglotException(org.graalvm.polyglot.PolyglotException) Test(org.junit.Test)

Example 9 with StackFrame

use of org.graalvm.polyglot.PolyglotException.StackFrame in project graal by oracle.

the class ValueHostConversionTest method testExceptionFrames3.

@Test
public void testExceptionFrames3() {
    Value value = context.asValue(new TestExceptionFrames2());
    TestExceptionFrames3 f = value.as(TestExceptionFrames3.class);
    try {
        f.foo();
        Assert.fail();
    } catch (PolyglotException e) {
        assertTrue(e.isHostException());
        assertTrue(e.asHostException() instanceof RuntimeException);
        assertEquals("foo", e.getMessage());
        Iterator<StackFrame> frameIterator = e.getPolyglotStackTrace().iterator();
        StackFrame frame;
        frame = frameIterator.next();
        assertTrue(frame.isHostFrame());
        assertEquals("foo", frame.toHostFrame().getMethodName());
        frame = frameIterator.next();
        assertTrue(frame.isHostFrame());
        assertEquals("invoke", frame.toHostFrame().getMethodName());
        frame = frameIterator.next();
        assertTrue(frame.isHostFrame());
        assertEquals("foo", frame.toHostFrame().getMethodName());
        frame = frameIterator.next();
        assertTrue(frame.isHostFrame());
        assertEquals("testExceptionFrames3", frame.toHostFrame().getMethodName());
    }
}
Also used : StackFrame(org.graalvm.polyglot.PolyglotException.StackFrame) ValueAssert.assertValue(com.oracle.truffle.api.test.polyglot.ValueAssert.assertValue) Value(org.graalvm.polyglot.Value) Iterator(java.util.Iterator) PolyglotException(org.graalvm.polyglot.PolyglotException) Test(org.junit.Test)

Aggregations

StackFrame (org.graalvm.polyglot.PolyglotException.StackFrame)9 ValueAssert.assertValue (com.oracle.truffle.api.test.polyglot.ValueAssert.assertValue)4 Iterator (java.util.Iterator)4 PolyglotException (org.graalvm.polyglot.PolyglotException)4 Value (org.graalvm.polyglot.Value)4 Test (org.junit.Test)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 ArrayList (java.util.ArrayList)1 ProxyExecutable (org.graalvm.polyglot.proxy.ProxyExecutable)1 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)1