src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java
Print this page
@@ -722,20 +722,12 @@
}
// In strict mode, eval does not instantiate variables and functions
// in the caller's environment. A new environment is created!
if (strictFlag) {
- // Create a new scope object
- final ScriptObject strictEvalScope = global.newObject();
-
- // bless it as a "scope"
- strictEvalScope.setIsScope();
-
- // set given scope to be it's proto so that eval can still
- // access caller environment vars in the new environment.
- strictEvalScope.setProto(scope);
- scope = strictEvalScope;
+ // Create a new scope object with given scope as its prototype
+ scope = newScope(scope);
}
final ScriptFunction func = getProgramFunction(clazz, scope);
Object evalThis;
if (directEval) {
@@ -746,10 +738,14 @@
}
return ScriptRuntime.apply(func, evalThis);
}
+ private static ScriptObject newScope(final ScriptObject callerScope) {
+ return new FunctionScope(PropertyMap.newMap(FunctionScope.class), callerScope);
+ }
+
private static Source loadInternal(final String srcStr, final String prefix, final String resourcePath) {
if (srcStr.startsWith(prefix)) {
final String resource = resourcePath + srcStr.substring(prefix.length());
// NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
// These scripts are always available and are loaded from nashorn.jar's resources.