I've got a problem with the equals/hashCode contract of ProxyObjectin graalJS. I've implemented ProxyObject for my Java objects like this:
public class MyProxyObject implements ProxyObject
{
private final Object receiver;
private MyProxyObject(Object aReceiver){
receiver = aReceiver;
}
@Override
public boolean equals(Object value)
{
Object unwrapped;
if (value instanceof Value v)
{
unwrapped = v.isNull() ? null : v.isProxyObject() ? v.asProxyObject() : v.isHostObject() ? v.asHostObject() : value;
}
else
{
unwrapped = value;
}
return receiver.equals(unwrapped instanceof MyProxyObject ? ((MyProxyObject) unwrapped).unwrap() : unwrapped);
}
@Override
public int hashCode()
{
return receiver.hashCode();
}
}
When I make the bindings like this:
Object sample = new Object();
var bindings = context.getBindings("js");
bindings.putMember("p1", MyProxyObject(sample));
bindings.putMember("p2", MyProxyObject(sample));
I believe that such comparision p1 == p2 in script should evaluate to true because equals and hashCode have been overridden. But the equals method gets never called. This leads to a strange behavior. Let's say that we have a proxy, which returns another proxy for its property. Then we can't get the same property in script multiple times and then compare them as equal. But we expect them to be equal. Can you help with this?
I've got a problem with the
equals/hashCodecontract ofProxyObjectin graalJS. I've implementedProxyObjectfor my Java objects like this:When I make the bindings like this:
I believe that such comparision
p1 == p2in script should evaluate to true becauseequalsandhashCodehave been overridden. But the equals method gets never called. This leads to a strange behavior. Let's say that we have a proxy, which returns another proxy for its property. Then we can't get the same property in script multiple times and then compare them as equal. But we expect them to be equal. Can you help with this?