Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ public Builder onExited(Consumer<Integer> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,16 @@ static Object sendImpl(Node node, PolyglotSharingLayer layer, Object receiver, M
@TruffleBoundary
static <T extends Throwable> 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);
Comment on lines +193 to 194
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrateValue() does:

return new OtherContextGuestObject(this, otherValue.delegate, valueContext);

(in migrateValue(), this == receiverContext)

Which is correct?
I'm not sure what the receiverContext is for, wouldn't only tracking the delegateContext be enough?
Is it because the OtherContextGuestObject/OtherContextException objects need to belong to one context and not many? (if so, is that needed?)

}
} else if (InteropLibrary.getUncached().isException(e)) {
Expand Down Expand Up @@ -338,13 +344,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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down