Search in sources :

Example 1 with ProxyObject

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

the class ProxySPITest method testProxyObjectUnsupported.

@Test
public void testProxyObjectUnsupported() throws Throwable {
    Context context = Context.create();
    ProxyObject proxyOuter = new ProxyObject() {

        public void putMember(String key, Value value) {
            throw new UnsupportedOperationException();
        }

        public boolean hasMember(String key) {
            return true;
        }

        public ProxyArray getMemberKeys() {
            return null;
        }

        public Object getMember(String key) {
            throw new UnsupportedOperationException();
        }
    };
    eval(context, proxyOuter, (proxyInner) -> {
        assertEmpty(Message.KEYS, proxyInner);
        assertUnsupported(Message.READ, proxyInner, "");
        assertUnsupported(Message.WRITE, proxyInner, "", 42);
        assertUnsupported(Message.createExecute(0), proxyInner);
        assertUnsupported(Message.GET_SIZE, proxyInner);
        assertUnsupported(Message.READ, proxyInner, 0);
        assertUnsupported(Message.WRITE, proxyInner, 1);
        assertUnsupported(Message.UNBOX, proxyInner);
        assertUnsupported(Message.TO_NATIVE, proxyInner);
        assertUnsupported(Message.AS_POINTER, proxyInner);
        assertUnsupported(Message.createInvoke(0), proxyInner);
        assertUnsupported(Message.createExecute(0), proxyInner);
        assertUnsupported(Message.createNew(0), proxyInner);
        assertEquals(false, Message.IS_BOXED, proxyInner);
        assertEquals(false, Message.IS_EXECUTABLE, proxyInner);
        assertEquals(false, Message.IS_INSTANTIABLE, proxyInner);
        assertEquals(false, Message.IS_NULL, proxyInner);
        assertEquals(true, Message.HAS_KEYS, proxyInner);
        assertEquals(false, Message.HAS_SIZE, proxyInner);
        assertEquals(false, Message.IS_POINTER, proxyInner);
        assertEquals(0, Message.KEY_INFO, proxyInner);
        return null;
    });
}
Also used : LanguageContext(com.oracle.truffle.api.test.polyglot.ContextAPITestLanguage.LanguageContext) Context(org.graalvm.polyglot.Context) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) Value(org.graalvm.polyglot.Value) Test(org.junit.Test)

Example 2 with ProxyObject

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

the class ProxySPITest method testProxyObject.

@Test
public void testProxyObject() throws Throwable {
    Context context = Context.create();
    Map<String, Object> values = new HashMap<>();
    ProxyObject proxyOuter = ProxyObject.fromMap(values);
    eval(context, proxyOuter, (proxyInner) -> {
        assertEquals(true, Message.HAS_KEYS, proxyInner);
        assertEmpty(Message.KEYS, proxyInner);
        assertUnknownIdentifier(Message.READ, proxyInner, "");
        assertEquals(NO_KEY, Message.KEY_INFO, proxyInner, "");
        assertEquals(42, Message.WRITE, proxyInner, "a", 42);
        assertEquals(42, Message.READ, proxyInner, "a");
        assertEquals(EXISTING_KEY, Message.KEY_INFO, proxyInner, "a");
        assertEquals(NO_KEY, Message.KEY_INFO, proxyInner, "");
        assertUnsupported(Message.createExecute(0), proxyInner);
        assertUnsupported(Message.GET_SIZE, proxyInner);
        assertUnsupported(Message.READ, proxyInner, 0);
        assertUnsupported(Message.WRITE, proxyInner, 1);
        assertUnsupported(Message.UNBOX, proxyInner);
        assertUnsupported(Message.TO_NATIVE, proxyInner);
        assertUnsupported(Message.AS_POINTER, proxyInner);
        assertUnsupported(Message.createInvoke(0), proxyInner);
        assertUnsupported(Message.createExecute(0), proxyInner);
        assertUnsupported(Message.createNew(0), proxyInner);
        assertEquals(false, Message.IS_BOXED, proxyInner);
        assertEquals(false, Message.IS_EXECUTABLE, proxyInner);
        assertEquals(false, Message.IS_INSTANTIABLE, proxyInner);
        assertEquals(false, Message.IS_NULL, proxyInner);
        assertEquals(false, Message.HAS_SIZE, proxyInner);
        assertEquals(false, Message.IS_POINTER, proxyInner);
        assertEquals(0, Message.KEY_INFO, proxyInner);
        assertEquals(true, Message.REMOVE, proxyInner, "a");
        assertEmpty(Message.KEYS, proxyInner);
        return null;
    });
}
Also used : LanguageContext(com.oracle.truffle.api.test.polyglot.ContextAPITestLanguage.LanguageContext) Context(org.graalvm.polyglot.Context) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) HashMap(java.util.HashMap) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyNativeObject(org.graalvm.polyglot.proxy.ProxyNativeObject) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) Test(org.junit.Test)

Example 3 with ProxyObject

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

the class PolyglotNativeAPI method polyglot_create_object.

@CEntryPoint(name = "polyglot_create_object")
public static PolyglotStatus polyglot_create_object(IsolateThread isolate_thread, PolyglotContextPointer polyglot_context, PolyglotValuePointerPointer result) {
    return withHandledErrors(() -> {
        Context c = ObjectHandles.getGlobal().get(polyglot_context);
        ProxyObject proxy = ProxyObject.fromMap(new HashMap<>());
        result.write(createHandle(c.asValue(proxy)));
    });
}
Also used : CEntryPointContext(org.graalvm.nativeimage.c.function.CEntryPointContext) Context(org.graalvm.polyglot.Context) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Aggregations

Context (org.graalvm.polyglot.Context)3 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)3 LanguageContext (com.oracle.truffle.api.test.polyglot.ContextAPITestLanguage.LanguageContext)2 Test (org.junit.Test)2 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 HashMap (java.util.HashMap)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1 CEntryPointContext (org.graalvm.nativeimage.c.function.CEntryPointContext)1 Value (org.graalvm.polyglot.Value)1 ProxyNativeObject (org.graalvm.polyglot.proxy.ProxyNativeObject)1