Hi all,

I'm just testing out Rhino a little and came across an issue. I made
the following ScriptedObject - absolutely useless, again, just for
testing -:
public class MSRScreen extends ScriptableObject {
   private static final long serialVersionUID =
-6246695110439492400L;

   public MSRScreen() {}

   public MSRScreen(string name) {
       jsFunction_flush();
   }

   public void jsConstructor() {}

   public void jsFunction_flush() {
       //Do absolutely nothing
   }
}

I have the following piece of code to run a script:
   private static Context context;
   private static ScriptableObject scope;

   public static void run(String script)
   {
       try {
           context = Context.enter();

           scope = context.initStandardObjects(null, true);
           ScriptableObject.defineClass(scope, MSRScreen.class);
           scope.defineFunctionProperties(new String[] { "screen",
"print" }, MSRhino.class, ScriptableObject.DONTENUM);

           context.evaluateString(scope, script, "Test", 0, null);
       }
       catch(Exception ex) {
           ex.printStackTrace();
       }
       finally {
           Context.exit();
       }
   }

   public static Object screen(String name) {
       return Context.toObject(new MSRScreen(name), scope);
   }

   public static void print(String value) {
       System.out.println(value);
   }

I pass to following small JavaScript to the run-method:
var a = screen("LCD");
a.flush();

For some reason, "var a" becomes a java.lang.String and the second
line will then complain it can't find "flush"  in java.lang.String.

Same occurs when i do directly screen("LCD").flush();

Why is this? Am I missing a specific piece of code? Please note that
I'm not interested in Live Connect or alike, my test in this case is
instancing a Java-object which has JS-methods in it and pass it to JS
to be used as that. Doing a direct "new MSRScreen().flush" from within
JS works fine, so it's not the class. For some reason, Rhino "forgets"
that the object is a MSRScreen and turns it into a String (at least,
thats what I see happening).

Any help is much appreciated!

Yours sincerely,
Lennard Fonteijn
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to