diff --git a/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToReference.java b/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToReference.java index c27a27349b6c..90f16dbacbc6 100644 --- a/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToReference.java +++ b/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/interop/ToReference.java @@ -1076,18 +1076,40 @@ StaticObject doForeignString(Object value, @Specialization(guards = { "interop.isException(value)", + "!isTypeMappingEnabled(context)", "!isStaticObject(value)", "!interop.isNull(value)", "!isHostString(value)", "!isEspressoException(value)", "!isBoxedPrimitive(value)" }) - StaticObject doForeignException(Object value, + StaticObject doForeignExceptionNoTypeMapping(Object value, @Cached.Shared("value") @CachedLibrary(limit = "LIMIT") InteropLibrary interop, @SuppressWarnings("unused") @Bind("getContext()") EspressoContext context) { return StaticObject.createForeignException(context, value, interop); } + @Specialization(guards = { + "interop.isException(value)", + "isTypeMappingEnabled(context)", + "!isStaticObject(value)", + "!interop.isNull(value)", + "!isHostString(value)", + "!isEspressoException(value)", + "!isBoxedPrimitive(value)" + }) + StaticObject doForeignExceptionTypeMapping(Object value, + @Cached.Shared("value") @CachedLibrary(limit = "LIMIT") InteropLibrary interop, + @SuppressWarnings("unused") @Bind("getContext()") EspressoContext context, + @Cached BranchProfile errorProfile, + @Cached LookupProxyKlassNode lookupProxyKlassNode, + @Cached LookupTypeConverterNode lookupTypeConverterNode, + @Cached LookupInternalTypeConverterNode lookupInternalTypeConverterNode, + @Cached ToReference.DynamicToReference converterToEspresso, + @Bind("getMeta()") Meta meta) throws UnsupportedTypeException { + return tryTypeConversion(value, interop, lookupProxyKlassNode, lookupTypeConverterNode, lookupInternalTypeConverterNode, converterToEspresso, errorProfile, meta); + } + @Specialization(guards = { "interop.hasArrayElements(value)", "!isTypeMappingEnabled(context)", @@ -1225,7 +1247,11 @@ private StaticObject tryTypeConversion(Object value, InteropLibrary interop, Loo } else { PolyglotTypeMappings.TypeConverter converter = lookupTypeConverterNode.execute(metaName); if (converter != null) { - return (StaticObject) converter.convert(StaticObject.createForeign(getLanguage(), meta.java_lang_Object, value, interop)); + if (interop.isException(value)) { + return (StaticObject) converter.convert(StaticObject.createForeignException(getContext(), value, interop)); + } else { + return (StaticObject) converter.convert(StaticObject.createForeign(getLanguage(), meta.java_lang_Object, value, interop)); + } } // check if foreign exception