Hi,

Is there a particular style of writing javascript objects that rhino performs best with? For example, I would prefer to write JS like the first script example below. Does it matter how you write the JS?

In addition (sanity check...), say the script below
- was compiled (compileReader) in a servlet's doGet and cached for subsequent use. - the script is combined with a script compiled in the servlet's init method. - then, create a NativeObject and give it your request and response objects as properties which is a passed as the args of a callMethod.

e.g.
// in a doGet method
Scriptable scope = context.newObject(sharedScope);
scope.setPrototype(sharedScope);
scope.setParentScope(null);
// create a new compiled script or get the cached version
Script script = getScript(context, scriptRes);
NativeObject result = (NativeObject)script.exec(context, scope);
NativeObject params = new NativeObject();
params.put("request", params, req);
params.put("response", params, resp);
Object[] args = {params};
NativeObject doGet = (NativeObject)ScriptableObject.callMethod(result, req.getMethod(), args);

Is the above java and the first script below threadsafe in a servlet type of interaction?

Preferred example script:

(function() {
  var privateFunc = function(request, response) {
...
  }
  return {
    GET: function(params) {
      var request = params.request;
      var response = params. response;
      privateFunc(request, response);
...
    }
  }
})();

or should you write your functions like:

function GET() {

}

or

var GET = function() {

}

or

var Obj = {
  GET: function() {

  }
}

etc...

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

Reply via email to