* Allow native host methods in scripted JavaObjects to be overridden in JavaScript, but

make sure we don't use any of the HopObject host methods.
This commit is contained in:
hns 2006-11-20 12:51:26 +00:00
parent 21117936ad
commit 0eae6629ee

View file

@ -181,24 +181,26 @@ public class JavaObject extends NativeJavaObject {
* Get a named property from this object. * Get a named property from this object.
*/ */
public Object get(String name, Scriptable start) { public Object get(String name, Scriptable start) {
// System.err.println ("GET: "+name); Object value;
Object obj;
// we really are not supposed to walk down the prototype chain in get(), // we really are not supposed to walk down the prototype chain in get(),
// but we break the rule in order to be able to override java methods, // but we break the rule in order to be able to override java methods,
// which are looked up by super.get() below // which are looked up by super.get() below
Scriptable proto = getPrototype(); Scriptable proto = getPrototype();
while (proto != null) { while (proto != null) {
obj = proto.get(name, start); value = proto.get(name, start);
if (obj != NOT_FOUND) { // Skip FunctionObject properties, which represent native wrapped
return obj; // java host methods. The prototype chain is made of HopObjects, and
// we can't invoked these on our wrapped java object.
if (value != NOT_FOUND && !(value instanceof FunctionObject)) {
return value;
} }
proto = proto.getPrototype(); proto = proto.getPrototype();
} }
obj = overload.get(name); value = overload.get(name);
if (obj != null) { if (value != null) {
return new FunctionObject(name, (Method) obj, this); return new FunctionObject(name, (Method) value, this);
} }
if ("_prototype".equals(name) || "__prototype__".equals(name)) { if ("_prototype".equals(name) || "__prototype__".equals(name)) {