* Fix prototype inheritance for wrapped Java objects. get() and has() are not
supposed to check the prototype chain. Instead, just register the prototype using setPrototype().
This commit is contained in:
parent
ab378b0806
commit
cd3fdb4fab
1 changed files with 9 additions and 9 deletions
|
@ -31,7 +31,6 @@ import java.io.IOException;
|
||||||
public class JavaObject extends NativeJavaObject {
|
public class JavaObject extends NativeJavaObject {
|
||||||
|
|
||||||
RhinoCore core;
|
RhinoCore core;
|
||||||
Scriptable prototype;
|
|
||||||
String protoName;
|
String protoName;
|
||||||
|
|
||||||
static HashMap overload;
|
static HashMap overload;
|
||||||
|
@ -56,13 +55,12 @@ public class JavaObject extends NativeJavaObject {
|
||||||
this.parent = scope;
|
this.parent = scope;
|
||||||
this.javaObject = obj;
|
this.javaObject = obj;
|
||||||
this.protoName = protoName;
|
this.protoName = protoName;
|
||||||
this.prototype = prototype;
|
|
||||||
this.core = core;
|
this.core = core;
|
||||||
staticType = obj.getClass();
|
staticType = obj.getClass();
|
||||||
|
setPrototype(prototype);
|
||||||
initMembers();
|
initMembers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -162,13 +160,20 @@ public class JavaObject extends NativeJavaObject {
|
||||||
return core.postProcessHref(javaObject, protoName, basicHref);
|
return core.postProcessHref(javaObject, protoName, basicHref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given property is defined in this object.
|
||||||
|
*/
|
||||||
public boolean has(String name, Scriptable start) {
|
public boolean has(String name, Scriptable start) {
|
||||||
// System.err.println ("HAS: "+name);
|
// System.err.println ("HAS: "+name);
|
||||||
if (prototype.has(name, start))
|
if (overload.containsKey(name)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return super.has(name, start);
|
return super.has(name, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
// System.err.println ("GET: "+name);
|
||||||
Object obj = overload.get(name);
|
Object obj = overload.get(name);
|
||||||
|
@ -176,11 +181,6 @@ public class JavaObject extends NativeJavaObject {
|
||||||
return new FunctionObject(name, (Method) obj, this);
|
return new FunctionObject(name, (Method) obj, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = prototype.get(name, start);
|
|
||||||
if (obj != null && obj != NOT_FOUND) {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.get(name, start);
|
return super.get(name, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue