< prev index next >

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

Print this page




 724         // In strict mode, eval does not instantiate variables and functions
 725         // in the caller's environment. A new environment is created!
 726         if (strictFlag) {
 727             // Create a new scope object with given scope as its prototype
 728             scope = newScope(scope);
 729         }
 730 
 731         final ScriptFunction func = getProgramFunction(clazz, scope);
 732         Object evalThis;
 733         if (directEval) {
 734             evalThis = (callThis != UNDEFINED && callThis != null) || strictFlag ? callThis : global;
 735         } else {
 736             // either indirect evalCall or non-eval (Function, engine.eval, ScriptObjectMirror.eval..)
 737             evalThis = callThis;
 738         }
 739 
 740         return ScriptRuntime.apply(func, evalThis);
 741     }
 742 
 743     private static ScriptObject newScope(final ScriptObject callerScope) {
 744         return new FunctionScope(PropertyMap.newMap(FunctionScope.class), callerScope);
 745     }
 746 
 747     private static Source loadInternal(final String srcStr, final String prefix, final String resourcePath) {
 748         if (srcStr.startsWith(prefix)) {
 749             final String resource = resourcePath + srcStr.substring(prefix.length());
 750             // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
 751             // These scripts are always available and are loaded from nashorn.jar's resources.
 752             return AccessController.doPrivileged(
 753                     new PrivilegedAction<Source>() {
 754                         @Override
 755                         public Source run() {
 756                             try {
 757                                 final URL resURL = Context.class.getResource(resource);
 758                                 return resURL != null ? sourceFor(srcStr, resURL) : null;
 759                             } catch (final IOException exp) {
 760                                 return null;
 761                             }
 762                         }
 763                     });
 764         }




 724         // In strict mode, eval does not instantiate variables and functions
 725         // in the caller's environment. A new environment is created!
 726         if (strictFlag) {
 727             // Create a new scope object with given scope as its prototype
 728             scope = newScope(scope);
 729         }
 730 
 731         final ScriptFunction func = getProgramFunction(clazz, scope);
 732         Object evalThis;
 733         if (directEval) {
 734             evalThis = (callThis != UNDEFINED && callThis != null) || strictFlag ? callThis : global;
 735         } else {
 736             // either indirect evalCall or non-eval (Function, engine.eval, ScriptObjectMirror.eval..)
 737             evalThis = callThis;
 738         }
 739 
 740         return ScriptRuntime.apply(func, evalThis);
 741     }
 742 
 743     private static ScriptObject newScope(final ScriptObject callerScope) {
 744         return new Scope(callerScope, PropertyMap.newMap(Scope.class));
 745     }
 746 
 747     private static Source loadInternal(final String srcStr, final String prefix, final String resourcePath) {
 748         if (srcStr.startsWith(prefix)) {
 749             final String resource = resourcePath + srcStr.substring(prefix.length());
 750             // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
 751             // These scripts are always available and are loaded from nashorn.jar's resources.
 752             return AccessController.doPrivileged(
 753                     new PrivilegedAction<Source>() {
 754                         @Override
 755                         public Source run() {
 756                             try {
 757                                 final URL resURL = Context.class.getResource(resource);
 758                                 return resURL != null ? sourceFor(srcStr, resURL) : null;
 759                             } catch (final IOException exp) {
 760                                 return null;
 761                             }
 762                         }
 763                     });
 764         }


< prev index next >