Hi all,
I'm trying to implement ES6 Proxy in Rhino, but running into a snag: when I send in a JavaScript Array from JavaScript into a Java method or constructor that takes a param of type Scriptable, things break down. When sending in a JavaSCript Object instead, things work fine.
I traced this back to NativeJavaObject.coerceTypeImpl: for JSTYPE_OBJECT the code below is invoked at some point, due to which it works:
else if (type.isInstance(value)) {
return value;
}
For JSTYPE_JAVA_ARRAY such code isn't there and I end up in the else:
else {
reportConversionError(value, type);
}
My conclusion is that coerceTypeImpl is buggy: it is supposed to do whatever is needed to 'modify the value so that it returns an instance of the requested type, but specifically for JavaScript arrays (NativeArray) there is no check to see if the value passed in is already an instance of the requested type.
As a matter of fact, I wonder if such an instanceof check shouldn't be at the top of the method where there's currently only a generic check if the passed in value is of the same class as the requested type.
This is now stopping me from my attempt to implement Proxies. I can add the instanceof check for arrays or generically at the top of the function and create a PR and if I manage to pull of the Proxy impl also create a PR for that.
Hoping on some guidance,
P