From ca8b144e384e5917cf3b89ad727d870c04175ee0 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 1 May 2026 15:29:04 +0200 Subject: [PATCH 1/3] Fix some typos --- .../src/com/oracle/truffle/api/TruffleContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleContext.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleContext.java index 2a9888432e1b..64ee7198d1b6 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleContext.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleContext.java @@ -1274,7 +1274,7 @@ public Builder onExited(Consumer r) { /** * Specifies a {@link Runnable} that will be executed when some operation on the new context - * attenmpted while the context is already {@link TruffleContext#close()} closed}. However, + * attempted while the context is already {@link TruffleContext#close() closed}. However, * the runnable will only be executed if the outer context is not closed. * * The purpose of the runnable is to allow throwing a custom guest exception before the From 89b1120a99f0832721521dbb9ea5917b1ea9efd7 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 1 May 2026 15:29:17 +0200 Subject: [PATCH 2/3] Rename for consistency --- .../oracle/truffle/polyglot/OtherContextGuestObject.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/OtherContextGuestObject.java b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/OtherContextGuestObject.java index 01d0e86abe25..3338f0f0c611 100644 --- a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/OtherContextGuestObject.java +++ b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/OtherContextGuestObject.java @@ -338,13 +338,13 @@ static class OtherContextException extends AbstractTruffleException { } @TruffleBoundary - OtherContextException(PolyglotContextImpl thisContext, Exception delegate, PolyglotContextImpl delegateContext) { + OtherContextException(PolyglotContextImpl receiverContext, Exception delegate, PolyglotContextImpl delegateContext) { super(delegate.getMessage()); assert !(delegate instanceof OtherContextException) : "recursive host foreign value found"; - assert thisContext != null && delegateContext != null : "Must have associated contexts."; - assert thisContext != delegateContext : "no need for foreign value if contexts match"; + assert receiverContext != null && delegateContext != null : "Must have associated contexts."; + assert receiverContext != delegateContext : "no need for foreign value if contexts match"; this.delegate = delegate; - this.receiverContext = thisContext; + this.receiverContext = receiverContext; this.delegateContext = delegateContext; } From 989228bbde2a6d820c988601bf222937678ff99b Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 1 May 2026 14:35:34 +0200 Subject: [PATCH 3/3] Fix incorrect OtherContextException wrapper when the exception comes back to its creator context --- .../oracle/truffle/polyglot/OtherContextGuestObject.java | 6 ++++++ .../com/oracle/truffle/polyglot/PolyglotContextImpl.java | 1 + 2 files changed, 7 insertions(+) diff --git a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/OtherContextGuestObject.java b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/OtherContextGuestObject.java index 3338f0f0c611..c994c4e71b2c 100644 --- a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/OtherContextGuestObject.java +++ b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/OtherContextGuestObject.java @@ -181,10 +181,16 @@ static Object sendImpl(Node node, PolyglotSharingLayer layer, Object receiver, M @TruffleBoundary static RuntimeException migrateException(PolyglotContextImpl receiverContext, Throwable e, PolyglotContextImpl valueContext) throws T { if (e instanceof OtherContextException) { + // Same logic as in migrateValue() OtherContextException other = (OtherContextException) e; if (other.receiverContext == receiverContext && other.delegateContext == valueContext) { + // reuse wrapper it is already wrapped throw other; + } else if (other.receiverContext == valueContext && other.delegateContext == receiverContext) { + // unpack foreign value it belongs to that context + throw (T) other.delegate; } else { + // TODO: Should the last arg be valueContext like in migrateValue? throw new OtherContextException(receiverContext, other.delegate, other.delegateContext); } } else if (InteropLibrary.getUncached().isException(e)) { diff --git a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotContextImpl.java b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotContextImpl.java index 5a67da99b9f6..1ea749c71a07 100644 --- a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotContextImpl.java +++ b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotContextImpl.java @@ -1720,6 +1720,7 @@ Object migrateValue(Object value, PolyglotContextImpl valueContext) { // guaranteed by migrateValue assert value instanceof TruffleObject; if (value instanceof OtherContextGuestObject) { + // Same logic as in migrateException() OtherContextGuestObject otherValue = (OtherContextGuestObject) value; if (otherValue.receiverContext == this && otherValue.delegateContext == valueContext) { // reuse wrapper it is already wrapped