changeset 22081:ff531952a91c

Making sure IOException from TruffleLanguage.parse method is correctly propagated to TruffleVM.eval caller.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Fri, 14 Aug 2015 13:57:12 +0200
parents 65e9fbb40e51
children 062c512dd677
files truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ExceptionDuringParsingTest.java truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java
diffstat 3 files changed, 54 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ExceptionDuringParsingTest.java	Fri Aug 14 13:57:12 2015 +0200
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.api.test.vm;
+
+import com.oracle.truffle.api.impl.Accessor;
+import static com.oracle.truffle.api.test.vm.ImplicitExplicitExportTest.L1;
+import com.oracle.truffle.api.vm.TruffleVM;
+import java.io.IOException;
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+public class ExceptionDuringParsingTest {
+    public static Accessor API;
+
+    @Test
+    public void canGetAccessToOwnLanguageInstance() throws Exception {
+        TruffleVM vm = TruffleVM.newVM().build();
+        TruffleVM.Language language = vm.getLanguages().get(L1);
+        assertNotNull("L1 language is defined", language);
+
+        try {
+            vm.eval(L1, "parse=No, no, no!");
+            fail("Exception thrown");
+        } catch (IOException ex) {
+            assertEquals(ex.getMessage(), "No, no, no!");
+        }
+    }
+}
--- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java	Thu Aug 13 18:22:22 2015 +0200
+++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java	Fri Aug 14 13:57:12 2015 +0200
@@ -128,6 +128,9 @@
 
         @Override
         protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
+            if (code.getCode().startsWith("parse=")) {
+                throw new IOException(code.getCode().substring(6));
+            }
             return new ValueCallTarget(code, this);
         }
 
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java	Thu Aug 13 18:22:22 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java	Fri Aug 14 13:57:12 2015 +0200
@@ -120,7 +120,9 @@
      *            {@link CallTarget#call(java.lang.Object...)}
      * @return a call target to invoke which also keeps in memory the {@link Node} tree representing
      *         just parsed <code>code</code>
-     * @throws IOException thrown when I/O or parsing goes wrong
+     * @throws IOException thrown when I/O or parsing goes wrong. Here-in thrown exception is
+     *             propagate to the user who called one of <code>eval</code> methods of
+     *             {@link TruffleVM}
      */
     protected abstract CallTarget parse(Source code, Node context, String... argumentNames) throws IOException;