JSDK:     Java SDK 1.4
Status:   Currently blocked!
Required: Urgent help or labotomy.
History:
I have a comprehensive embedded Java test harness/engine part of which
includes an 'event' generation and 'event' matching/waiting subsystem.
The javascript tests can wait for events to occur from the Java system
(under test) using a wait method (also entirely written in Java).
I need to be able to pass a Javascript object to Java to be called
from the event matching mechanism (Java) so that the test script can
decide if the event matches what it is expecting rather than some pre-
defined Java matching criteria.
I need to do this so that I can wait on multiple events
simultaneously, each using different javascript object instances of
the same Javascript code (see futureWaitEvent).

IF the tests were written in Java, the event handler would look like
this (at its VERY simplest!):
Java>   class Handler(name)
Java>   {
Java>           private String name = "";
Java>           public Handler(String name)
Java>           {
Java>                   this.name = name;
Java>           }
Java>           public boolean handle(Object someDataFromJavaLand)
Java>           {
Java>                   System.out.println(this.name);
Java>                   boolean handled = false;
Java>
Java>                   ...
Java>                   //      Decide if the someDataFromJavaLand is handled 
or not...
Java>                   ...
Java>                   return handled;
Java>           }
Java>   }
Java>
Java>   // The Java test script's main method of work:
Java>   public void testDoesSomeWork()
Java>   {
Java>           ...
Java>           var waited = waitEvent(new handler("hello"), new
handler("world!));
Java>           ...
Java>   }
Java>
Java>   public boolean waitEvent(Handler a, Handler b)
Java>   {
Java>           ...
Java>           boolean handled = a.handle(eventData);
Java>           handled &= b.handle(eventData);
Java>           ...
Java>   }


Question)       Is this a sensible way to do it in Java/Javascript (SEE
BELOW), if so, how do I do the bit I'm stuck on, if not can someone
suggest a sensible and easy way of doing it - including code if
possible 8-)!!


js>     //      Javascript event handler 'proxy' object.
js>     function foo(someData)
js>     {
js>             this.data = someData;
js>             this.handler = "foobar";
js>     }
js>
js>     //      Javascript event handler.
js>     function foobar(dataFromJavaLand, dataFromFunctionFoo)
js>     {
js>             //      I need access to some data from Java
js>             //      I also need access to foo.data.
js>
js>             //      Do some work with the data.
js>     }
js>
js>     //
js>     function work()
js>     {
js>             //      Call the event waiting mechanism.
js>             var result = waitEvent(new foo("hello world!"));
js>             var anotherResult = futureWaitEvent(new foo("hello"), new
foo("world!"));
js>     }
Java>
Java>   public static boolean waitEvent(Object jsData)
Java>   {
Java>           //      (jsData is of type NativeObject).
Java>
Java>           //      * * THIS IS THE BIT I'M STUCK ON! * *
Java>
Java>           //      Psudo-code:
Java>           //      * * I need to be able to do this: * *
Java>           //              Object dataFromJs = jsData.data;
Java>           //      ...and then call the method thus:
Java>           //              Objcet someNewData = new Integer(1);    //      
At the very
simplest.
Java>           //              Object result = jsData.handler(someNewData, 
dataFromJs);
Java>   }

TIA, Frank.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to