8006635: Reduce access levels as much as possible

Mon, 21 Jan 2013 21:17:38 +0530

author
sundar
date
Mon, 21 Jan 2013 21:17:38 +0530
changeset 41
8b3cc4ad1810
parent 40
0cee498b330d
child 42
935dcec38e9a

8006635: Reduce access levels as much as possible
Reviewed-by: jlaskey, lagergren, attila

src/jdk/nashorn/api/scripting/NashornScriptEngine.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/api/scripting/ScriptObjectMirror.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/codegen/Compiler.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/Symbol.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/debug/JSONWriter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeArray.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeDebug.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeJava.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Context.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/DebugLogger.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ECMAException.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/OptionsObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/StructureLoader.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/tools/Shell.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/BooleanAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/codegen/CompilerTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/parser/ParserTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/runtime/ContextTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/runtime/JSTypeTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Mon Jan 21 11:03:56 2013 +0100
     1.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Mon Jan 21 21:17:38 2013 +0530
     1.3 @@ -86,13 +86,22 @@
     1.4          options.process(args);
     1.5  
     1.6          // throw ParseException on first error from script
     1.7 -        final ErrorManager errors = new Context.ThrowErrorManager();
     1.8 +        final ErrorManager errMgr = new Context.ThrowErrorManager();
     1.9 +        // application loader for the context
    1.10 +        ClassLoader tmp;
    1.11 +        try {
    1.12 +            tmp = Thread.currentThread().getContextClassLoader();
    1.13 +        } catch (final SecurityException se) {
    1.14 +            tmp = null;
    1.15 +        }
    1.16 +        final ClassLoader appLoader = tmp;
    1.17 +
    1.18          // create new Nashorn Context
    1.19          this.nashornContext = AccessController.doPrivileged(new PrivilegedAction<Context>() {
    1.20              @Override
    1.21              public Context run() {
    1.22                  try {
    1.23 -                    return new Context(options, errors);
    1.24 +                    return new Context(options, errMgr, appLoader);
    1.25                  } catch (final RuntimeException e) {
    1.26                      if (Context.DEBUG) {
    1.27                          e.printStackTrace();
     2.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Mon Jan 21 11:03:56 2013 +0100
     2.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Mon Jan 21 21:17:38 2013 +0530
     2.3 @@ -25,6 +25,8 @@
     2.4  
     2.5  package jdk.nashorn.api.scripting;
     2.6  
     2.7 +import java.security.AccessController;
     2.8 +import java.security.PrivilegedAction;
     2.9  import java.util.AbstractMap;
    2.10  import java.util.ArrayList;
    2.11  import java.util.Collection;
    2.12 @@ -141,7 +143,14 @@
    2.13          return inGlobal(new Callable<Object>() {
    2.14              @Override
    2.15              public Object call() {
    2.16 -                return wrap(global.getContext().eval(global, s, null, null, false), global);
    2.17 +                final Context context = AccessController.doPrivileged(
    2.18 +                        new PrivilegedAction<Context>() {
    2.19 +                            @Override
    2.20 +                            public Context run() {
    2.21 +                                return Context.getContext();
    2.22 +                            }
    2.23 +                        });
    2.24 +                return wrap(context.eval(global, s, null, null, false), global);
    2.25              }
    2.26          });
    2.27      }
    2.28 @@ -178,7 +187,7 @@
    2.29      public void setSlot(final int index, final Object value) {
    2.30          inGlobal(new Callable<Void>() {
    2.31              @Override public Void call() {
    2.32 -                sobj.set(index, unwrap(value, global), global.getContext()._strict);
    2.33 +                sobj.set(index, unwrap(value, global), global.isStrictContext());
    2.34                  return null;
    2.35              }
    2.36          });
    2.37 @@ -275,7 +284,7 @@
    2.38  
    2.39      @Override
    2.40      public void putAll(final Map<? extends String, ? extends Object> map) {
    2.41 -        final boolean strict = sobj.getContext()._strict;
    2.42 +        final boolean strict = sobj.isStrictContext();
    2.43          inGlobal(new Callable<Object>() {
    2.44              @Override public Object call() {
    2.45                  for (final Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) {
     3.1 --- a/src/jdk/nashorn/internal/codegen/Compiler.java	Mon Jan 21 11:03:56 2013 +0100
     3.2 +++ b/src/jdk/nashorn/internal/codegen/Compiler.java	Mon Jan 21 21:17:38 2013 +0530
     3.3 @@ -186,7 +186,7 @@
     3.4       * @return compiler instance
     3.5       */
     3.6      public static Compiler compiler(final Source source, final Context context) {
     3.7 -        return Compiler.compiler(source, context, context.getErrors(), context._strict);
     3.8 +        return Compiler.compiler(source, context, context.getErrorManager(), context._strict);
     3.9      }
    3.10  
    3.11      /**
     4.1 --- a/src/jdk/nashorn/internal/ir/Symbol.java	Mon Jan 21 11:03:56 2013 +0100
     4.2 +++ b/src/jdk/nashorn/internal/ir/Symbol.java	Mon Jan 21 21:17:38 2013 +0530
     4.3 @@ -605,7 +605,7 @@
     4.4      private void trace(final String desc) {
     4.5          if (TRACE_SYMBOL != null && TRACE_SYMBOL.equals(name)) {
     4.6              Context.err("SYMBOL: '" + name + "' " + desc);
     4.7 -            new Throwable().printStackTrace(Context.getContext().getErr());
     4.8 +            new Throwable().printStackTrace(Context.getCurrentErr());
     4.9          }
    4.10      }
    4.11  }
     5.1 --- a/src/jdk/nashorn/internal/ir/debug/JSONWriter.java	Mon Jan 21 11:03:56 2013 +0100
     5.2 +++ b/src/jdk/nashorn/internal/ir/debug/JSONWriter.java	Mon Jan 21 21:17:38 2013 +0530
     5.3 @@ -25,6 +25,8 @@
     5.4  
     5.5  package jdk.nashorn.internal.ir.debug;
     5.6  
     5.7 +import java.security.AccessController;
     5.8 +import java.security.PrivilegedAction;
     5.9  import java.util.Arrays;
    5.10  import java.util.List;
    5.11  import jdk.nashorn.internal.codegen.Compiler;
    5.12 @@ -86,7 +88,13 @@
    5.13       */
    5.14      public static String parse(final String code, final String name, final boolean includeLoc) {
    5.15          final ScriptObject global     = Context.getGlobal();
    5.16 -        final Context      context    = global.getContext();
    5.17 +        final Context      context    = AccessController.doPrivileged(
    5.18 +                new PrivilegedAction<Context>() {
    5.19 +                    @Override
    5.20 +                    public Context run() {
    5.21 +                        return Context.getContext();
    5.22 +                    }
    5.23 +                });
    5.24          final Compiler     compiler   = Compiler.compiler(new Source(name, code), context, new Context.ThrowErrorManager(), context._strict);
    5.25          final Parser       parser     = new Parser(compiler, context._strict);
    5.26          final JSONWriter   jsonWriter = new JSONWriter(includeLoc);
     6.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Mon Jan 21 11:03:56 2013 +0100
     6.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Mon Jan 21 21:17:38 2013 +0530
     6.3 @@ -46,6 +46,7 @@
     6.4  import jdk.nashorn.internal.runtime.GlobalObject;
     6.5  import jdk.nashorn.internal.runtime.JSType;
     6.6  import jdk.nashorn.internal.runtime.NativeJavaPackage;
     6.7 +import jdk.nashorn.internal.runtime.OptionsObject;
     6.8  import jdk.nashorn.internal.runtime.PropertyDescriptor;
     6.9  import jdk.nashorn.internal.runtime.Scope;
    6.10  import jdk.nashorn.internal.runtime.ScriptFunction;
    6.11 @@ -365,7 +366,7 @@
    6.12       *
    6.13       * @return the context
    6.14       */
    6.15 -    public static Context getThisContext() {
    6.16 +    static Context getThisContext() {
    6.17          return instance().getContext();
    6.18      }
    6.19  
    6.20 @@ -374,7 +375,7 @@
    6.21       *
    6.22       * @return true if strict mode enabled in {@link Global#getThisContext()}
    6.23       */
    6.24 -    public static boolean isStrict() {
    6.25 +    static boolean isStrict() {
    6.26          return getThisContext()._strict;
    6.27      }
    6.28  
    6.29 @@ -387,13 +388,7 @@
    6.30              return;
    6.31          }
    6.32  
    6.33 -        final ScriptObject oldGlobal = Context.getGlobal();
    6.34 -        Context.setGlobal(this);
    6.35 -        try {
    6.36 -            init();
    6.37 -        } finally {
    6.38 -            Context.setGlobal(oldGlobal);
    6.39 -        }
    6.40 +        init();
    6.41      }
    6.42  
    6.43      @Override
    6.44 @@ -650,9 +645,10 @@
    6.45          if (!(str instanceof String || str instanceof ConsString)) {
    6.46              return str;
    6.47          }
    6.48 -        final ScriptObject scope = (self instanceof ScriptObject) ? (ScriptObject)self : Global.instance();
    6.49 +        final Global global = Global.instance();
    6.50 +        final ScriptObject scope = (self instanceof ScriptObject) ? (ScriptObject)self : global;
    6.51  
    6.52 -        return Global.getThisContext().eval(scope, str.toString(), callThis, location, Boolean.TRUE.equals(strict));
    6.53 +        return global.getContext().eval(scope, str.toString(), callThis, location, Boolean.TRUE.equals(strict));
    6.54      }
    6.55  
    6.56      /**
    6.57 @@ -690,8 +686,9 @@
    6.58       * @throws IOException if source could not be read
    6.59       */
    6.60      public static Object load(final Object self, final Object source) throws IOException {
    6.61 -        final ScriptObject scope = (self instanceof ScriptObject) ? (ScriptObject)self : Global.instance();
    6.62 -        return getThisContext().load(scope, source);
    6.63 +        final Global global = Global.instance();
    6.64 +        final ScriptObject scope = (self instanceof ScriptObject) ? (ScriptObject)self : global;
    6.65 +        return global.getContext().load(scope, source);
    6.66      }
    6.67  
    6.68      ScriptObject getFunctionPrototype() {
    6.69 @@ -1302,6 +1299,8 @@
    6.70      }
    6.71  
    6.72      private void init() {
    6.73 +        assert Context.getGlobal() == this : "this global is not set as current";
    6.74 +
    6.75          // initialize Function and Object constructor
    6.76          initFunctionAndObject();
    6.77  
    6.78 @@ -1367,7 +1366,7 @@
    6.79              initScripting();
    6.80          }
    6.81  
    6.82 -        if (Context.DEBUG) {
    6.83 +        if (Context.DEBUG && System.getSecurityManager() == null) {
    6.84              initDebug();
    6.85          }
    6.86  
    6.87 @@ -1460,8 +1459,7 @@
    6.88          addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
    6.89  
    6.90          // Nashorn extension: global.$OPTIONS (scripting-mode-only)
    6.91 -        // expose current Context to access command line options
    6.92 -        value = this.getContext();
    6.93 +        value = new OptionsObject(this.getContext());
    6.94          addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, value);
    6.95      }
    6.96  
     7.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java	Mon Jan 21 11:03:56 2013 +0100
     7.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java	Mon Jan 21 21:17:38 2013 +0530
     7.3 @@ -603,7 +603,7 @@
     7.4      public static Object pop(final Object self) {
     7.5          try {
     7.6              final ScriptObject sobj = (ScriptObject)self;
     7.7 -            final boolean strict    = sobj.getContext()._strict;
     7.8 +            final boolean strict    = sobj.isStrictContext();
     7.9  
    7.10              if (bulkable(sobj)) {
    7.11                  return ((NativeArray)sobj).getArray().pop();
    7.12 @@ -640,7 +640,7 @@
    7.13      public static Object push(final Object self, final Object... args) {
    7.14          try {
    7.15              final ScriptObject sobj   = (ScriptObject)self;
    7.16 -            final boolean      strict = sobj.getContext()._strict;
    7.17 +            final boolean      strict = sobj.isStrictContext();
    7.18  
    7.19              if (bulkable(sobj)) {
    7.20                  final NativeArray nativeArray = (NativeArray)sobj;
    7.21 @@ -675,7 +675,7 @@
    7.22      public static Object reverse(final Object self) {
    7.23          try {
    7.24              final ScriptObject sobj   = (ScriptObject)self;
    7.25 -            final boolean      strict = sobj.getContext()._strict;
    7.26 +            final boolean      strict = sobj.isStrictContext();
    7.27              final long         len    = JSType.toUint32(sobj.getLength());
    7.28              final long         middle = len / 2;
    7.29  
    7.30 @@ -846,8 +846,7 @@
    7.31      public static Object sort(final Object self, final Object comparefn) {
    7.32          try {
    7.33              final ScriptObject sobj    = (ScriptObject) self;
    7.34 -            final Context      context = sobj.getContext();
    7.35 -            final boolean      strict  = context._strict;
    7.36 +            final boolean      strict  = sobj.isStrictContext();
    7.37              final long         len     = JSType.toUint32(sobj.getLength());
    7.38  
    7.39              if (len > 1) {
    7.40 @@ -994,7 +993,7 @@
    7.41              nativeArray.getArray().shiftRight(items.length);
    7.42  
    7.43              for (int j = 0; j < items.length; j++) {
    7.44 -                nativeArray.setArray(nativeArray.getArray().set(j, items[j], sobj.getContext()._strict));
    7.45 +                nativeArray.setArray(nativeArray.getArray().set(j, items[j], sobj.isStrictContext()));
    7.46              }
    7.47          } else {
    7.48              for (long k = len; k > 0; k--) {
     8.1 --- a/src/jdk/nashorn/internal/objects/NativeDebug.java	Mon Jan 21 11:03:56 2013 +0100
     8.2 +++ b/src/jdk/nashorn/internal/objects/NativeDebug.java	Mon Jan 21 21:17:38 2013 +0530
     8.3 @@ -252,7 +252,7 @@
     8.4      @SuppressWarnings("resource")
     8.5      @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
     8.6      public static Object dumpCounters(final Object self) {
     8.7 -        final PrintWriter out = Context.getContext().getErr();
     8.8 +        final PrintWriter out = Context.getCurrentErr();
     8.9  
    8.10          out.println("ScriptObject count " + ScriptObject.getCount());
    8.11          out.println("Scope count " + ScriptObject.getScopeCount());
     9.1 --- a/src/jdk/nashorn/internal/objects/NativeJava.java	Mon Jan 21 11:03:56 2013 +0100
     9.2 +++ b/src/jdk/nashorn/internal/objects/NativeJava.java	Mon Jan 21 21:17:38 2013 +0530
     9.3 @@ -334,7 +334,7 @@
     9.4  
     9.5      private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
     9.6          final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
     9.7 -        return primClass != null ? primClass : Global.instance().getContext().findClass(typeName);
     9.8 +        return primClass != null ? primClass : Global.getThisContext().findClass(typeName);
     9.9      }
    9.10  
    9.11      private static Class<?> arrayType(final String typeName) throws ClassNotFoundException {
    10.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Mon Jan 21 11:03:56 2013 +0100
    10.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Mon Jan 21 21:17:38 2013 +0530
    10.3 @@ -72,12 +72,6 @@
    10.4          };
    10.5  
    10.6      /**
    10.7 -     * Get the error stream if applicable and initialized, otherwise stderr
    10.8 -     * Usually this is the error stream given the context, but for testing and
    10.9 -     * certain bootstrapping situations we need a default stream
   10.10 -     */
   10.11 -
   10.12 -    /**
   10.13       * Return the current global scope
   10.14       * @return current global scope
   10.15       */
   10.16 @@ -107,7 +101,21 @@
   10.17       * @return current global scope's context.
   10.18       */
   10.19      public static Context getContext() {
   10.20 -        return Context.getGlobal().getContext();
   10.21 +        final SecurityManager sm = System.getSecurityManager();
   10.22 +        if (sm != null) {
   10.23 +            sm.checkPermission(new RuntimePermission("getNashornContext"));
   10.24 +        }
   10.25 +        return getContextTrusted();
   10.26 +    }
   10.27 +
   10.28 +    /**
   10.29 +     * Get current context's error writer
   10.30 +     *
   10.31 +     * @return error writer of the current context
   10.32 +     */
   10.33 +    public static PrintWriter getCurrentErr() {
   10.34 +        final ScriptObject global = getGlobal();
   10.35 +        return (global != null)? global.getContext().getErr() : new PrintWriter(System.err);
   10.36      }
   10.37  
   10.38      /**
   10.39 @@ -127,7 +135,7 @@
   10.40       */
   10.41      @SuppressWarnings("resource")
   10.42      public static void err(final String str, final boolean crlf) {
   10.43 -        final PrintWriter err = Context.getContext().getErr();
   10.44 +        final PrintWriter err = Context.getCurrentErr();
   10.45          if (err != null) {
   10.46              if (crlf) {
   10.47                  err.println(str);
   10.48 @@ -137,6 +145,9 @@
   10.49          }
   10.50      }
   10.51  
   10.52 +    /** class loader to resolve classes from script. */
   10.53 +    private final ClassLoader  appLoader;
   10.54 +
   10.55      /** Class loader to load classes from -classpath option, if set. */
   10.56      private final ClassLoader  classPathLoader;
   10.57  
   10.58 @@ -242,13 +253,14 @@
   10.59      /** time zone for this context */
   10.60      public final TimeZone _timezone;
   10.61  
   10.62 +    private static final ClassLoader myLoader = Context.class.getClassLoader();
   10.63      private static final StructureLoader sharedLoader;
   10.64  
   10.65      static {
   10.66          sharedLoader = AccessController.doPrivileged(new PrivilegedAction<StructureLoader>() {
   10.67              @Override
   10.68              public StructureLoader run() {
   10.69 -                return new StructureLoader(Context.class.getClassLoader(), null);
   10.70 +                return new StructureLoader(myLoader, null);
   10.71              }
   10.72          });
   10.73      }
   10.74 @@ -273,9 +285,10 @@
   10.75       *
   10.76       * @param options options from command line or Context creator
   10.77       * @param errors  error manger
   10.78 +     * @param appLoader application class loader
   10.79       */
   10.80 -    public Context(final Options options, final ErrorManager errors) {
   10.81 -        this(options, errors, new PrintWriter(System.out, true), new PrintWriter(System.err, true));
   10.82 +    public Context(final Options options, final ErrorManager errors, final ClassLoader appLoader) {
   10.83 +        this(options, errors, new PrintWriter(System.out, true), new PrintWriter(System.err, true), appLoader);
   10.84      }
   10.85  
   10.86      /**
   10.87 @@ -285,13 +298,15 @@
   10.88       * @param errors  error manger
   10.89       * @param out     output writer for this Context
   10.90       * @param err     error writer for this Context
   10.91 +     * @param appLoader application class loader
   10.92       */
   10.93 -    public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err) {
   10.94 +    public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader) {
   10.95          final SecurityManager sm = System.getSecurityManager();
   10.96          if (sm != null) {
   10.97              sm.checkPermission(new RuntimePermission("createNashornContext"));
   10.98          }
   10.99  
  10.100 +        this.appLoader = appLoader;
  10.101          this.scriptLoader = (ScriptLoader)AccessController.doPrivileged(
  10.102               new PrivilegedAction<ClassLoader>() {
  10.103                  @Override
  10.104 @@ -389,7 +404,7 @@
  10.105       * Get the error manager for this context
  10.106       * @return error manger
  10.107       */
  10.108 -    public ErrorManager getErrors() {
  10.109 +    public ErrorManager getErrorManager() {
  10.110          return errors;
  10.111      }
  10.112  
  10.113 @@ -652,28 +667,17 @@
  10.114              }
  10.115          }
  10.116  
  10.117 -        // try script loader first
  10.118 -        try {
  10.119 -            return Class.forName(fullName, true, scriptLoader);
  10.120 -        } catch (final ClassNotFoundException e) {
  10.121 -            // ignored, continue search
  10.122 -        }
  10.123 -
  10.124 -        // try script -classpath loader, if set
  10.125 +        // try the script -classpath loader, if that is set
  10.126          if (classPathLoader != null) {
  10.127              try {
  10.128                  return Class.forName(fullName, true, classPathLoader);
  10.129 -            } catch (final ClassNotFoundException e) {
  10.130 +            } catch (final ClassNotFoundException ignored) {
  10.131                  // ignore, continue search
  10.132              }
  10.133          }
  10.134  
  10.135 -        // This helps in finding using "app" loader - which is typically set as thread context loader
  10.136 -        try {
  10.137 -            return Class.forName(fullName, true, Thread.currentThread().getContextClassLoader());
  10.138 -        } catch (final ClassNotFoundException e) {
  10.139 -            throw e;
  10.140 -        }
  10.141 +        // Try finding using the "app" loader.
  10.142 +        return Class.forName(fullName, true, appLoader);
  10.143      }
  10.144  
  10.145      /**
  10.146 @@ -684,7 +688,7 @@
  10.147       */
  10.148      public static void printStackTrace(final Throwable t) {
  10.149          if (Context.DEBUG) {
  10.150 -            t.printStackTrace(Context.getContext().getErr());
  10.151 +            t.printStackTrace(Context.getCurrentErr());
  10.152          }
  10.153      }
  10.154  
  10.155 @@ -714,18 +718,35 @@
  10.156       * @return the global script object
  10.157       */
  10.158      public ScriptObject createGlobal() {
  10.159 +        final SecurityManager sm = System.getSecurityManager();
  10.160 +        if (sm != null) {
  10.161 +            sm.checkPermission(new RuntimePermission("createNashornGlobal"));
  10.162 +        }
  10.163 +
  10.164          final ScriptObject global = newGlobal();
  10.165 -
  10.166          // Need only minimal global object, if we are just compiling.
  10.167          if (!_compile_only) {
  10.168 -            // initialize global scope with builtin global objects
  10.169 -            ((GlobalObject)global).initBuiltinObjects();
  10.170 +            final ScriptObject oldGlobal = Context.getGlobal();
  10.171 +            try {
  10.172 +                Context.setGlobal(global);
  10.173 +                // initialize global scope with builtin global objects
  10.174 +                ((GlobalObject)global).initBuiltinObjects();
  10.175 +            } finally {
  10.176 +                Context.setGlobal(oldGlobal);
  10.177 +            }
  10.178          }
  10.179  
  10.180          return global;
  10.181      }
  10.182  
  10.183      /**
  10.184 +     * Trusted variant package-private
  10.185 +     */
  10.186 +    static Context getContextTrusted() {
  10.187 +        return Context.getGlobal().getContext();
  10.188 +    }
  10.189 +
  10.190 +    /**
  10.191       * Try to infer Context instance from the Class. If we cannot,
  10.192       * then get it from the thread local variable.
  10.193       *
  10.194 @@ -740,7 +761,7 @@
  10.195              context = ((NashornLoader)loader).getContext();
  10.196          }
  10.197  
  10.198 -        return (context != null) ? context : Context.getContext();
  10.199 +        return (context != null) ? context : Context.getContextTrusted();
  10.200      }
  10.201  
  10.202      private Object evaluateSource(final String name, final URL url, final ScriptObject scope, final ScriptObject thiz) throws IOException {
    11.1 --- a/src/jdk/nashorn/internal/runtime/DebugLogger.java	Mon Jan 21 11:03:56 2013 +0100
    11.2 +++ b/src/jdk/nashorn/internal/runtime/DebugLogger.java	Mon Jan 21 21:17:38 2013 +0530
    11.3 @@ -74,7 +74,7 @@
    11.4       * @return print writer for log output.
    11.5       */
    11.6      public PrintWriter getOutputStream() {
    11.7 -        return Context.getContext().getErr();
    11.8 +        return Context.getCurrentErr();
    11.9      }
   11.10  
   11.11      /**
    12.1 --- a/src/jdk/nashorn/internal/runtime/ECMAException.java	Mon Jan 21 11:03:56 2013 +0100
    12.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAException.java	Mon Jan 21 21:17:38 2013 +0530
    12.3 @@ -182,7 +182,7 @@
    12.4      public static Object printStackTrace(final ScriptObject errObj) {
    12.5          final Object exception = getException(errObj);
    12.6          if (exception instanceof Throwable) {
    12.7 -            ((Throwable)exception).printStackTrace(Context.getContext().getErr());
    12.8 +            ((Throwable)exception).printStackTrace(Context.getCurrentErr());
    12.9          } else {
   12.10              Context.err("<stack trace not available>");
   12.11          }
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/jdk/nashorn/internal/runtime/OptionsObject.java	Mon Jan 21 21:17:38 2013 +0530
    13.3 @@ -0,0 +1,136 @@
    13.4 +/*
    13.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + *
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.  Oracle designates this
   13.11 + * particular file as subject to the "Classpath" exception as provided
   13.12 + * by Oracle in the LICENSE file that accompanied this code.
   13.13 + *
   13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.17 + * version 2 for more details (a copy is included in the LICENSE file that
   13.18 + * accompanied this code).
   13.19 + *
   13.20 + * You should have received a copy of the GNU General Public License version
   13.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.23 + *
   13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.25 + * or visit www.oracle.com if you need additional information or have any
   13.26 + * questions.
   13.27 + */
   13.28 +
   13.29 +package jdk.nashorn.internal.runtime;
   13.30 +
   13.31 +import java.util.TimeZone;
   13.32 +
   13.33 +/**
   13.34 + * A convenience object to expose only command line options from a Context.
   13.35 + */
   13.36 +public final class OptionsObject {
   13.37 +    /** Always allow functions as statements */
   13.38 +    public final boolean _anon_functions;
   13.39 +
   13.40 +    /** Size of the per-global Class cache size */
   13.41 +    public final int     _class_cache_size;
   13.42 +
   13.43 +    /** Only compile script, do not run it or generate other ScriptObjects */
   13.44 +    public final boolean _compile_only;
   13.45 +
   13.46 +    /** Accumulated callsite flags that will be used when boostrapping script callsites */
   13.47 +    public final int     _callsite_flags;
   13.48 +
   13.49 +    /** Genereate line number table in class files */
   13.50 +    public final boolean _debug_lines;
   13.51 +
   13.52 +    /** Package to which generated class files are added */
   13.53 +    public final String  _dest_dir;
   13.54 +
   13.55 +    /** Display stack trace upon error, default is false */
   13.56 +    public final boolean _dump_on_error;
   13.57 +
   13.58 +    /** Invalid lvalue expressions should be reported as early errors */
   13.59 +    public final boolean _early_lvalue_error;
   13.60 +
   13.61 +    /** Empty statements should be preserved in the AST */
   13.62 +    public final boolean _empty_statements;
   13.63 +
   13.64 +    /** Show full Nashorn version */
   13.65 +    public final boolean _fullversion;
   13.66 +
   13.67 +    /** Create a new class loaded for each compilation */
   13.68 +    public final boolean _loader_per_compile;
   13.69 +
   13.70 +    /** Package to which generated class files are added */
   13.71 +    public final String  _package;
   13.72 +
   13.73 +    /** Only parse the source code, do not compile */
   13.74 +    public final boolean _parse_only;
   13.75 +
   13.76 +    /** Print the AST before lowering */
   13.77 +    public final boolean _print_ast;
   13.78 +
   13.79 +    /** Print the AST after lowering */
   13.80 +    public final boolean _print_lower_ast;
   13.81 +
   13.82 +    /** Print resulting bytecode for script */
   13.83 +    public final boolean _print_code;
   13.84 +
   13.85 +    /** Print function will no print newline characters */
   13.86 +    public final boolean _print_no_newline;
   13.87 +
   13.88 +    /** Print AST in more human readable form */
   13.89 +    public final boolean _print_parse;
   13.90 +
   13.91 +    /** Print AST in more human readable form after Lowering */
   13.92 +    public final boolean _print_lower_parse;
   13.93 +
   13.94 +    /** print symbols and their contents for the script */
   13.95 +    public final boolean _print_symbols;
   13.96 +
   13.97 +    /** is this context in scripting mode? */
   13.98 +    public final boolean _scripting;
   13.99 +
  13.100 +    /** is this context in strict mode? */
  13.101 +    public final boolean _strict;
  13.102 +
  13.103 +    /** print version info of Nashorn */
  13.104 +    public final boolean _version;
  13.105 +
  13.106 +    /** should code verification be done of generated bytecode */
  13.107 +    public final boolean _verify_code;
  13.108 +
  13.109 +    /** time zone for this context */
  13.110 +    public final TimeZone _timezone;
  13.111 +
  13.112 +    public OptionsObject(final Context context) {
  13.113 +        this._anon_functions = context._anon_functions;
  13.114 +        this._callsite_flags = context._callsite_flags;
  13.115 +        this._class_cache_size = context._class_cache_size;
  13.116 +        this._compile_only = context._compile_only;
  13.117 +        this._debug_lines = context._debug_lines;
  13.118 +        this._dest_dir = context._dest_dir;
  13.119 +        this._dump_on_error = context._dump_on_error;
  13.120 +        this._early_lvalue_error = context._early_lvalue_error;
  13.121 +        this._empty_statements = context._empty_statements;
  13.122 +        this._fullversion = context._fullversion;
  13.123 +        this._loader_per_compile = context._loader_per_compile;
  13.124 +        this._package = context._package;
  13.125 +        this._parse_only = context._parse_only;
  13.126 +        this._print_ast = context._print_ast;
  13.127 +        this._print_code = context._print_code;
  13.128 +        this._print_lower_ast = context._print_lower_ast;
  13.129 +        this._print_lower_parse = context._print_lower_parse;
  13.130 +        this._print_no_newline = context._print_no_newline;
  13.131 +        this._print_parse = context._print_parse;
  13.132 +        this._print_symbols = context._print_symbols;
  13.133 +        this._scripting = context._scripting;
  13.134 +        this._strict = context._strict;
  13.135 +        this._timezone = context._timezone;
  13.136 +        this._verify_code = context._verify_code;
  13.137 +        this._version = context._version;
  13.138 +    }
  13.139 +}
    14.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Mon Jan 21 11:03:56 2013 +0100
    14.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Mon Jan 21 21:17:38 2013 +0530
    14.3 @@ -1043,11 +1043,15 @@
    14.4          set(key, value, getContext()._strict);
    14.5      }
    14.6  
    14.7 +    public final boolean isStrictContext() {
    14.8 +        return getContext()._strict;
    14.9 +    }
   14.10 +
   14.11      /**
   14.12       * Return the current context from the object's map.
   14.13       * @return Current context.
   14.14       */
   14.15 -    public final Context getContext() {
   14.16 +    protected final Context getContext() {
   14.17          return getMap().getContext();
   14.18      }
   14.19  
    15.1 --- a/src/jdk/nashorn/internal/runtime/StructureLoader.java	Mon Jan 21 11:03:56 2013 +0100
    15.2 +++ b/src/jdk/nashorn/internal/runtime/StructureLoader.java	Mon Jan 21 21:17:38 2013 +0530
    15.3 @@ -129,7 +129,7 @@
    15.4          Context context = getContext();
    15.5  
    15.6          if (context == null) {
    15.7 -            context = Context.getContext();
    15.8 +            context = Context.getContextTrusted();
    15.9          }
   15.10  
   15.11          final byte[] code = new ObjectClassGenerator(context).generate(descriptor);
    16.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java	Mon Jan 21 11:03:56 2013 +0100
    16.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java	Mon Jan 21 21:17:38 2013 +0530
    16.3 @@ -25,6 +25,7 @@
    16.4  
    16.5  package jdk.nashorn.internal.runtime.arrays;
    16.6  
    16.7 +import jdk.nashorn.internal.runtime.Context;
    16.8  import jdk.nashorn.internal.runtime.ScriptObject;
    16.9  
   16.10  /**
   16.11 @@ -83,6 +84,6 @@
   16.12  
   16.13      @Override
   16.14      public void remove() {
   16.15 -        array.delete(index, array.getContext()._strict);
   16.16 +        array.delete(index, array.isStrictContext());
   16.17      }
   16.18  }
    17.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Mon Jan 21 11:03:56 2013 +0100
    17.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Mon Jan 21 21:17:38 2013 +0530
    17.3 @@ -136,7 +136,7 @@
    17.4   * </p>
    17.5   */
    17.6  
    17.7 -public class JavaAdapterFactory {
    17.8 +public final class JavaAdapterFactory {
    17.9      private static final Type SCRIPT_FUNCTION_TYPE = Type.getType(ScriptFunction.class);
   17.10      private static final Type SCRIPT_OBJECT_TYPE = Type.getType(ScriptObject.class);
   17.11      private static final Type OBJECT_TYPE = Type.getType(Object.class);
   17.12 @@ -470,7 +470,7 @@
   17.13          // private final ScriptObject global;
   17.14          w.visitField(ACC_PRIVATE | ACC_FINAL, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR, null, null).visitEnd();
   17.15  
   17.16 -        // private ContextSetter(ScriptObject global) {
   17.17 +        // private GlobalSetter(ScriptObject global) {
   17.18          InstructionAdapter mv = new InstructionAdapter(w.visitMethod(ACC_PRIVATE, INIT,
   17.19                  SET_GLOBAL_METHOD_DESCRIPTOR, null, new String[0]));
   17.20          mv.visitCode();
    18.1 --- a/src/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java	Mon Jan 21 11:03:56 2013 +0100
    18.2 +++ b/src/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java	Mon Jan 21 21:17:38 2013 +0530
    18.3 @@ -285,7 +285,7 @@
    18.4                          out = new PrintWriter(new FileOutputStream(PROFILEFILE));
    18.5                          fileOutput = true;
    18.6                      } catch (final FileNotFoundException e) {
    18.7 -                        out = Context.getContext().getErr();
    18.8 +                        out = Context.getCurrentErr();
    18.9                      }
   18.10  
   18.11                      dump(out);
   18.12 @@ -317,8 +317,6 @@
   18.13          private static final MethodHandle TRACEVOID   = findOwnMH("traceVoid", void.class, MethodHandle.class, Object[].class);
   18.14          private static final MethodHandle TRACEMISS   = findOwnMH("traceMiss", void.class, Object[].class);
   18.15  
   18.16 -        private static final PrintWriter out = Context.getContext().getErr();
   18.17 -
   18.18          TracingLinkerCallSite(final NashornCallSiteDescriptor desc) {
   18.19             super(desc);
   18.20          }
   18.21 @@ -366,7 +364,7 @@
   18.22              return MH.foldArguments(relink, MH.asType(MH.asCollector(MH.bindTo(TRACEMISS, this), Object[].class, type.parameterCount()), type.changeReturnType(void.class)));
   18.23          }
   18.24  
   18.25 -        private void printObject(final Object arg) {
   18.26 +        private void printObject(final PrintWriter out, final Object arg) {
   18.27              if (!getNashornDescriptor().isTraceObjects()) {
   18.28                  out.print((arg instanceof ScriptObject) ? "ScriptObject" : arg);
   18.29                  return;
   18.30 @@ -396,7 +394,7 @@
   18.31                          if (value instanceof ScriptObject) {
   18.32                              out.print("...");
   18.33                          } else {
   18.34 -                            printObject(value);
   18.35 +                            printObject(out, value);
   18.36                          }
   18.37  
   18.38                          isFirst = false;
   18.39 @@ -409,19 +407,19 @@
   18.40              }
   18.41          }
   18.42  
   18.43 -        private void tracePrint(final String tag, final Object[] args, final Object result) {
   18.44 +        private void tracePrint(final PrintWriter out, final String tag, final Object[] args, final Object result) {
   18.45              //boolean isVoid = type().returnType() == void.class;
   18.46              out.print(Debug.id(this) + " TAG " + tag);
   18.47              out.print(getDescriptor().getName() + "(");
   18.48  
   18.49              if (args.length > 0) {
   18.50 -                printObject(args[0]);
   18.51 +                printObject(out, args[0]);
   18.52                  for (int i = 1; i < args.length; i++) {
   18.53                      final Object arg = args[i];
   18.54                      out.print(", ");
   18.55  
   18.56                      if (getNashornDescriptor().isTraceScope() || !(arg instanceof ScriptObject && ((ScriptObject)arg).isScope())) {
   18.57 -                        printObject(arg);
   18.58 +                        printObject(out, arg);
   18.59                      } else {
   18.60                          out.print("SCOPE");
   18.61                      }
   18.62 @@ -432,7 +430,7 @@
   18.63  
   18.64              if (tag.equals("EXIT  ")) {
   18.65                  out.print(" --> ");
   18.66 -                printObject(result);
   18.67 +                printObject(out, result);
   18.68              }
   18.69  
   18.70              out.println();
   18.71 @@ -450,9 +448,10 @@
   18.72           */
   18.73          @SuppressWarnings("unused")
   18.74          public Object traceObject(final MethodHandle mh, final Object... args) throws Throwable {
   18.75 -            tracePrint("ENTER ", args, null);
   18.76 +            final PrintWriter out = Context.getCurrentErr();
   18.77 +            tracePrint(out, "ENTER ", args, null);
   18.78              final Object result = mh.invokeWithArguments(args);
   18.79 -            tracePrint("EXIT  ", args, result);
   18.80 +            tracePrint(out, "EXIT  ", args, result);
   18.81  
   18.82              return result;
   18.83          }
   18.84 @@ -467,9 +466,10 @@
   18.85           */
   18.86          @SuppressWarnings("unused")
   18.87          public void traceVoid(final MethodHandle mh, final Object... args) throws Throwable {
   18.88 -            tracePrint("ENTER ", args, null);
   18.89 +            final PrintWriter out = Context.getCurrentErr();
   18.90 +            tracePrint(out, "ENTER ", args, null);
   18.91              mh.invokeWithArguments(args);
   18.92 -            tracePrint("EXIT  ", args, null);
   18.93 +            tracePrint(out, "EXIT  ", args, null);
   18.94          }
   18.95  
   18.96          /**
   18.97 @@ -481,7 +481,7 @@
   18.98           */
   18.99          @SuppressWarnings("unused")
  18.100          public void traceMiss(final Object... args) throws Throwable {
  18.101 -            tracePrint("MISS ", args, null);
  18.102 +            tracePrint(Context.getCurrentErr(), "MISS ", args, null);
  18.103          }
  18.104  
  18.105          private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
    19.1 --- a/src/jdk/nashorn/tools/Shell.java	Mon Jan 21 11:03:56 2013 +0100
    19.2 +++ b/src/jdk/nashorn/tools/Shell.java	Mon Jan 21 21:17:38 2013 +0530
    19.3 @@ -148,7 +148,7 @@
    19.4       *
    19.5       * @throws IOException if there's a problem setting up the streams
    19.6       */
    19.7 -    protected int run(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) throws IOException {
    19.8 +    protected final int run(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) throws IOException {
    19.9          final Context context = makeContext(in, out, err, args);
   19.10          if (context == null) {
   19.11              return COMMANDLINE_ERROR;
   19.12 @@ -157,14 +157,14 @@
   19.13          final ScriptObject global = context.createGlobal();
   19.14          final List<String> files = context.getOptions().getFiles();
   19.15          if (files.isEmpty()) {
   19.16 -            return readEvalPrint(global);
   19.17 +            return readEvalPrint(context, global);
   19.18          }
   19.19  
   19.20          if (context._compile_only) {
   19.21 -            return compileScripts(global, files);
   19.22 +            return compileScripts(context, global, files);
   19.23          }
   19.24  
   19.25 -        return runScripts(global, files);
   19.26 +        return runScripts(context, global, files);
   19.27      }
   19.28  
   19.29      /**
   19.30 @@ -178,7 +178,7 @@
   19.31       * @return null if there are problems with option parsing.
   19.32       */
   19.33      @SuppressWarnings("resource")
   19.34 -    protected Context makeContext(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) {
   19.35 +    private Context makeContext(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) {
   19.36          final PrintStream pout = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out);
   19.37          final PrintStream perr = err instanceof PrintStream ? (PrintStream) err : new PrintStream(err);
   19.38          final PrintWriter wout = new PrintWriter(pout, true);
   19.39 @@ -217,27 +217,27 @@
   19.40              }
   19.41          }
   19.42  
   19.43 -        return new Context(options, errors, wout, werr);
   19.44 +        return new Context(options, errors, wout, werr, Thread.currentThread().getContextClassLoader());
   19.45      }
   19.46  
   19.47      /**
   19.48       * Compiles the given script files in the command line
   19.49       *
   19.50 +     * @param context the nashorn context
   19.51       * @param global the global scope
   19.52       * @param files the list of script files to compile
   19.53       *
   19.54       * @return error code
   19.55       * @throws IOException when any script file read results in I/O error
   19.56       */
   19.57 -    protected int compileScripts(final ScriptObject global, final List<String> files) throws IOException {
   19.58 -        final Context context = global.getContext();
   19.59 +    private int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
   19.60          final ScriptObject oldGlobal = Context.getGlobal();
   19.61          final boolean globalChanged = (oldGlobal != global);
   19.62          try {
   19.63              if (globalChanged) {
   19.64                  Context.setGlobal(global);
   19.65              }
   19.66 -            final ErrorManager errors = context.getErrors();
   19.67 +            final ErrorManager errors = context.getErrorManager();
   19.68  
   19.69              // For each file on the command line.
   19.70              for (final String fileName : files) {
   19.71 @@ -263,21 +263,21 @@
   19.72      /**
   19.73       * Runs the given JavaScript files in the command line
   19.74       *
   19.75 +     * @param context the nashorn context
   19.76       * @param global the global scope
   19.77       * @param files the list of script files to run
   19.78       *
   19.79       * @return error code
   19.80       * @throws IOException when any script file read results in I/O error
   19.81       */
   19.82 -    protected int runScripts(final ScriptObject global, final List<String> files) throws IOException {
   19.83 -        final Context context = global.getContext();
   19.84 +    private int runScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
   19.85          final ScriptObject oldGlobal = Context.getGlobal();
   19.86          final boolean globalChanged = (oldGlobal != global);
   19.87          try {
   19.88              if (globalChanged) {
   19.89                  Context.setGlobal(global);
   19.90              }
   19.91 -            final ErrorManager errors = context.getErrors();
   19.92 +            final ErrorManager errors = context.getErrorManager();
   19.93  
   19.94              // For each file on the command line.
   19.95              for (final String fileName : files) {
   19.96 @@ -325,12 +325,12 @@
   19.97      /**
   19.98       * read-eval-print loop for Nashorn shell.
   19.99       *
  19.100 +     * @param context the nashorn context
  19.101       * @param global  global scope object to use
  19.102       * @return return code
  19.103       */
  19.104      @SuppressWarnings("resource")
  19.105 -    protected int readEvalPrint(final ScriptObject global) {
  19.106 -        final Context context = global.getContext();
  19.107 +    private int readEvalPrint(final Context context, final ScriptObject global) {
  19.108          final String prompt = bundle.getString("shell.prompt");
  19.109          final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  19.110          final PrintWriter err = context.getErr();
    20.1 --- a/test/src/jdk/nashorn/internal/access/BooleanAccessTest.java	Mon Jan 21 11:03:56 2013 +0100
    20.2 +++ b/test/src/jdk/nashorn/internal/access/BooleanAccessTest.java	Mon Jan 21 21:17:38 2013 +0530
    20.3 @@ -25,8 +25,8 @@
    20.4  
    20.5  package jdk.nashorn.internal.access;
    20.6  
    20.7 -import static org.testng.Assert.assertEquals;
    20.8 -import static org.testng.Assert.assertTrue;
    20.9 +import static org.testng.AssertJUnit.assertEquals;
   20.10 +import static org.testng.AssertJUnit.assertTrue;
   20.11  
   20.12  import java.util.Arrays;
   20.13  import javax.script.ScriptEngine;
    21.1 --- a/test/src/jdk/nashorn/internal/codegen/CompilerTest.java	Mon Jan 21 11:03:56 2013 +0100
    21.2 +++ b/test/src/jdk/nashorn/internal/codegen/CompilerTest.java	Mon Jan 21 21:17:38 2013 +0530
    21.3 @@ -74,7 +74,7 @@
    21.4  
    21.5          final StringWriter sw = new StringWriter();
    21.6          final PrintWriter pw = new PrintWriter(sw);
    21.7 -        this.context = new Context(options, errors, pw, pw);
    21.8 +        this.context = new Context(options, errors, pw, pw, Thread.currentThread().getContextClassLoader());
    21.9          this.global = context.createGlobal();
   21.10      }
   21.11  
   21.12 @@ -160,7 +160,7 @@
   21.13              }
   21.14              final Source source = new Source(file.getAbsolutePath(), buffer);
   21.15              final ScriptFunction script = context.compileScript(source, global, context._strict);
   21.16 -            if (script == null || context.getErrors().getNumberOfErrors() > 0) {
   21.17 +            if (script == null || context.getErrorManager().getNumberOfErrors() > 0) {
   21.18                  log("Compile failed: " + file.getAbsolutePath());
   21.19                  failed++;
   21.20              } else {
    22.1 --- a/test/src/jdk/nashorn/internal/parser/ParserTest.java	Mon Jan 21 11:03:56 2013 +0100
    22.2 +++ b/test/src/jdk/nashorn/internal/parser/ParserTest.java	Mon Jan 21 21:17:38 2013 +0530
    22.3 @@ -65,7 +65,7 @@
    22.4          options.set("scripting", true);
    22.5  
    22.6          ErrorManager errors = new ErrorManager();
    22.7 -        this.context = new Context(options, errors);
    22.8 +        this.context = new Context(options, errors, Thread.currentThread().getContextClassLoader());
    22.9          this.global = context.createGlobal();
   22.10      }
   22.11  
    23.1 --- a/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Mon Jan 21 11:03:56 2013 +0100
    23.2 +++ b/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Mon Jan 21 21:17:38 2013 +0530
    23.3 @@ -41,7 +41,7 @@
    23.4      public void evalTest() {
    23.5          final Options options = new Options("");
    23.6          final ErrorManager errors = new ErrorManager();
    23.7 -        final Context cx = new Context(options, errors);
    23.8 +        final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
    23.9          final ScriptObject oldGlobal = Context.getGlobal();
   23.10          Context.setGlobal(cx.createGlobal());
   23.11          try {
   23.12 @@ -60,7 +60,7 @@
   23.13      public void reflectionTest() {
   23.14          final Options options = new Options("");
   23.15          final ErrorManager errors = new ErrorManager();
   23.16 -        final Context cx = new Context(options, errors);
   23.17 +        final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
   23.18          final ScriptObject oldGlobal = Context.getGlobal();
   23.19          Context.setGlobal(cx.createGlobal());
   23.20  
    24.1 --- a/test/src/jdk/nashorn/internal/runtime/JSTypeTest.java	Mon Jan 21 11:03:56 2013 +0100
    24.2 +++ b/test/src/jdk/nashorn/internal/runtime/JSTypeTest.java	Mon Jan 21 21:17:38 2013 +0530
    24.3 @@ -27,6 +27,7 @@
    24.4  
    24.5  import static org.testng.Assert.assertEquals;
    24.6  import static org.testng.Assert.assertTrue;
    24.7 +import static org.testng.Assert.assertFalse;
    24.8  
    24.9  import org.testng.annotations.Test;
   24.10  
   24.11 @@ -39,16 +40,16 @@
   24.12       */
   24.13      @Test
   24.14      public void testIsPrimitive() {
   24.15 -        assertEquals(true,  JSType.isPrimitive(null));
   24.16 -        assertEquals(true,  JSType.isPrimitive(ScriptRuntime.UNDEFINED));
   24.17 -        assertEquals(true,  JSType.isPrimitive(Double.NaN));
   24.18 -        assertEquals(true,  JSType.isPrimitive(Double.NEGATIVE_INFINITY));
   24.19 -        assertEquals(true,  JSType.isPrimitive(Double.POSITIVE_INFINITY));
   24.20 -        assertEquals(true,  JSType.isPrimitive(0.0));
   24.21 -        assertEquals(true,  JSType.isPrimitive(3.14));
   24.22 -        assertEquals(true,  JSType.isPrimitive("hello"));
   24.23 -        assertEquals(true,  JSType.isPrimitive(""));
   24.24 -        assertEquals(false, JSType.isPrimitive(new Object()));
   24.25 +        assertTrue(JSType.isPrimitive(null));
   24.26 +        assertTrue(JSType.isPrimitive(ScriptRuntime.UNDEFINED));
   24.27 +        assertTrue(JSType.isPrimitive(Double.NaN));
   24.28 +        assertTrue(JSType.isPrimitive(Double.NEGATIVE_INFINITY));
   24.29 +        assertTrue(JSType.isPrimitive(Double.POSITIVE_INFINITY));
   24.30 +        assertTrue(JSType.isPrimitive(0.0));
   24.31 +        assertTrue(JSType.isPrimitive(3.14));
   24.32 +        assertTrue(JSType.isPrimitive("hello"));
   24.33 +        assertTrue(JSType.isPrimitive(""));
   24.34 +        assertFalse(JSType.isPrimitive(new Object()));
   24.35      }
   24.36  
   24.37      /**
   24.38 @@ -56,17 +57,17 @@
   24.39       */
   24.40      @Test
   24.41      public void testToBoolean() {
   24.42 -        assertEquals(false, JSType.toBoolean(ScriptRuntime.UNDEFINED));
   24.43 -        assertEquals(false, JSType.toBoolean(null));
   24.44 -        assertEquals(false, JSType.toBoolean(Boolean.FALSE));
   24.45 -        assertEquals(true,  JSType.toBoolean(Boolean.TRUE));
   24.46 -        assertEquals(false, JSType.toBoolean(-0.0));
   24.47 -        assertEquals(false, JSType.toBoolean(0.0));
   24.48 -        assertEquals(false, JSType.toBoolean(Double.NaN));
   24.49 -        assertEquals(true,  JSType.toBoolean(3.14));
   24.50 -        assertEquals(false, JSType.toBoolean(""));
   24.51 -        assertEquals(true,  JSType.toBoolean("javascript"));
   24.52 -        assertEquals(true,  JSType.toBoolean(new Object()));
   24.53 +        assertFalse(JSType.toBoolean(ScriptRuntime.UNDEFINED));
   24.54 +        assertFalse(JSType.toBoolean(null));
   24.55 +        assertFalse(JSType.toBoolean(Boolean.FALSE));
   24.56 +        assertTrue(JSType.toBoolean(Boolean.TRUE));
   24.57 +        assertFalse(JSType.toBoolean(-0.0));
   24.58 +        assertFalse(JSType.toBoolean(0.0));
   24.59 +        assertFalse(JSType.toBoolean(Double.NaN));
   24.60 +        assertTrue(JSType.toBoolean(3.14));
   24.61 +        assertFalse(JSType.toBoolean(""));
   24.62 +        assertTrue(JSType.toBoolean("javascript"));
   24.63 +        assertTrue(JSType.toBoolean(new Object()));
   24.64      }
   24.65  
   24.66      /**
   24.67 @@ -75,10 +76,10 @@
   24.68      @Test
   24.69      public void testToNumber_Object() {
   24.70          assertTrue(Double.isNaN(JSType.toNumber(ScriptRuntime.UNDEFINED)));
   24.71 -        assertEquals(0.0,  JSType.toNumber((Object)null), 0.0);
   24.72 -        assertEquals(1.0,  JSType.toNumber(Boolean.TRUE), 0.0);
   24.73 -        assertEquals(0.0,  JSType.toNumber(Boolean.FALSE), 0.0);
   24.74 -        assertEquals(3.14, JSType.toNumber(3.14), 0.0);
   24.75 +        assertEquals(JSType.toNumber((Object)null), 0.0, 0.0);
   24.76 +        assertEquals(JSType.toNumber(Boolean.TRUE), 1.0, 0.0);
   24.77 +        assertEquals(JSType.toNumber(Boolean.FALSE), 0.0, 0.0);
   24.78 +        assertEquals(JSType.toNumber(3.14), 3.14, 0.0);
   24.79          // FIXME: add more assertions for specific String to number cases
   24.80          // FIXME: add case for Object type (JSObject with getDefaultValue)
   24.81      }
   24.82 @@ -88,16 +89,16 @@
   24.83       */
   24.84      @Test
   24.85      public void testToString_Object() {
   24.86 -        assertEquals("undefined", JSType.toString(ScriptRuntime.UNDEFINED));
   24.87 -        assertEquals("null", JSType.toString(null));
   24.88 -        assertEquals("true", JSType.toString(Boolean.TRUE));
   24.89 -        assertEquals("false", JSType.toString(Boolean.FALSE));
   24.90 -        assertEquals("", JSType.toString(""));
   24.91 -        assertEquals("nashorn", JSType.toString("nashorn"));
   24.92 -        assertEquals("NaN", JSType.toString(Double.NaN));
   24.93 -        assertEquals("Infinity", JSType.toString(Double.POSITIVE_INFINITY));
   24.94 -        assertEquals("-Infinity", JSType.toString(Double.NEGATIVE_INFINITY));
   24.95 -        assertEquals("0", JSType.toString(0.0));
   24.96 +        assertEquals(JSType.toString(ScriptRuntime.UNDEFINED), "undefined");
   24.97 +        assertEquals(JSType.toString(null), "null");
   24.98 +        assertEquals(JSType.toString(Boolean.TRUE), "true");
   24.99 +        assertEquals(JSType.toString(Boolean.FALSE), "false");
  24.100 +        assertEquals(JSType.toString(""), "");
  24.101 +        assertEquals(JSType.toString("nashorn"), "nashorn");
  24.102 +        assertEquals(JSType.toString(Double.NaN), "NaN");
  24.103 +        assertEquals(JSType.toString(Double.POSITIVE_INFINITY), "Infinity");
  24.104 +        assertEquals(JSType.toString(Double.NEGATIVE_INFINITY), "-Infinity");
  24.105 +        assertEquals(JSType.toString(0.0), "0");
  24.106          // FIXME: add more number-to-string test cases
  24.107          // FIXME: add case for Object type (JSObject with getDefaultValue)
  24.108      }
    25.1 --- a/test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java	Mon Jan 21 11:03:56 2013 +0100
    25.2 +++ b/test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java	Mon Jan 21 21:17:38 2013 +0530
    25.3 @@ -104,7 +104,7 @@
    25.4          Options options = new Options("nashorn", werr);
    25.5          options.process(args);
    25.6          ErrorManager errors = new ErrorManager(werr);
    25.7 -        this.context = new Context(options, errors, wout, werr);
    25.8 +        this.context = new Context(options, errors, wout, werr, Thread.currentThread().getContextClassLoader());
    25.9      }
   25.10  
   25.11      @Override
   25.12 @@ -113,7 +113,7 @@
   25.13          try {
   25.14              ctxOut.setDelegatee(out);
   25.15              ctxErr.setDelegatee(err);
   25.16 -            final ErrorManager errors = context.getErrors();
   25.17 +            final ErrorManager errors = context.getErrorManager();
   25.18              final ScriptObject global = context.createGlobal();
   25.19              Context.setGlobal(global);
   25.20  

mercurial