Skip to content

Commit

Permalink
[GR-28777] EngineImpl#isMultiThreaded returns incorrect value.
Browse files Browse the repository at this point in the history
PullRequest: graal/8045
  • Loading branch information
tzezula committed Jan 19, 2021
2 parents 326f58b + b4f38c5 commit 82ee668
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -453,7 +452,10 @@ public void testProxyObject() {
return new Object[]{42};
};

assertNull(value.getMemberKeys().iterator().next());
assertFails(() -> value.getMemberKeys(), PolyglotException.class, (e) -> {
assertTrue(e.isHostException());
assertTrue(e.asHostException() instanceof IllegalStateException);
});
assertEquals(6, proxy.getMemberKeysCounter);

proxy.getMemberKeys = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public boolean isMultiThreaded(Object guestObject) {
// be conservative
return true;
}
return context.singleThreaded.isValid();
return !context.singleThreaded.isValid();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.time.ZoneId;
import java.time.ZonedDateTime;

import com.oracle.truffle.api.CompilerDirectives;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.proxy.Proxy;
import org.graalvm.polyglot.proxy.ProxyArray;
Expand Down Expand Up @@ -292,10 +293,25 @@ Object getMembers(@SuppressWarnings("unused") boolean includeInternal,
result = EMPTY;
}
Object guestValue = languageContext.toGuestValue(library, result);
if (!InteropLibrary.getFactory().getUncached().hasArrayElements(guestValue)) {
InteropLibrary interop = InteropLibrary.getFactory().getUncached();
if (!interop.hasArrayElements(guestValue)) {
throw illegalProxy(languageContext, "getMemberKeys() returned invalid value %s but must return an array of member key Strings.",
languageContext.asValue(guestValue).toString());
}
// Todo: Use interop to determine an array element type when the GR-5737 is resolved.
for (int i = 0; i < interop.getArraySize(guestValue); i++) {
try {
Object element = interop.readArrayElement(guestValue, i);
if (!interop.isString(element)) {
throw illegalProxy(languageContext, "getMemberKeys() returned invalid value %s but must return an array of member key Strings.",
languageContext.asValue(guestValue).toString());
}
} catch (UnsupportedOperationException e) {
CompilerDirectives.shouldNotReachHere(e);
} catch (InvalidArrayIndexException e) {
continue;
}
}
return guestValue;
} else {
throw UnsupportedMessageException.create();
Expand Down

0 comments on commit 82ee668

Please sign in to comment.