The fix sort of works. But there are some new problems. I enclosed two JavaScript files, button.js and image.js.

If I load button.js first and then image.js, I got the following:

js> load("button.js");
js> load("image.js");
Ambiguous import: [JavaClass javax.swing.ImageIcon] and [JavaClass javax.swing.ImageIcon]
js> load("image.js");
Ambiguous import: [JavaClass java.net.URL] and [JavaClass java.net.URL]
js> load("image.js");
Ambiguous import: [JavaClass java.lang.System] and [JavaClass java.lang.System]
js> load("image.js");
loadImage for 0
Ambiguous import: [JavaClass java.awt.Toolkit] and [JavaClass java.awt.Toolkit]
js> load("image.js");
loadImage for 0
js>

If I load imag.js first and then button.js, I got the following:

js> load("image.js");
loadImage for 0
js: [JavaPackage java.lang.URL] is not a function.
[JavaPackage java.lang.URL] is not a function.
js> load("image.js");
js: [JavaPackage java.lang.ImageIcon] is not a function.
[JavaPackage java.lang.ImageIcon] is not a function.
js> load("image.js");
js: [JavaPackage java.lang.ImageIcon] is not a function.
[JavaPackage java.lang.ImageIcon] is not a function.
js> load("image.js");
js: [JavaPackage java.lang.ImageIcon] is not a function.
[JavaPackage java.lang.ImageIcon] is not a function.
js> load("button.js");
js: [JavaPackage java.lang.JButton] is not a function.
[JavaPackage java.lang.JButton] is not a function.
js> load("button.js");
js: [JavaPackage java.lang.JButton] is not a function.
[JavaPackage java.lang.JButton] is not a function.
js> load("image.js");
js: [JavaPackage java.lang.ImageIcon] is not a function.
[JavaPackage java.lang.ImageIcon] is not a function.
js>

It looks like something wrong in the image.js file but this should not interfere with button.js. It looks like some arbitary package objects are created, like java.lang.URL. This happened in NativeJavaPackage.get method. If a class of java.lang.URL is not found, a package object is then created. So next time the interpreter encounters URL, it somehow uses the object java.lang.URL instead of the correct class object java.net.URL.. This is one problem. The interference between button.js and jmage.js is another problem.

Howard
  ----- Original Message -----
  From: Norris Boyd
  To: \ Howard\\ Xuhua Lin
  Sent: Thursday, August 12, 1999 12:58 PM
  Subject: Re: ImporterTopLevel problem


  Sorry I've been slow. I finished up the fix this morning and have posted it on the ftp site and checked into cvs.
  Let me know if it works for you.

  --Norris

  \"Howard\" Xuhua Lin wrote:

    Hi, Norris, what's the status of the ImporterTopeLevel problem (i.e if you use importPackage twice, you will get an "Ambiguous import" exception)? Are you still working on it? Howard
This commit is contained in:
norris%netscape.com 1999-08-13 17:25:14 +00:00
Родитель 5399226320
Коммит 4751b9866b
4 изменённых файлов: 50 добавлений и 26 удалений

Просмотреть файл

@ -75,7 +75,7 @@ public class ImporterTopLevel extends ScriptableObject {
for (int i=0; i < importedPackages.size(); i++) {
Object o = importedPackages.elementAt(i);
NativeJavaPackage p = (NativeJavaPackage) o;
Object v = p.get(name, start);
Object v = p.getPkgProperty(name, start, false);
if (!(v instanceof NativeJavaPackage)) {
if (result == NOT_FOUND)
result = v;

Просмотреть файл

@ -128,13 +128,19 @@ public class NativeJavaPackage extends ScriptableObject {
}
public synchronized Object get(String id, Scriptable start) {
Object cached = super.get(id, start);
return getPkgProperty(id, start, true);
}
synchronized Object getPkgProperty(String name, Scriptable start,
boolean createPkg)
{
Object cached = super.get(name, start);
if (cached != NOT_FOUND)
return cached;
String newPackage = packageName.length() == 0
? id
: packageName + "." + id;
? name
: packageName + "." + name;
Context cx = Context.getContext();
SecuritySupport ss = cx.getSecuritySupport();
Scriptable newValue;
@ -146,18 +152,24 @@ public class NativeJavaPackage extends ScriptableObject {
newValue.setParentScope(this);
newValue.setPrototype(this.prototype);
} catch (ClassNotFoundException ex) {
newValue = new NativeJavaPackage(newPackage);
newValue.setParentScope(this);
newValue.setPrototype(this.prototype);
if (createPkg) {
NativeJavaPackage pkg = new NativeJavaPackage(newPackage);
pkg.setParentScope(this);
pkg.setPrototype(this.prototype);
newValue = pkg;
} else {
newValue = null;
}
}
if (newValue != null) {
// Make it available for fast lookup and sharing of
// lazily-reflected constructors and static members.
super.put(name, start, newValue);
}
// Make it available for fast lookup and sharing of lazily-reflected
// constructors and static members.
super.put(id, start, newValue);
return newValue;
}
public synchronized Object get(int index, Scriptable start) {
public Object get(int index, Scriptable start) {
return NOT_FOUND;
}

Просмотреть файл

@ -75,7 +75,7 @@ public class ImporterTopLevel extends ScriptableObject {
for (int i=0; i < importedPackages.size(); i++) {
Object o = importedPackages.elementAt(i);
NativeJavaPackage p = (NativeJavaPackage) o;
Object v = p.get(name, start);
Object v = p.getPkgProperty(name, start, false);
if (!(v instanceof NativeJavaPackage)) {
if (result == NOT_FOUND)
result = v;

Просмотреть файл

@ -128,13 +128,19 @@ public class NativeJavaPackage extends ScriptableObject {
}
public synchronized Object get(String id, Scriptable start) {
Object cached = super.get(id, start);
return getPkgProperty(id, start, true);
}
synchronized Object getPkgProperty(String name, Scriptable start,
boolean createPkg)
{
Object cached = super.get(name, start);
if (cached != NOT_FOUND)
return cached;
String newPackage = packageName.length() == 0
? id
: packageName + "." + id;
? name
: packageName + "." + name;
Context cx = Context.getContext();
SecuritySupport ss = cx.getSecuritySupport();
Scriptable newValue;
@ -146,18 +152,24 @@ public class NativeJavaPackage extends ScriptableObject {
newValue.setParentScope(this);
newValue.setPrototype(this.prototype);
} catch (ClassNotFoundException ex) {
newValue = new NativeJavaPackage(newPackage);
newValue.setParentScope(this);
newValue.setPrototype(this.prototype);
if (createPkg) {
NativeJavaPackage pkg = new NativeJavaPackage(newPackage);
pkg.setParentScope(this);
pkg.setPrototype(this.prototype);
newValue = pkg;
} else {
newValue = null;
}
}
if (newValue != null) {
// Make it available for fast lookup and sharing of
// lazily-reflected constructors and static members.
super.put(name, start, newValue);
}
// Make it available for fast lookup and sharing of lazily-reflected
// constructors and static members.
super.put(id, start, newValue);
return newValue;
}
public synchronized Object get(int index, Scriptable start) {
public Object get(int index, Scriptable start) {
return NOT_FOUND;
}