Implement the "cast" of java class objects so that js objects in java adapters can

use 'this' for the implemented java interface.
This commit is contained in:
norris%netscape.com 1999-09-24 18:20:08 +00:00
Родитель 96c3481ea5
Коммит 4c9c27afaa
2 изменённых файлов: 30 добавлений и 0 удалений

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

@ -118,6 +118,21 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
Object[] args)
throws JavaScriptException
{
// If it looks like a "cast" of an object to this class type,
// walk the prototype chain to see if there's a wrapper of a
// object that's an instanceof this class.
if (args.length == 1 && args[0] instanceof Scriptable) {
Class c = getClassObject();
Scriptable p = (Scriptable) args[0];
do {
if (p instanceof Wrapper) {
Object o = ((Wrapper) p).unwrap();
if (c.isInstance(o))
return p;
}
p = p.getPrototype();
} while (p != null);
}
return construct(cx, scope, args);
}

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

@ -118,6 +118,21 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
Object[] args)
throws JavaScriptException
{
// If it looks like a "cast" of an object to this class type,
// walk the prototype chain to see if there's a wrapper of a
// object that's an instanceof this class.
if (args.length == 1 && args[0] instanceof Scriptable) {
Class c = getClassObject();
Scriptable p = (Scriptable) args[0];
do {
if (p instanceof Wrapper) {
Object o = ((Wrapper) p).unwrap();
if (c.isInstance(o))
return p;
}
p = p.getPrototype();
} while (p != null);
}
return construct(cx, scope, args);
}