First, is there some way to see the actual java that is created for a
compiled rhino/JS class? (why does the compiler only accept files with
a .js extension?)
---------------------------
I have some questions/concerns about the best way to write JS for rhino
in a servlet container.
I have a router JS that is created as a Script object in a servlet
(RhinoServlet) if null (or a clearCache==true is passed in). In the
servlet, I create an empty NativeObject to namespace my objects/methods
(named 'ripple'). This router.js is exec'd for each request and passed
the request and response objects.
Several 'action' JS'es are created as Script objects and exec'd in the
init method of the servlet. The router.js basically routes request data
to a globally available 'action' JS like so:
var result = ripple[action][reqMethod](reqData);
My question is about the appropriate way to write javascript for such an
environment. For example, if I write a JS like so:
ripple.login = {};
ripple.login.POST = function(reqData) {
// blah blah
}
Or:
ripple.login = {
POST: function(reqData) {
// blah blah
}
};
Will this create static methods? Or will it be OK in a multithreaded
environment?
Instead, should I be writing JS like:
ripple.login = function(){
this.POST = function(reqData) {
// blah blah
}
};
thanks for any insight,
-Rob
Any comments on this?
Actually, just seeing the java source would be helpful. When I compile a
JS file, the source is *not* included. I am not adding the "-nosource"
when compiling. After compiling and then opeing the class in eclipse,
eclipse says no source is associated. Is there some other way to see the
source.
Also, being in a webapp environment I want my server-side javascript
files to have a different extension than ".js" so I can pattern match on
it. The compiler hard codes a FileFilter matching on ".js". Could the
file filter just be taken out? Or make it configurable?
best,
-Rob
There is no Java source: Rhino compiles directly to Java bytecode. If
you use jsc to compile to Java classes you can then use javap to view
the bytecode, but that only helps if you know how to read Java
bytecode :-)
>
> Also, being in a webapp environment I want my server-side javascript
> files to have a different extension than ".js" so I can pattern match on
> it. The compiler hard codes a FileFilter matching on ".js". Could the
> file filter just be taken out? Or make it configurable?
Yes, that sounds like a fine extension if you'd like to propose a
change.
Index: toolsrc/org/mozilla/javascript/tools/jsc/Main.java
===================================================================
RCS
file: /cvsroot/mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/jsc/Main.java,v
retrieving revision 1.13
diff -u -r1.13 Main.java
--- toolsrc/org/mozilla/javascript/tools/jsc/Main.java 10 Nov 2006
15:27:39 -0000 1.13
+++ toolsrc/org/mozilla/javascript/tools/jsc/Main.java 29 Sep 2007
19:19:48 -0000
@@ -248,10 +248,10 @@
{
for (int i = 0; i != filenames.length; ++i) {
String filename = filenames[i];
- if (!filename.endsWith(".js")) {
+ /*if (!filename.endsWith(".js")) {
addError("msg.extension.not.js", filename);
return;
- }
+ }*/
File f = new File(filename);
String source = readSource(f);
if (source == null) return;
#############################
:)
best,
-Rob