Hi Greg,

Thanks for your response. Replies below:

On 10-08-21 01:41 PM, Greg Roodt wrote:
I believe load() is part of Rhino Shell. I think all that the<script />
task runs when using JavaScript is the interpreter. It would only have the
pure Javascript standard language features (and a few bits and pieces to
interact with Java and the execution context).
load() is normally exposed as part of the global object when running Rhino, in the shell or the interpreter. All the js module loaders that support Rhino that I've encountered, including RequireJS and dojo, make use of load() to load JavaScript modules.
It might be easier to run the shell for each test? Like so:
java org.mozilla.javascript.tools.shell.Main [options]
script-filename-or-url [script-arguments]
https://developer.mozilla.org/en/Rhino_Shell#Invoking_the_Shell

Or like John Resig does with env.js:
http://ejohn.org/blog/bringing-the-browser-to-the-server/
I'm using that technique for other parts of my code, but it would be much easier to simply hook into Ant's ResourceSet data structures for this part, as it's possible to register a number of unit tests with dojo before running them.

Or maybe, define your own global load() function inside the<script />  tag?
That's what I'm working on. This seems to work, but I still need to test it with the dojo module loader:

        <script language="javascript" manager="bsf">

            <classpath>

                <fileset dir="../../../lib/java/" includes="js.jar"/>

                <fileset dir="../../../lib/build-java/" 
includes="*.jar"></fileset>

            </classpath><![CDATA[

            //define load in global scope

            function readFile(path){

                stream = new java.io.FileInputStream(new java.io.File(path));

                fc = stream.getChannel();

                bb = fc.map(java.nio.channels.FileChannel.MapMode.READ_ONLY, 0, 
fc.size());

                return 
java.nio.charset.Charset.defaultCharset().decode(bb).toString();

            }

            load = function(path){

                eval(String(readFile(path)))

            }

            echo = helloworld.createTask("echo");

            var contents = readFile('hello.js')

            echo.setMessage(contents);

            echo.perform();

            load('hello.js')

            echo.perform();

]]></script>

hello.js:

echo.setMessage("hello world!");


Outputs:

hello:

     [echo] echo.setMessage("hello world!");

     [echo] hello world!


Thanks,

Jake

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to