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;
});
}
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;
});
}
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)));
});
}
Aggregations