Hi guys,
I'm trying to figure out if this failing piece of code fails due to a
bug in Rhino. The short of it is that we have a global object (in this
case an instance of TestBean) that has a read-only property named
"blah"; we execute some JS code which attempts to define a function
named "blah" (and does so successfully, I think), but when the code
attempts to call this new function, Rhino picks up the read-only
"blah" property on the global object (rather than the function) --
throwing a TypeError.
The real-world application of this is in HtmlUnit: the global object
in an HTML document is the window, which has (for example) a read-only
"navigator" property. However, you are allowed to define a function
named "navigator" and call it (hiding the real "navigator" property).
Have a look at the code below and let me know what you think... Should
this work in Rhino? Is it a bug? Is it misconfiguration?
Take care,
Daniel
public class TestBean extends ScriptableObject {
private Object blah = "a";
public Object getBlah() {
return blah;
}
@Override
public String getClassName() {
return "TestBean";
}
}
public void testPropertyReplacement() throws Exception {
Context cx = ContextFactory.getGlobal().enterContext();
try {
ScriptableObject scope = new TestBean();
cx.initStandardObjects(scope);
Method getter = TestBean.class.getDeclaredMethod("getBlah");
scope.defineProperty("blah", null, getter, null,
ScriptableObject.EMPTY);
String source =
"function blah() { return 'x'; }\n" +
"blah();\n";
cx.evaluateString(scope, source, "source", 1, null);
} finally {
Context.exit();
}
}
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino