* No more need for per-thread-scope workaround, works out of the box with Rhino 1.6.
This commit is contained in:
parent
b210d5cd11
commit
7e00def51c
3 changed files with 12 additions and 45 deletions
|
@ -78,7 +78,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
|||
"wrapJavaMap", "unwrapJavaMap"
|
||||
};
|
||||
|
||||
defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
|
||||
defineFunctionProperties(globalFuncs, GlobalObject.class, DONTENUM | READONLY | PERMANENT);
|
||||
put("app", this, Context.toObject(new ApplicationBean(app), this));
|
||||
put("Xml", this, Context.toObject(new XmlObject(core), this));
|
||||
put("global", this, this);
|
||||
|
@ -127,48 +127,19 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
|||
if (isRecording) {
|
||||
changedProperties.add(name);
|
||||
}
|
||||
Context cx = Context.getCurrentContext();
|
||||
GlobalObject scope = (GlobalObject) cx.getThreadLocal("threadscope");
|
||||
if (scope != null) {
|
||||
// check if this is a per-thread scope instance
|
||||
if (sharedGlobal != null) {
|
||||
// make thread scope accessible as "global"
|
||||
if ("global".equals(name)) {
|
||||
return scope;
|
||||
return this;
|
||||
}
|
||||
// use synchronized get on fast changing per-thread scopes just to be sure
|
||||
Object obj = scope.getSynchronized(name);
|
||||
if (obj != null && obj != NOT_FOUND) {
|
||||
return obj;
|
||||
synchronized(this) {
|
||||
return super.get(name, start);
|
||||
}
|
||||
}
|
||||
if (sharedGlobal != null) {
|
||||
// we're a per-thread scope
|
||||
return sharedGlobal.getInternal(name);
|
||||
} else {
|
||||
// we are the shared scope
|
||||
return super.get(name, start);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly get a property, bypassing the extra stuff in get(String, Scriptable).
|
||||
*
|
||||
* @param name
|
||||
* @return the property for the given name
|
||||
*/
|
||||
protected Object getInternal(String name) {
|
||||
return super.get(name, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly get a property, bypassing the extra stuff in get(String, Scriptable),
|
||||
* and synchronizing in order to prevent cache read errors on multiprocessor systems.
|
||||
* TODO: we need extensive testing in order to tell whether this is really necessary.
|
||||
*
|
||||
* @param name
|
||||
* @return the property for the given name
|
||||
*/
|
||||
protected synchronized Object getSynchronized(String name) {
|
||||
return super.get(name, this);
|
||||
// we're the shared scope
|
||||
return super.get(name, start);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -750,4 +721,8 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
|||
public void clearChangeSet() {
|
||||
changedProperties = null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return sharedGlobal == null ? "[Shared Scope]" : "[Thread Scope]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -780,9 +780,6 @@ public final class RhinoCore implements ScopeProvider {
|
|||
private synchronized void evaluate (TypeInfo type, Resource code) {
|
||||
// get the current context
|
||||
Context cx = Context.getCurrentContext();
|
||||
// unregister the per-thread scope while evaluating
|
||||
Object threadScope = cx.getThreadLocal("threadscope");
|
||||
cx.removeThreadLocal("threadscope");
|
||||
|
||||
String sourceName = code.getName();
|
||||
Reader reader = null;
|
||||
|
@ -830,9 +827,6 @@ public final class RhinoCore implements ScopeProvider {
|
|||
// shouldn't happen
|
||||
}
|
||||
}
|
||||
if (threadScope != null) {
|
||||
cx.putThreadLocal("threadscope", threadScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,6 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
|
||||
context.setOptimizationLevel(optLevel);
|
||||
// register the per-thread scope with the dynamic scope
|
||||
context.putThreadLocal("threadscope", global);
|
||||
context.putThreadLocal("reval", reval);
|
||||
context.putThreadLocal("engine", this);
|
||||
// update prototypes
|
||||
|
@ -227,7 +226,6 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
public synchronized void exitContext() {
|
||||
context.removeThreadLocal("reval");
|
||||
context.removeThreadLocal("engine");
|
||||
context.removeThreadLocal("threadscope");
|
||||
Context.exit();
|
||||
// core.global.unregisterScope();
|
||||
thread = null;
|
||||
|
|
Loading…
Add table
Reference in a new issue