Skip to content

Commit

Permalink
[GR-51113] Backport 23.1: Fix type converter combination for foreign …
Browse files Browse the repository at this point in the history
…exceptions and custom type converters.

PullRequest: graal/16471
  • Loading branch information
marwan-hallaoui committed Jan 4, 2024
2 parents f01bcd8 + c16ccfb commit 7a7dffa
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1068,18 +1068,45 @@ 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) {
try {
return tryTypeConversion(value, interop, lookupProxyKlassNode, lookupTypeConverterNode, lookupInternalTypeConverterNode, converterToEspresso, errorProfile, meta);
} catch (@SuppressWarnings("unused") UnsupportedTypeException ex) {
// no meta object available, but we know it's a foreign exception so simply wrap
return StaticObject.createForeignException(context, value, interop);
}
}

@Specialization(guards = {
"interop.hasArrayElements(value)",
"!isTypeMappingEnabled(context)",
Expand Down Expand Up @@ -1217,7 +1244,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 7a7dffa

Please sign in to comment.