Search in sources :

Example 6 with Proxy

use of org.graalvm.polyglot.proxy.Proxy in project graal by oracle.

the class PolyglotLanguageContext method toGuestValue.

static Object toGuestValue(Object originalLanguageContext, Object receiver) {
    PolyglotLanguageContext languageContext = ((PolyglotLanguageContext) originalLanguageContext);
    if (receiver instanceof Value) {
        Value receiverValue = (Value) receiver;
        PolyglotValue valueImpl = (PolyglotValue) languageContext.getAPIAccess().getImpl(receiverValue);
        if (valueImpl.languageContext.context != languageContext.context) {
            CompilerDirectives.transferToInterpreter();
            throw PolyglotImpl.engineError(new IllegalArgumentException(String.format("Values cannot be passed from one context to another. " + "The current value originates from context 0x%s and the argument originates from context 0x%s.", Integer.toHexString(languageContext.context.api.hashCode()), Integer.toHexString(valueImpl.languageContext.context.api.hashCode()))));
        }
        return languageContext.getAPIAccess().getReceiver(receiverValue);
    } else if (PolyglotImpl.isGuestPrimitive(receiver)) {
        return receiver;
    } else if (receiver instanceof Proxy) {
        return PolyglotProxy.toProxyGuestObject(languageContext, (Proxy) receiver);
    } else {
        return JAVAINTEROP.toGuestObject(receiver, languageContext);
    }
}
Also used : Proxy(org.graalvm.polyglot.proxy.Proxy) Value(org.graalvm.polyglot.Value)

Aggregations

Proxy (org.graalvm.polyglot.proxy.Proxy)6 Test (org.junit.Test)4 Value (org.graalvm.polyglot.Value)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 LanguageContext (com.oracle.truffle.api.test.polyglot.ContextAPITestLanguage.LanguageContext)2 ValueAssert.assertValue (com.oracle.truffle.api.test.polyglot.ValueAssert.assertValue)2 Context (org.graalvm.polyglot.Context)2