* Make init(), enterContext(), exitContext() and abort()

synchronized (can't hurt)
* Some mostly stylistic improvements prompted by Intellij
This commit is contained in:
hns 2006-01-11 16:05:48 +00:00
parent cb92ec8469
commit 39f8bbe85e

View file

@ -72,12 +72,13 @@ public class RhinoEngine implements ScriptingEngine {
* Zero argument constructor. * Zero argument constructor.
*/ */
public RhinoEngine() { public RhinoEngine() {
// nothing to do
} }
/** /**
* Init the scripting engine with an application and a request evaluator * Init the scripting engine with an application and a request evaluator
*/ */
public void init(Application app, RequestEvaluator reval) { public synchronized void init(Application app, RequestEvaluator reval) {
this.app = app; this.app = app;
this.reval = reval; this.reval = reval;
core = getRhinoCore(app); core = getRhinoCore(app);
@ -170,6 +171,7 @@ public class RhinoEngine implements ScriptingEngine {
try { try {
optLevel = Integer.parseInt(app.getProperty("rhino.optlevel")); optLevel = Integer.parseInt(app.getProperty("rhino.optlevel"));
} catch (Exception ignore) { } catch (Exception ignore) {
// use default opt-level
} }
context.setOptimizationLevel(optLevel); context.setOptimizationLevel(optLevel);
@ -187,20 +189,19 @@ public class RhinoEngine implements ScriptingEngine {
* evaluation is entered. The globals parameter contains the global values * evaluation is entered. The globals parameter contains the global values
* to be applied during this execution context. * to be applied during this execution context.
*/ */
public void enterContext(Map globals) throws ScriptingException { public synchronized void enterContext(Map globals) throws ScriptingException {
// set the thread filed in the FESI evaluator // remember the current thread as our thread
// evaluator.thread = Thread.currentThread ();
// set globals on the global object
// context = Context.enter (context);
globals.putAll(extensionGlobals);
thread = Thread.currentThread(); thread = Thread.currentThread();
if ((globals != null) && (globals != lastGlobals)) { // set globals on the global object
if (globals != lastGlobals) {
// add globals from extensions
globals.putAll(extensionGlobals);
// loop through global vars and set them // loop through global vars and set them
for (Iterator i = globals.keySet().iterator(); i.hasNext();) { for (Iterator i = globals.keySet().iterator(); i.hasNext();) {
String k = (String) i.next(); String k = (String) i.next();
Object v = globals.get(k); Object v = globals.get(k);
Scriptable scriptable = null; Scriptable scriptable;
// create a special wrapper for the path object. // create a special wrapper for the path object.
// other objects are wrapped in the default way. // other objects are wrapped in the default way.
@ -215,17 +216,16 @@ public class RhinoEngine implements ScriptingEngine {
global.put(k, global, scriptable); global.put(k, global, scriptable);
} }
}
// remember the globals set on this evaluator // remember the globals set on this evaluator
lastGlobals = globals; lastGlobals = globals;
} }
}
/** /**
* This method is called to let the scripting engine know that the current * This method is called to let the scripting engine know that the current
* execution context has terminated. * execution context has terminated.
*/ */
public void exitContext() { public synchronized void exitContext() {
context.removeThreadLocal("reval"); context.removeThreadLocal("reval");
context.removeThreadLocal("engine"); context.removeThreadLocal("engine");
context.removeThreadLocal("threadscope"); context.removeThreadLocal("threadscope");
@ -345,7 +345,7 @@ public class RhinoEngine implements ScriptingEngine {
String msg; String msg;
if (x instanceof JavaScriptException) { if (x instanceof JavaScriptException) {
// created by javascript throw statement // created by javascript throw statement
msg = ((JavaScriptException) x).getMessage(); msg = x.getMessage();
} else if (x instanceof WrappedException) { } else if (x instanceof WrappedException) {
// wrapped java excepiton // wrapped java excepiton
WrappedException wx = (WrappedException) x; WrappedException wx = (WrappedException) x;
@ -381,7 +381,7 @@ public class RhinoEngine implements ScriptingEngine {
* Let the evaluator know that the current evaluation has been * Let the evaluator know that the current evaluation has been
* aborted. * aborted.
*/ */
public void abort() { public synchronized void abort() {
// current request has been aborted. // current request has been aborted.
Thread t = thread; Thread t = thread;
if (t != null && t.isAlive()) { if (t != null && t.isAlive()) {
@ -393,6 +393,7 @@ public class RhinoEngine implements ScriptingEngine {
t.stop(); t.stop();
} }
} catch (InterruptedException i) { } catch (InterruptedException i) {
// interrupted, ignore
} }
} }
} }
@ -415,11 +416,7 @@ public class RhinoEngine implements ScriptingEngine {
Object func = ScriptableObject.getProperty(op, fname); Object func = ScriptableObject.getProperty(op, fname);
if (func != null && func != Undefined.instance && func instanceof Function) { return func instanceof Function;
return true;
}
return false;
} }
/** /**