Skip to content

Commit f7f210c

Browse files
committed
[GR-44626] Espresso interop fixes relating to foreign exceptions.
PullRequest: graal/13969
2 parents e77557c + 54051da commit f7f210c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToEspressoNode.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
@GenerateUncached
6565
public abstract class ToEspressoNode extends EspressoNode {
6666

67+
public abstract Object execute(Object value, Klass targetType) throws UnsupportedTypeException;
68+
6769
public static final int LIMIT = 2;
6870

6971
// region Specialization predicates
@@ -137,11 +139,6 @@ static boolean isBoxedPrimitive(Object obj) {
137139
return obj instanceof Number || obj instanceof Character || obj instanceof Boolean;
138140
}
139141

140-
static boolean isForeignException(Klass klass) {
141-
Meta meta = klass.getMeta();
142-
return meta.polyglot != null /* polyglot enabled */ && meta.polyglot.ForeignException.equals(klass);
143-
}
144-
145142
static boolean isIntegerCompatible(Klass klass) {
146143
return klass.isAssignableFrom(klass.getMeta().java_lang_Integer);
147144
}
@@ -188,8 +185,6 @@ static boolean isHostObject(EspressoContext context, Object value) {
188185

189186
// endregion Specialization predicates
190187

191-
public abstract Object execute(Object value, Klass targetType) throws UnsupportedTypeException;
192-
193188
@Specialization(guards = "!isPrimitiveKlass(klass)")
194189
Object doEspresso(StaticObject value, Klass klass,
195190
@Cached BranchProfile exceptionProfile,
@@ -545,6 +540,10 @@ Object doForeignClassProxy(Object value, ObjectKlass klass,
545540
}
546541
} else {
547542
if (klass == meta.java_lang_Object) {
543+
// check if foreign exception
544+
if (interop.isException(value)) {
545+
return StaticObject.createForeignException(klass.getContext(), value, interop);
546+
}
548547
// see if a generated proxy can be used for interface mapped types
549548
ObjectKlass proxyKlass = lookupProxyKlassNode.execute(metaObject, metaName, klass);
550549
if (proxyKlass != null) {

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/Target_com_oracle_truffle_espresso_polyglot_Interop.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,9 @@ StaticObject doCached(
19741974
} catch (InteropException e) {
19751975
exceptionProfile.enter();
19761976
throw throwInteropExceptionAsGuest.execute(e);
1977+
} catch (EspressoException e) {
1978+
// make sure we don't try to convert espresso exceptions
1979+
throw e;
19771980
} catch (AbstractTruffleException ex) {
19781981
exceptionProfile.enter();
19791982
StaticObject foreignException = getAllocator().createForeignException(getContext(), ex, exceptionInterop);

0 commit comments

Comments
 (0)