use of org.graalvm.polyglot.proxy.Proxy in project graal by oracle.
the class ProxyAPITest method testProxy.
@Test
public void testProxy() {
Proxy proxy = new Proxy() {
};
Value value = context.asValue(proxy);
assertTrue(value.isProxyObject());
assertSame(proxy, value.asProxyObject());
assertUnsupported(value, PROXY_OBJECT);
}
use of org.graalvm.polyglot.proxy.Proxy in project graal by oracle.
the class ProxySPITest method testSimpleProxy.
@Test
public void testSimpleProxy() throws Throwable {
Context context = Context.create();
Proxy proxyOuter = new Proxy() {
};
eval(context, proxyOuter, (proxyInner) -> {
assertUnsupported(Message.createExecute(0), proxyInner);
assertUnsupported(Message.AS_POINTER, proxyInner);
assertUnsupported(Message.GET_SIZE, proxyInner);
assertEmpty(Message.KEYS, proxyInner);
assertUnsupported(Message.READ, proxyInner);
assertUnsupported(Message.WRITE, proxyInner);
assertUnsupported(Message.REMOVE, proxyInner);
assertUnsupported(Message.TO_NATIVE, proxyInner);
assertUnsupported(Message.UNBOX, 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_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.Proxy in project graal by oracle.
the class ProxySPITest method testProxyError.
@Test
public void testProxyError() throws Throwable {
Context context = Context.create();
Proxy proxyOuter = new AllProxy();
eval(context, proxyOuter, (proxyInner) -> {
assertHostError(Message.AS_POINTER, proxyInner);
assertHostError(Message.GET_SIZE, proxyInner);
assertHostError(Message.KEYS, proxyInner);
assertHostError(Message.READ, proxyInner, "");
assertHostError(Message.READ, proxyInner, 42);
assertHostError(Message.WRITE, proxyInner, "", 42);
assertHostError(Message.WRITE, proxyInner, 42, 42);
assertHostError(Message.REMOVE, proxyInner, 10);
assertHostError(Message.UNBOX, proxyInner);
assertHostError(Message.createInvoke(0), proxyInner, "");
assertHostError(Message.createExecute(0), proxyInner);
assertHostError(Message.createNew(0), proxyInner);
assertHostError(Message.KEY_INFO, proxyInner, "");
assertHostError(Message.KEY_INFO, proxyInner, 42);
assertUnsupported(Message.TO_NATIVE, proxyInner);
assertEquals(true, Message.IS_BOXED, proxyInner);
assertEquals(true, Message.IS_EXECUTABLE, proxyInner);
assertEquals(true, Message.IS_INSTANTIABLE, proxyInner);
assertEquals(false, Message.IS_NULL, proxyInner);
assertEquals(true, Message.HAS_KEYS, proxyInner);
assertEquals(true, Message.HAS_SIZE, proxyInner);
assertEquals(true, Message.IS_POINTER, proxyInner);
return null;
});
}
use of org.graalvm.polyglot.proxy.Proxy in project graal by oracle.
the class ValueHostConversionTest method testProxyIdentityRestore.
@Test
public void testProxyIdentityRestore() {
Proxy proxy = new Proxy() {
};
Value value = context.asValue(proxy);
assertUnsupported(value, PROXY_OBJECT);
assertSame(proxy, context.asValue(value.as(Object.class)).asProxyObject());
}
use of org.graalvm.polyglot.proxy.Proxy in project graal by oracle.
the class HostLanguage method findMetaObject.
@Override
protected Object findMetaObject(HostContext context, Object value) {
if (value instanceof TruffleObject) {
TruffleObject to = (TruffleObject) value;
if (VMAccessor.JAVAINTEROP.isHostObject(to)) {
Object javaObject = VMAccessor.JAVAINTEROP.asHostObject(to);
Class<?> javaType;
if (javaObject == null) {
javaType = Void.class;
} else {
javaType = javaObject.getClass();
}
return javaClassToGuestObject(javaType, context.internalContext);
} else if (PolyglotProxy.isProxyGuestObject(to)) {
Proxy proxy = PolyglotProxy.toProxyHostObject(to);
return javaClassToGuestObject(proxy.getClass(), context.internalContext);
} else if (VMAccessor.JAVAINTEROP.isHostFunction(value)) {
return "Bound Method";
} else {
return "Foreign Object";
}
} else {
return javaClassToGuestObject(value.getClass(), context.internalContext);
}
}
Aggregations