@@ -1076,18 +1076,45 @@ StaticObject doForeignString(Object value,
1076
1076
1077
1077
@ Specialization (guards = {
1078
1078
"interop.isException(value)" ,
1079
+ "!isTypeMappingEnabled(context)" ,
1079
1080
"!isStaticObject(value)" ,
1080
1081
"!interop.isNull(value)" ,
1081
1082
"!isHostString(value)" ,
1082
1083
"!isEspressoException(value)" ,
1083
1084
"!isBoxedPrimitive(value)"
1084
1085
})
1085
- StaticObject doForeignException (Object value ,
1086
+ StaticObject doForeignExceptionNoTypeMapping (Object value ,
1086
1087
@ Cached .Shared ("value" ) @ CachedLibrary (limit = "LIMIT" ) InteropLibrary interop ,
1087
1088
@ SuppressWarnings ("unused" ) @ Bind ("getContext()" ) EspressoContext context ) {
1088
1089
return StaticObject .createForeignException (context , value , interop );
1089
1090
}
1090
1091
1092
+ @ Specialization (guards = {
1093
+ "interop.isException(value)" ,
1094
+ "isTypeMappingEnabled(context)" ,
1095
+ "!isStaticObject(value)" ,
1096
+ "!interop.isNull(value)" ,
1097
+ "!isHostString(value)" ,
1098
+ "!isEspressoException(value)" ,
1099
+ "!isBoxedPrimitive(value)"
1100
+ })
1101
+ StaticObject doForeignExceptionTypeMapping (Object value ,
1102
+ @ Cached .Shared ("value" ) @ CachedLibrary (limit = "LIMIT" ) InteropLibrary interop ,
1103
+ @ SuppressWarnings ("unused" ) @ Bind ("getContext()" ) EspressoContext context ,
1104
+ @ Cached BranchProfile errorProfile ,
1105
+ @ Cached LookupProxyKlassNode lookupProxyKlassNode ,
1106
+ @ Cached LookupTypeConverterNode lookupTypeConverterNode ,
1107
+ @ Cached LookupInternalTypeConverterNode lookupInternalTypeConverterNode ,
1108
+ @ Cached ToReference .DynamicToReference converterToEspresso ,
1109
+ @ Bind ("getMeta()" ) Meta meta ) {
1110
+ try {
1111
+ return tryTypeConversion (value , interop , lookupProxyKlassNode , lookupTypeConverterNode , lookupInternalTypeConverterNode , converterToEspresso , errorProfile , meta );
1112
+ } catch (@ SuppressWarnings ("unused" ) UnsupportedTypeException ex ) {
1113
+ // no meta object available, but we know it's a foreign exception so simply wrap
1114
+ return StaticObject .createForeignException (context , value , interop );
1115
+ }
1116
+ }
1117
+
1091
1118
@ Specialization (guards = {
1092
1119
"interop.hasArrayElements(value)" ,
1093
1120
"!isTypeMappingEnabled(context)" ,
@@ -1225,7 +1252,11 @@ private StaticObject tryTypeConversion(Object value, InteropLibrary interop, Loo
1225
1252
} else {
1226
1253
PolyglotTypeMappings .TypeConverter converter = lookupTypeConverterNode .execute (metaName );
1227
1254
if (converter != null ) {
1228
- return (StaticObject ) converter .convert (StaticObject .createForeign (getLanguage (), meta .java_lang_Object , value , interop ));
1255
+ if (interop .isException (value )) {
1256
+ return (StaticObject ) converter .convert (StaticObject .createForeignException (getContext (), value , interop ));
1257
+ } else {
1258
+ return (StaticObject ) converter .convert (StaticObject .createForeign (getLanguage (), meta .java_lang_Object , value , interop ));
1259
+ }
1229
1260
}
1230
1261
1231
1262
// check if foreign exception
0 commit comments