src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java

Print this page




 686         }
 687 
 688         // In strict mode, eval does not instantiate variables and functions
 689         // in the caller's environment. A new environment is created!
 690         if (strictFlag) {
 691             // Create a new scope object
 692             final ScriptObject strictEvalScope = global.newObject();
 693 
 694             // bless it as a "scope"
 695             strictEvalScope.setIsScope();
 696 
 697             // set given scope to be it's proto so that eval can still
 698             // access caller environment vars in the new environment.
 699             strictEvalScope.setProto(scope);
 700             scope = strictEvalScope;
 701         }
 702 
 703         final ScriptFunction func = getProgramFunction(clazz, scope);
 704         Object evalThis;
 705         if (directEval) {
 706             evalThis = callThis instanceof ScriptObject || strictFlag ? callThis : global;
 707         } else {
 708             evalThis = global;
 709         }
 710 
 711         return ScriptRuntime.apply(func, evalThis);
 712     }
 713 
 714     private static Source loadInternal(final String srcStr, final String prefix, final String resourcePath) {
 715         if (srcStr.startsWith(prefix)) {
 716             final String resource = resourcePath + srcStr.substring(prefix.length());
 717             // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
 718             // These scripts are always available and are loaded from nashorn.jar's resources.
 719             return AccessController.doPrivileged(
 720                     new PrivilegedAction<Source>() {
 721                         @Override
 722                         public Source run() {
 723                             try {
 724                                 final URL resURL = Context.class.getResource(resource);
 725                                 return resURL != null ? sourceFor(srcStr, resURL) : null;
 726                             } catch (final IOException exp) {




 686         }
 687 
 688         // In strict mode, eval does not instantiate variables and functions
 689         // in the caller's environment. A new environment is created!
 690         if (strictFlag) {
 691             // Create a new scope object
 692             final ScriptObject strictEvalScope = global.newObject();
 693 
 694             // bless it as a "scope"
 695             strictEvalScope.setIsScope();
 696 
 697             // set given scope to be it's proto so that eval can still
 698             // access caller environment vars in the new environment.
 699             strictEvalScope.setProto(scope);
 700             scope = strictEvalScope;
 701         }
 702 
 703         final ScriptFunction func = getProgramFunction(clazz, scope);
 704         Object evalThis;
 705         if (directEval) {
 706             evalThis = (callThis != UNDEFINED && callThis != null) || strictFlag ? callThis : global;
 707         } else {
 708             evalThis = global;
 709         }
 710 
 711         return ScriptRuntime.apply(func, evalThis);
 712     }
 713 
 714     private static Source loadInternal(final String srcStr, final String prefix, final String resourcePath) {
 715         if (srcStr.startsWith(prefix)) {
 716             final String resource = resourcePath + srcStr.substring(prefix.length());
 717             // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
 718             // These scripts are always available and are loaded from nashorn.jar's resources.
 719             return AccessController.doPrivileged(
 720                     new PrivilegedAction<Source>() {
 721                         @Override
 722                         public Source run() {
 723                             try {
 724                                 final URL resURL = Context.class.getResource(resource);
 725                                 return resURL != null ? sourceFor(srcStr, resURL) : null;
 726                             } catch (final IOException exp) {