Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 47337 invoked from network); 9 Feb 2011 09:35:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Feb 2011 09:35:07 -0000 Received: (qmail 41367 invoked by uid 500); 9 Feb 2011 09:35:07 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 40773 invoked by uid 500); 9 Feb 2011 09:35:04 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 40764 invoked by uid 99); 9 Feb 2011 09:35:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Feb 2011 09:35:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Feb 2011 09:35:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 34E3D2388A38; Wed, 9 Feb 2011 09:34:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1068807 - /sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java Date: Wed, 09 Feb 2011 09:34:42 -0000 To: commits@sling.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110209093442.34E3D2388A38@eris.apache.org> Author: fmeschbe Date: Wed Feb 9 09:34:41 2011 New Revision: 1068807 URL: http://svn.apache.org/viewvc?rev=1068807&view=rev Log: SLING-1972 Don't keep the script toplevel scope as an instance field. Rather use the top call scope field of the Rhino Context Modified: sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java Modified: sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java?rev=1068807&r1=1068806&r2=1068807&view=diff ============================================================================== --- sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java (original) +++ sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java Wed Feb 9 09:34:41 2011 @@ -47,7 +47,6 @@ import org.slf4j.Logger; public class RhinoJavaScriptEngine extends AbstractSlingScriptEngine { private Scriptable rootScope; - private Scriptable scope; public RhinoJavaScriptEngine(ScriptEngineFactory factory, Scriptable rootScope) { @@ -73,32 +72,28 @@ public class RhinoJavaScriptEngine exten // container for replaced properties Map replacedProperties = null; + Scriptable scope = null; // create a rhino Context and execute the script try { final Context rhinoContext = Context.enter(); - if (ScriptRuntime.hasTopCall(rhinoContext) && scope == null) { - + if (ScriptRuntime.hasTopCall(rhinoContext)) { // reuse the top scope if we are included scope = ScriptRuntime.getTopCallScope(rhinoContext); - } else { - - if (scope == null) { - // create the request top scope, use the ImporterToplevel here - // to support the importPackage and importClasses functions - scope = new ImporterTopLevel(); // new NativeObject(); - - // Set the global scope to be our prototype - scope.setPrototype(rootScope); - - // We want "scope" to be a new top-level scope, so set its - // parent scope to null. This means that any variables created - // by assignments will be properties of "scope". - scope.setParentScope(null); - } + // create the request top scope, use the ImporterToplevel here + // to support the importPackage and importClasses functions + scope = new ImporterTopLevel(); + + // Set the global scope to be our prototype + scope.setPrototype(rootScope); + + // We want "scope" to be a new top-level scope, so set its + // parent scope to null. This means that any variables created + // by assignments will be properties of "scope". + scope.setParentScope(null); // setup the context for use WrapFactory wrapFactory = ((RhinoJavaScriptEngineFactory) getFactory()).getWrapFactory(); @@ -121,7 +116,7 @@ public class RhinoJavaScriptEngine exten // log the script stack trace ((Logger) bindings.get(SlingBindings.LOG)).error(t.getScriptStackTrace()); - + // set the exception cause Object value = t.getValue(); if (value != null) { @@ -132,12 +127,12 @@ public class RhinoJavaScriptEngine exten se.initCause((Throwable) value); } } - + // if the cause could not be set, overwrite the stack trace if (se.getCause() == null) { se.setStackTrace(t.getStackTrace()); } - + throw se; } catch (Throwable t) { @@ -153,7 +148,6 @@ public class RhinoJavaScriptEngine exten resetBoundProperties(scope, replacedProperties); Context.exit(); - } }