Skip to content

Commit

Permalink
make sure foreign exceptions also check for available type conversion…
Browse files Browse the repository at this point in the history
…s before wrapping them to Espresso ForeignExceptions
  • Loading branch information
javeleon committed Dec 22, 2023
1 parent 489611a commit 8206a57
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8206a57

Please sign in to comment.