boolean isTopLevelCall = false;
// create a rhino Context and execute the script
try {
final Context rhinoContext = Context.enter();
rhinoContext.setOptimizationLevel(optimizationLevel());
if (ScriptRuntime.hasTopCall(rhinoContext)) {
// reuse the top scope if we are included
scope = ScriptRuntime.getTopCallScope(rhinoContext);
} else {
// 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();
rhinoContext.setWrapFactory(wrapFactory);
// this is the top level call
isTopLevelCall = true;
}
// add initial properties to the scope
replacedProperties = setBoundProperties(scope, bindings);
final int lineNumber = 1;
final Object securityDomain = null;
Object result = rhinoContext.evaluateReader(scope, scriptReader, scriptName,
lineNumber, securityDomain);
if (result instanceof Wrapper) {
result = ((Wrapper) result).unwrap();
}