I have a very complex Java application. It has a GUI development front end
that allows users to write JavaScript statements in and insert them in
dozens of places. Currently, we have to use the eval to continuously
compile and execute the JavaScript code. This code is executed thousands
of times
and it requires access to the beans created by the Java program. This fix
improved our performance by up to 10X depending on the testcase.
Note, I modified the JavaScriptEngine.java by adding getScope() method.
This method returns the scope (see below).
private Scriptable global;
public Scriptable getScope(){
return global;
}
The following is the modified code I clipped from our application:
String scriptKey = rsc.getName() + "." + attr;
Script scriptx = null;
if ( javascript){
/compile only once if javascript
try {
scriptx = (Script)scriptExec.get(scriptKey);
if (scriptx == null) { // has it been
compiled ?
---> Reader rr = new StringReader((String)map);
---> scriptx = cx.compileReader (bsfE.getScope()
,rr,rsc.getName() + "." + attr, 0,null); // compile, cx is Context
scriptExec.put(scriptKey,scriptx) ; // save the
executable in hashtable
}
---> scriptx.exec (cx,bsfE.getScope());
//execute compiled script
} catch (Exception ee) { //ivan - Please check out my
exception processing
log.error ("while.evaluating", rsc.getName() + "." + attr,
(Exception) value);
throw ee;
}
}
I would like you to make getScope() call available in your next release.
Note, There are other places where we do call JavaScript routines.
However, the way our application is designed we need this additional
feature to get acceptable performance.
Thanks,
Ivan
Ivan R. Eisen
Senior Software Engineer
Work (512)838-8255 or Tie-Line 678-8255
"Victor J.
Orlikowski" To: [EMAIL PROTECTED]
<[EMAIL PROTECTED] cc:
du> Subject: Re: Public availability of
the global scope variable
06/13/03 01:44 AM
Please respond to
"Bean Scripting
Framework
developers"
On Thu, May 08, 2003 at 09:04:35AM -0500, Ivan Eisen wrote:
> I have and application where Rhino JavaScript routines are executed
> repeatedly.�� I have compiled them and cached the executable;� however,
I
> had to modify the com\ibm\bsf\engines\javascript\JavaScriptEngine.java
> routine to get� the private variable Scriptable global.� I need a way to
> get the global scope so that I can get to declared beans that in our
> JavaScript routines.�� Are you planning to make the global scope variable
> available in a future release?� If so when is that release scheduled.
>
Apologies again for the late reply, Ivan.
It had not been the intent to provide access to the global scope
via the Scriptable variable global.
I am curious as to why you need access to this variable; since you
have declared the beans to BSF, and modified them via Javascript,
you should still be able to access them via the calling Java code.
I'm afraid I need a little more information, to understand your
requirements.
Victor
--
Victor J. Orlikowski | The Wall is Down, But the Threat Remains!
==================================================================
[EMAIL PROTECTED] | [EMAIL PROTECTED] | [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]