Subj : Re: Rhino instanceof problem/question. To : ob7ect From : Igor Bukanov Date : Thu Jan 22 2004 05:18 pm ob7ect wrote: > I've been using Rhino in an application that I've been developing for > a couple of years, and have never encountered this problem before. > I'm wondering if it's just something trivial that I've missed, but > perhaps someone can help illuminate the problem. > > In Java, I'm calling a JS function: > > Object[] fArgs = new Object[]{ > activator, target, cmdstring, sd, new Integer(2) > }; > boolean result = Context.toBoolean( > ScriptEngine.callFunction(sd.getFunctionName(), fArgs ) ); > > In JS, the function I'm calling is like this: > > function myfunction(activator,target,cstr,sd,state){ > > > if ( target instanceof my.framework.BaseObject ){ > // is a BaseObject > // never evaluates true, although it should > }else{ > echo("class: " + target.getClass().getName()); > // echos: class: my.framework.BaseObject > } > > if ( target.getParent() instanceof my.framework.BaseObject ){ > // is a BaseObject > // evaluates true > } > > } > > > Now I know that the object being passed in through the 'target' > parameter is ALWAYS a subclass of BaseObject (as is reported by > getClass().getName()), and that it's parent (getParent()) is also > always a BaseObject. Now for some reason the first call, which tests > the function arg 'target' doesn't type to any class -- not even > Object, while the second does seem to work. > > Does Rhino do something special to function argument parameters that > prevents instanceof from operating on them properly?? Did you converted target to Scriptable (through Context.toObject() or through Context.javaToJS() in the forthcomming Rhino 1.5R5) before calling the script function? Rhino expects that function parameters should only be instances of String, Number, Boolean and Scriptable. If you fail to do so, the results vary. Regards, Igor .