Skip to content

Commit

Permalink
[GR-5004] Java Interop should throw InteropException for illegal argu…
Browse files Browse the repository at this point in the history
…ments.
  • Loading branch information
woess committed Jul 13, 2017
2 parents f343c22 + c7c10a7 commit 2d4662b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package com.oracle.truffle.api.interop.java.test;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.MessageResolution;
Expand Down Expand Up @@ -57,14 +56,6 @@ public int hashCode() {
}
}

@Resolve(message = "com.oracle.truffle.api.interop.java.ClassMessage")
abstract static class MessageWithFrameNode extends Node {
protected Object access(VirtualFrame frame, TruffleObject receiver) {
return frame.toString() + receiver.toString();
}

}

@Resolve(message = "com.oracle.truffle.api.interop.java.test.OwnMessageResolutionTest.MyMsg")
abstract static class MessageWithoutFrameNode extends Node {
protected Object access(JObj receiver) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.Node;

Expand Down Expand Up @@ -508,6 +509,8 @@ private static Object invoke(SingleMethodDesc method, Object obj, Object[] argum
Object ret;
try {
ret = method.invoke(obj, arguments);
} catch (IllegalArgumentException ex) {
throw UnsupportedTypeException.raise(arguments);
} catch (Throwable ex) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,17 +528,6 @@ public static <K, V> Map<K, V> getMapView(Map<K, V> map, boolean includeInternal
return tmap.cloneInternal(includeInternal);
}

/**
* A message to find out Java class for {@link TruffleObject}s wrapping plain
* {@link #asTruffleObject(java.lang.Object) Java objects}. The receiver of the message shall be
* an object created via {@link #asTruffleObject(java.lang.Object) asTruffleObject(original)}
* method and it is supposed to return the same object as
* {@link #asTruffleObject(java.lang.Object) asTruffleObject(original.getClass())}.
* <p>
* not yet public
*/
static final Message CLASS_MESSAGE = ClassMessage.INSTANCE;

/**
* Finds a Java class representation for the provided object. If the object was created via
* {@link #asTruffleObject(java.lang.Object) asTruffleObject(original)} call, then it is
Expand All @@ -555,13 +544,15 @@ public static <K, V> Map<K, V> getMapView(Map<K, V> map, boolean includeInternal
* @since 0.26
*/
public static TruffleObject toJavaClass(TruffleObject obj) {
CompilerAsserts.neverPartOfCompilation();
try {
return (TruffleObject) ForeignAccess.send(CLASS_MESSAGE.createNode(), obj);
} catch (UnsupportedMessageException ex) {
if (obj instanceof JavaObject) {
JavaObject receiver = (JavaObject) obj;
if (receiver.isClass()) {
return new JavaObject(null, receiver.clazz.getClass(), receiver.languageContext);
} else {
return new JavaObject(null, receiver.clazz, receiver.languageContext);
}
} else {
return null;
} catch (InteropException ex) {
throw ex.raise();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,18 +322,6 @@ public int access(JavaObject receiver, String name) {
}
}

@Resolve(message = "com.oracle.truffle.api.interop.java.ClassMessage")
abstract static class ClassMessageNode extends Node {
protected Object access(JavaObject receiver) {
if (receiver.isClass()) {
return new JavaObject(null, receiver.clazz.getClass());
} else {
return new JavaObject(null, receiver.clazz);
}
}

}

@Resolve(message = "IS_EXECUTABLE")
abstract static class IsExecutableObjectNode extends Node {

Expand Down

0 comments on commit 2d4662b

Please sign in to comment.