Skip to content

Commit 2f63ee5

Browse files
committed
Fix migration of already-wrapped context values
1 parent 276e2d9 commit 2f63ee5

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

truffle/src/com.oracle.truffle.api.instrumentation.test/src/com/oracle/truffle/api/instrumentation/test/TruffleContextTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,31 @@ public void testEvalInnerContext() throws InteropException {
769769
innerContext.close();
770770
}
771771

772+
@Test
773+
public void testMigrateInnerContextValueThroughOtherInnerContext() throws InteropException {
774+
EvalContextTestObject innerObject = new EvalContextTestObject();
775+
EvalContextTestObject forwardingObject = new EvalContextTestObject();
776+
AtomicBoolean returnInnerObject = new AtomicBoolean(true);
777+
setupLanguageThatReturns(() -> returnInnerObject.getAndSet(false) ? innerObject : forwardingObject);
778+
779+
TruffleContext innerContext = languageEnv.newInnerContextBuilder().initializeCreatorContext(true).build();
780+
TruffleContext otherInnerContext = languageEnv.newInnerContextBuilder().initializeCreatorContext(true).build();
781+
innerObject.expectedContext = innerContext;
782+
forwardingObject.expectedContext = otherInnerContext;
783+
784+
Object innerResult = innerContext.evalInternal(null, newTruffleSource());
785+
assertNotEquals("must be wrapped", innerObject, innerResult);
786+
787+
Object forwardingResult = otherInnerContext.evalInternal(null, newTruffleSource());
788+
assertNotEquals("must be wrapped", forwardingObject, forwardingResult);
789+
InteropLibrary.getUncached().execute(forwardingResult, innerResult);
790+
791+
assertEquals(1, innerObject.executeCount);
792+
assertEquals(1, forwardingObject.executeCount);
793+
otherInnerContext.close();
794+
innerContext.close();
795+
}
796+
772797
@ExportLibrary(InteropLibrary.class)
773798
static class EvalContextTestObject implements TruffleObject {
774799

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotContextImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ Object migrateValue(Object value, PolyglotContextImpl valueContext) {
17291729
// unpack foreign value it belongs to that context
17301730
return otherValue.delegate;
17311731
} else {
1732-
return new OtherContextGuestObject(this, otherValue.delegate, valueContext);
1732+
return new OtherContextGuestObject(this, otherValue.delegate, otherValue.delegateContext);
17331733
}
17341734
}
17351735
assert value instanceof TruffleObject;

0 commit comments

Comments
 (0)