From 7e00def51cf401d029f6a57e59b68c459499123d Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 11 Dec 2006 09:55:23 +0000 Subject: [PATCH] * No more need for per-thread-scope workaround, works out of the box with Rhino 1.6. --- src/helma/scripting/rhino/GlobalObject.java | 49 +++++---------------- src/helma/scripting/rhino/RhinoCore.java | 6 --- src/helma/scripting/rhino/RhinoEngine.java | 2 - 3 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/helma/scripting/rhino/GlobalObject.java b/src/helma/scripting/rhino/GlobalObject.java index b239ac75..58ea1b8d 100644 --- a/src/helma/scripting/rhino/GlobalObject.java +++ b/src/helma/scripting/rhino/GlobalObject.java @@ -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]"; + } } diff --git a/src/helma/scripting/rhino/RhinoCore.java b/src/helma/scripting/rhino/RhinoCore.java index aa880ae6..b6bf430f 100644 --- a/src/helma/scripting/rhino/RhinoCore.java +++ b/src/helma/scripting/rhino/RhinoCore.java @@ -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); - } } } diff --git a/src/helma/scripting/rhino/RhinoEngine.java b/src/helma/scripting/rhino/RhinoEngine.java index 1693f779..ccea3cd8 100644 --- a/src/helma/scripting/rhino/RhinoEngine.java +++ b/src/helma/scripting/rhino/RhinoEngine.java @@ -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;