mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Subject:
Re: netscape.javascript.JSObject ? Date: Thu, 03 Jun 1999 17:52:42 -0700 From: Frank Mitchell <frankm@eng.Sun.COM> Organization: Java Products Engineering To: Norris Boyd <norris@netscape.com> References: 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 Norris Boyd wrote: > > Sorry--missed the checkin of a new file. It's there now. > > I'd also added a small change for the "inheritance" of JavaScript array methods. Actually, I've already done that (and for String as well). It still fails some LC3 regression tests, though. I'm including a tarfile that includes the previous changes and the new ones. Frank
This commit is contained in:
parent
5513cb38fd
commit
dbbafc6b60
@ -52,21 +52,6 @@ public class NativeJavaArray extends NativeJavaObject {
|
||||
this.array = array;
|
||||
this.length = Array.getLength(array);
|
||||
this.cls = cl.getComponentType();
|
||||
setPrototype(ScriptableObject.getClassPrototype(scope, "Array"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prototype of the object.
|
||||
*/
|
||||
public Scriptable getPrototype() {
|
||||
return prototype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the prototype of the object.
|
||||
*/
|
||||
public void setPrototype(Scriptable m) {
|
||||
prototype = m;
|
||||
}
|
||||
|
||||
public boolean has(String id, Scriptable start) {
|
||||
@ -130,6 +115,15 @@ public class NativeJavaArray extends NativeJavaObject {
|
||||
return cls.isInstance(instance);
|
||||
}
|
||||
|
||||
public Scriptable getPrototype() {
|
||||
if (prototype == null) {
|
||||
prototype =
|
||||
ScriptableObject.getClassPrototype(this.getParentScope(),
|
||||
"Array");
|
||||
}
|
||||
return prototype;
|
||||
}
|
||||
|
||||
Object array;
|
||||
int length;
|
||||
Class cls;
|
||||
|
@ -40,7 +40,7 @@ import java.util.Hashtable;
|
||||
public class NativeJavaClass extends NativeJavaObject implements Function {
|
||||
|
||||
public NativeJavaClass(Scriptable scope, Class cl) {
|
||||
super(cl, JavaMembers.lookupClass(scope, cl, cl));
|
||||
super(scope, cl, JavaMembers.lookupClass(scope, cl, cl));
|
||||
fieldAndMethods = members.getFieldAndMethodsObjects(javaObject, false);
|
||||
}
|
||||
|
||||
@ -236,21 +236,6 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Scriptable getParentScope() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParentScope(Scriptable scope) {
|
||||
// beard:
|
||||
// need at least the top-most scope, so JavaMembers.reflectMethod()
|
||||
// will work. this fixes a bug where a static field of a class would get
|
||||
// reflected by JavaMembers.reflect() in the scope of a NativeJavaClass,
|
||||
// and calls to ScriptableObject.getFunctionPrototype() would return
|
||||
// null because there was no top-level scope with "Function" defined.
|
||||
// question: should the package hierarchy form the scope chain or is top-level sufficient?
|
||||
parent = scope;
|
||||
}
|
||||
|
||||
private Hashtable fieldAndMethods;
|
||||
|
||||
// beard: need a scope for finding top-level prototypes.
|
||||
|
@ -202,6 +202,12 @@ public class NativeJavaMethod extends NativeFunction implements Function {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public Object getDefaultValue(Class hint) {
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find the correct function to call given the set of methods
|
||||
* or constructors and the arguments.
|
||||
@ -232,7 +238,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
|
||||
Member bestFit = null;
|
||||
Class[] bestFitTypes = null;
|
||||
|
||||
java.util.Vector ambiguousMethods = null;
|
||||
java.util.Vector ambiguousMethods = new java.util.Vector();
|
||||
|
||||
for (int i = 0; i < methodsOrCtors.length; i++) {
|
||||
Member member = methodsOrCtors[i];
|
||||
@ -264,8 +270,6 @@ public class NativeJavaMethod extends NativeFunction implements Function {
|
||||
if (preference == PREFERENCE_AMBIGUOUS) {
|
||||
if (debug) printDebug("Deferring ", member, args);
|
||||
// add to "ambiguity list"
|
||||
if (ambiguousMethods == null)
|
||||
ambiguousMethods = new java.util.Vector();
|
||||
ambiguousMethods.addElement(member);
|
||||
}
|
||||
else if (preference == PREFERENCE_FIRST_ARG) {
|
||||
@ -279,12 +283,9 @@ public class NativeJavaMethod extends NativeFunction implements Function {
|
||||
}
|
||||
}
|
||||
|
||||
if (ambiguousMethods == null)
|
||||
return bestFit;
|
||||
|
||||
// Compare ambiguous methods with best fit, in case
|
||||
// the current best fit removes the ambiguities.
|
||||
for (int i = ambiguousMethods.size() - 1; i >= 0; i--) {
|
||||
for (int i = ambiguousMethods.size() - 1; i >= 0 ; i--) {
|
||||
Member member = (Member)ambiguousMethods.elementAt(i);
|
||||
Class paramTypes[] = hasMethods
|
||||
? ((Method) member).getParameterTypes()
|
||||
|
@ -34,8 +34,11 @@ import java.util.Enumeration;
|
||||
*/
|
||||
|
||||
public class NativeJavaObject implements Scriptable, Wrapper {
|
||||
|
||||
public NativeJavaObject(Object javaObject, JavaMembers members) {
|
||||
|
||||
public NativeJavaObject(Scriptable scope, Object javaObject,
|
||||
JavaMembers members)
|
||||
{
|
||||
this.parent = scope;
|
||||
this.javaObject = javaObject;
|
||||
this.members = members;
|
||||
}
|
||||
@ -43,6 +46,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
|
||||
public NativeJavaObject(Scriptable scope, Object javaObject,
|
||||
Class staticType)
|
||||
{
|
||||
this.parent = scope;
|
||||
this.javaObject = javaObject;
|
||||
Class dynamicType = javaObject != null ? javaObject.getClass()
|
||||
: staticType;
|
||||
@ -93,17 +97,27 @@ public class NativeJavaObject implements Scriptable, Wrapper {
|
||||
}
|
||||
|
||||
public Scriptable getPrototype() {
|
||||
if (javaObject.getClass() == ScriptRuntime.StringClass) {
|
||||
return ScriptableObject.getClassPrototype(parent, "String");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPrototype(Scriptable prototype) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent (enclosing) scope of the object.
|
||||
*/
|
||||
public Scriptable getParentScope() {
|
||||
return null;
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParentScope(Scriptable parent) {
|
||||
/**
|
||||
* Sets the parent (enclosing) scope of the object.
|
||||
*/
|
||||
public void setParentScope(Scriptable m) {
|
||||
parent = m;
|
||||
}
|
||||
|
||||
public Object[] getIds() {
|
||||
@ -550,12 +564,16 @@ public class NativeJavaObject implements Scriptable, Wrapper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The parent scope of this object.
|
||||
*/
|
||||
protected Scriptable parent;
|
||||
|
||||
protected Object javaObject;
|
||||
protected JavaMembers members;
|
||||
private Hashtable fieldAndMethods;
|
||||
static Class jsObjectClass;
|
||||
static Constructor jsObjectCtor;
|
||||
static Method jsObjectGetScriptable;
|
||||
|
||||
}
|
||||
|
||||
|
@ -52,21 +52,6 @@ public class NativeJavaArray extends NativeJavaObject {
|
||||
this.array = array;
|
||||
this.length = Array.getLength(array);
|
||||
this.cls = cl.getComponentType();
|
||||
setPrototype(ScriptableObject.getClassPrototype(scope, "Array"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prototype of the object.
|
||||
*/
|
||||
public Scriptable getPrototype() {
|
||||
return prototype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the prototype of the object.
|
||||
*/
|
||||
public void setPrototype(Scriptable m) {
|
||||
prototype = m;
|
||||
}
|
||||
|
||||
public boolean has(String id, Scriptable start) {
|
||||
@ -130,6 +115,15 @@ public class NativeJavaArray extends NativeJavaObject {
|
||||
return cls.isInstance(instance);
|
||||
}
|
||||
|
||||
public Scriptable getPrototype() {
|
||||
if (prototype == null) {
|
||||
prototype =
|
||||
ScriptableObject.getClassPrototype(this.getParentScope(),
|
||||
"Array");
|
||||
}
|
||||
return prototype;
|
||||
}
|
||||
|
||||
Object array;
|
||||
int length;
|
||||
Class cls;
|
||||
|
@ -40,7 +40,7 @@ import java.util.Hashtable;
|
||||
public class NativeJavaClass extends NativeJavaObject implements Function {
|
||||
|
||||
public NativeJavaClass(Scriptable scope, Class cl) {
|
||||
super(cl, JavaMembers.lookupClass(scope, cl, cl));
|
||||
super(scope, cl, JavaMembers.lookupClass(scope, cl, cl));
|
||||
fieldAndMethods = members.getFieldAndMethodsObjects(javaObject, false);
|
||||
}
|
||||
|
||||
@ -236,21 +236,6 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Scriptable getParentScope() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParentScope(Scriptable scope) {
|
||||
// beard:
|
||||
// need at least the top-most scope, so JavaMembers.reflectMethod()
|
||||
// will work. this fixes a bug where a static field of a class would get
|
||||
// reflected by JavaMembers.reflect() in the scope of a NativeJavaClass,
|
||||
// and calls to ScriptableObject.getFunctionPrototype() would return
|
||||
// null because there was no top-level scope with "Function" defined.
|
||||
// question: should the package hierarchy form the scope chain or is top-level sufficient?
|
||||
parent = scope;
|
||||
}
|
||||
|
||||
private Hashtable fieldAndMethods;
|
||||
|
||||
// beard: need a scope for finding top-level prototypes.
|
||||
|
@ -202,6 +202,12 @@ public class NativeJavaMethod extends NativeFunction implements Function {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public Object getDefaultValue(Class hint) {
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find the correct function to call given the set of methods
|
||||
* or constructors and the arguments.
|
||||
@ -232,7 +238,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
|
||||
Member bestFit = null;
|
||||
Class[] bestFitTypes = null;
|
||||
|
||||
java.util.Vector ambiguousMethods = null;
|
||||
java.util.Vector ambiguousMethods = new java.util.Vector();
|
||||
|
||||
for (int i = 0; i < methodsOrCtors.length; i++) {
|
||||
Member member = methodsOrCtors[i];
|
||||
@ -264,8 +270,6 @@ public class NativeJavaMethod extends NativeFunction implements Function {
|
||||
if (preference == PREFERENCE_AMBIGUOUS) {
|
||||
if (debug) printDebug("Deferring ", member, args);
|
||||
// add to "ambiguity list"
|
||||
if (ambiguousMethods == null)
|
||||
ambiguousMethods = new java.util.Vector();
|
||||
ambiguousMethods.addElement(member);
|
||||
}
|
||||
else if (preference == PREFERENCE_FIRST_ARG) {
|
||||
@ -279,12 +283,9 @@ public class NativeJavaMethod extends NativeFunction implements Function {
|
||||
}
|
||||
}
|
||||
|
||||
if (ambiguousMethods == null)
|
||||
return bestFit;
|
||||
|
||||
// Compare ambiguous methods with best fit, in case
|
||||
// the current best fit removes the ambiguities.
|
||||
for (int i = ambiguousMethods.size() - 1; i >= 0; i--) {
|
||||
for (int i = ambiguousMethods.size() - 1; i >= 0 ; i--) {
|
||||
Member member = (Member)ambiguousMethods.elementAt(i);
|
||||
Class paramTypes[] = hasMethods
|
||||
? ((Method) member).getParameterTypes()
|
||||
|
@ -34,8 +34,11 @@ import java.util.Enumeration;
|
||||
*/
|
||||
|
||||
public class NativeJavaObject implements Scriptable, Wrapper {
|
||||
|
||||
public NativeJavaObject(Object javaObject, JavaMembers members) {
|
||||
|
||||
public NativeJavaObject(Scriptable scope, Object javaObject,
|
||||
JavaMembers members)
|
||||
{
|
||||
this.parent = scope;
|
||||
this.javaObject = javaObject;
|
||||
this.members = members;
|
||||
}
|
||||
@ -43,6 +46,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
|
||||
public NativeJavaObject(Scriptable scope, Object javaObject,
|
||||
Class staticType)
|
||||
{
|
||||
this.parent = scope;
|
||||
this.javaObject = javaObject;
|
||||
Class dynamicType = javaObject != null ? javaObject.getClass()
|
||||
: staticType;
|
||||
@ -93,17 +97,27 @@ public class NativeJavaObject implements Scriptable, Wrapper {
|
||||
}
|
||||
|
||||
public Scriptable getPrototype() {
|
||||
if (javaObject.getClass() == ScriptRuntime.StringClass) {
|
||||
return ScriptableObject.getClassPrototype(parent, "String");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPrototype(Scriptable prototype) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent (enclosing) scope of the object.
|
||||
*/
|
||||
public Scriptable getParentScope() {
|
||||
return null;
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParentScope(Scriptable parent) {
|
||||
/**
|
||||
* Sets the parent (enclosing) scope of the object.
|
||||
*/
|
||||
public void setParentScope(Scriptable m) {
|
||||
parent = m;
|
||||
}
|
||||
|
||||
public Object[] getIds() {
|
||||
@ -550,12 +564,16 @@ public class NativeJavaObject implements Scriptable, Wrapper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The parent scope of this object.
|
||||
*/
|
||||
protected Scriptable parent;
|
||||
|
||||
protected Object javaObject;
|
||||
protected JavaMembers members;
|
||||
private Hashtable fieldAndMethods;
|
||||
static Class jsObjectClass;
|
||||
static Constructor jsObjectCtor;
|
||||
static Method jsObjectGetScriptable;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user