8006678: Avoid too many Context.getGlobal() calls

Tue, 22 Jan 2013 22:07:12 +0530

author
sundar
date
Tue, 22 Jan 2013 22:07:12 +0530
changeset 44
e62dba3ce52b
parent 43
e43d1013d871
child 45
0dbcb7350595

8006678: Avoid too many Context.getGlobal() calls
Reviewed-by: lagergren, jlaskey

make/project.properties file | annotate | diff | comparison | revisions
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/Lower.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/debug/JSONWriter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeArguments.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeArray.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeBoolean.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeDate.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeFunction.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeJSAdapter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeJSON.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeJava.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeNumber.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeRegExp.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeString.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Context.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ECMAErrors.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ErrorManager.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/JSType.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ParserException.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptFunction.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptRuntime.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptingFunctions.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/SetMethodCreator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/URIUtils.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Undefined.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/arrays/IteratorAction.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.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/JavaArgumentConverters.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/Lookup.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java file | annotate | diff | comparison | revisions
     1.1 --- a/make/project.properties	Tue Jan 22 14:36:28 2013 +0100
     1.2 +++ b/make/project.properties	Tue Jan 22 22:07:12 2013 +0530
     1.3 @@ -216,7 +216,7 @@
     1.4  # add '-Dtest.js.outofprocess' to run each test in a new sub-process
     1.5  run.test.jvmargs=-server -Xmx${run.test.xmx} -XX:-TieredCompilation -esa -ea -Dnashorn.debug=true -Dfile.encoding=UTF-8 
     1.6  #-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M  
     1.7 -run.test.jvmargs.octane=-Xms${run.test.xms} -${run.test.jvmargs}
     1.8 +run.test.jvmargs.octane=-Xms${run.test.xms} ${run.test.jvmargs}
     1.9  
    1.10  run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
    1.11  
     2.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Tue Jan 22 14:36:28 2013 +0100
     2.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Tue Jan 22 22:07:12 2013 +0530
     2.3 @@ -216,7 +216,7 @@
     2.4              realSelf = self;
     2.5          }
     2.6          try {
     2.7 -            final ScriptObject oldGlobal = Context.getGlobal();
     2.8 +            final ScriptObject oldGlobal = getNashornGlobal();
     2.9              try {
    2.10                  if(oldGlobal != global) {
    2.11                      setNashornGlobal(global);
    2.12 @@ -343,7 +343,7 @@
    2.13      }
    2.14  
    2.15      private Object invokeImpl(final Object selfObject, final String name, final Object... args) throws ScriptException, NoSuchMethodException {
    2.16 -        final ScriptObject oldGlobal     = Context.getGlobal();
    2.17 +        final ScriptObject oldGlobal     = getNashornGlobal();
    2.18          final boolean globalChanged = (oldGlobal != global);
    2.19  
    2.20          Object self = selfObject;
    2.21 @@ -395,7 +395,7 @@
    2.22          if (script == null) {
    2.23              return null;
    2.24          }
    2.25 -        final ScriptObject oldGlobal = Context.getGlobal();
    2.26 +        final ScriptObject oldGlobal = getNashornGlobal();
    2.27          final boolean globalChanged = (oldGlobal != global);
    2.28          try {
    2.29              if (globalChanged) {
    2.30 @@ -457,7 +457,7 @@
    2.31      }
    2.32  
    2.33      private ScriptFunction compileImpl(final char[] buf, final ScriptContext ctxt) throws ScriptException {
    2.34 -        final ScriptObject oldGlobal = Context.getGlobal();
    2.35 +        final ScriptObject oldGlobal = getNashornGlobal();
    2.36          final boolean globalChanged = (oldGlobal != global);
    2.37          try {
    2.38              final Object val = ctxt.getAttribute(ScriptEngine.FILENAME);
    2.39 @@ -479,13 +479,17 @@
    2.40          }
    2.41      }
    2.42  
    2.43 -    // don't make this public!!
    2.44 +    // don't make these public!!
    2.45 +    static ScriptObject getNashornGlobal() {
    2.46 +       return Context.getGlobal();
    2.47 +    }
    2.48 +
    2.49      static void setNashornGlobal(final ScriptObject global) {
    2.50          AccessController.doPrivileged(new PrivilegedAction<Void>() {
    2.51              @Override
    2.52              public Void run() {
    2.53 -               Context.setGlobal(global);
    2.54 -               return null;
    2.55 +                Context.setGlobal(global);
    2.56 +                return null;
    2.57              }
    2.58          });
    2.59      }
     3.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Tue Jan 22 14:36:28 2013 +0100
     3.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Tue Jan 22 22:07:12 2013 +0530
     3.3 @@ -83,7 +83,7 @@
     3.4      }
     3.5  
     3.6      private <V> V inGlobal(final Callable<V> callable) {
     3.7 -        final ScriptObject oldGlobal = Context.getGlobal();
     3.8 +        final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal();
     3.9          final boolean globalChanged = (oldGlobal != global);
    3.10          if (globalChanged) {
    3.11              NashornScriptEngine.setNashornGlobal(global);
    3.12 @@ -105,7 +105,7 @@
    3.13      @Override
    3.14      public Object call(final String methodName, final Object args[]) {
    3.15          final Object val = sobj.get(methodName);
    3.16 -        final ScriptObject oldGlobal = Context.getGlobal();
    3.17 +        final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal();
    3.18          final boolean globalChanged = (oldGlobal != global);
    3.19  
    3.20          if (val instanceof ScriptFunction) {
    3.21 @@ -180,7 +180,7 @@
    3.22  
    3.23      @Override
    3.24      public void setMember(final String name, final Object value) {
    3.25 -        put(name, wrap(value, Context.getGlobal()));
    3.26 +        put(name, wrap(value, NashornScriptEngine.getNashornGlobal()));
    3.27      }
    3.28  
    3.29      @Override
     4.1 --- a/src/jdk/nashorn/internal/codegen/Lower.java	Tue Jan 22 14:36:28 2013 +0100
     4.2 +++ b/src/jdk/nashorn/internal/codegen/Lower.java	Tue Jan 22 22:07:12 2013 +0530
     4.3 @@ -1080,10 +1080,10 @@
     4.4      /*
     4.5       * For a script, add scope symbols as defined in the property map
     4.6       */
     4.7 -    private static void initFromPropertyMap(final FunctionNode functionNode) {
     4.8 +    private static void initFromPropertyMap(final Context context, final FunctionNode functionNode) {
     4.9          assert functionNode.isScript();
    4.10  
    4.11 -        final PropertyMap map = Context.getGlobal().getMap();
    4.12 +        final PropertyMap map = context.getGlobalMap();
    4.13  
    4.14          for (final Property property : map.getProperties()) {
    4.15              final String key = property.getKey();
    4.16 @@ -1130,7 +1130,7 @@
    4.17          }
    4.18  
    4.19          if (functionNode.isScript()) {
    4.20 -            initFromPropertyMap(functionNode);
    4.21 +            initFromPropertyMap(compiler.getContext(), functionNode);
    4.22          }
    4.23  
    4.24          // Add function name as local symbol
     5.1 --- a/src/jdk/nashorn/internal/ir/debug/JSONWriter.java	Tue Jan 22 14:36:28 2013 +0100
     5.2 +++ b/src/jdk/nashorn/internal/ir/debug/JSONWriter.java	Tue Jan 22 22:07:12 2013 +0530
     5.3 @@ -71,7 +71,6 @@
     5.4  import jdk.nashorn.internal.parser.TokenType;
     5.5  import jdk.nashorn.internal.runtime.Context;
     5.6  import jdk.nashorn.internal.runtime.ParserException;
     5.7 -import jdk.nashorn.internal.runtime.ScriptObject;
     5.8  import jdk.nashorn.internal.runtime.Source;
     5.9  
    5.10  /**
    5.11 @@ -87,7 +86,6 @@
    5.12       * @return JSON string representation of AST of the supplied code
    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    = AccessController.doPrivileged(
    5.17                  new PrivilegedAction<Context>() {
    5.18                      @Override
    5.19 @@ -103,7 +101,7 @@
    5.20              functionNode.accept(jsonWriter);
    5.21              return jsonWriter.getString();
    5.22          } catch (final ParserException e) {
    5.23 -            e.throwAsEcmaException(global);
    5.24 +            e.throwAsEcmaException();
    5.25              return null;
    5.26          }
    5.27      }
     6.1 --- a/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java	Tue Jan 22 14:36:28 2013 +0100
     6.2 +++ b/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java	Tue Jan 22 22:07:12 2013 +0530
     6.3 @@ -157,7 +157,7 @@
     6.4              if (getter == UNDEFINED || getter instanceof ScriptFunction) {
     6.5                  this.get = getter;
     6.6              } else {
     6.7 -                typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(getter));
     6.8 +                typeError("not.a.function", ScriptRuntime.safeToString(getter));
     6.9              }
    6.10          } else {
    6.11              delete(GET, strict);
    6.12 @@ -168,7 +168,7 @@
    6.13              if (setter == UNDEFINED || setter instanceof ScriptFunction) {
    6.14                  this.set = setter;
    6.15              } else {
    6.16 -                typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(setter));
    6.17 +                typeError("not.a.function", ScriptRuntime.safeToString(setter));
    6.18              }
    6.19          } else {
    6.20              delete(SET, strict);
     7.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Tue Jan 22 14:36:28 2013 +0100
     7.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Tue Jan 22 22:07:12 2013 +0530
     7.3 @@ -1157,7 +1157,7 @@
     7.4       */
     7.5      public static Object toObject(final Object obj) {
     7.6          if (obj == null || obj == UNDEFINED) {
     7.7 -            typeError(instance(), "not.an.object", ScriptRuntime.safeToString(obj));
     7.8 +            typeError("not.an.object", ScriptRuntime.safeToString(obj));
     7.9          }
    7.10  
    7.11          if (obj instanceof ScriptObject) {
    7.12 @@ -1274,7 +1274,7 @@
    7.13       */
    7.14      public static void checkObject(final Object obj) {
    7.15          if (!(obj instanceof ScriptObject)) {
    7.16 -            typeError(instance(), "not.an.object", ScriptRuntime.safeToString(obj));
    7.17 +            typeError("not.an.object", ScriptRuntime.safeToString(obj));
    7.18          }
    7.19      }
    7.20  
    7.21 @@ -1286,7 +1286,7 @@
    7.22       */
    7.23      public static void checkObjectCoercible(final Object obj) {
    7.24          if (obj == null || obj == UNDEFINED) {
    7.25 -            typeError(instance(), "not.an.object", ScriptRuntime.safeToString(obj));
    7.26 +            typeError("not.an.object", ScriptRuntime.safeToString(obj));
    7.27          }
    7.28      }
    7.29  
     8.1 --- a/src/jdk/nashorn/internal/objects/NativeArguments.java	Tue Jan 22 14:36:28 2013 +0100
     8.2 +++ b/src/jdk/nashorn/internal/objects/NativeArguments.java	Tue Jan 22 22:07:12 2013 +0530
     8.3 @@ -485,7 +485,7 @@
     8.4              final boolean allowed = super.defineOwnProperty(key, propertyDesc, false);
     8.5              if (!allowed) {
     8.6                  if (reject) {
     8.7 -                    typeError(Global.instance(), "cant.redefine.property",  key, ScriptRuntime.safeToString(this));
     8.8 +                    typeError("cant.redefine.property",  key, ScriptRuntime.safeToString(this));
     8.9                  }
    8.10                  return false;
    8.11              }
     9.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java	Tue Jan 22 14:36:28 2013 +0100
     9.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java	Tue Jan 22 22:07:12 2013 +0530
     9.3 @@ -47,7 +47,6 @@
     9.4  import jdk.nashorn.internal.objects.annotations.Setter;
     9.5  import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
     9.6  import jdk.nashorn.internal.objects.annotations.Where;
     9.7 -import jdk.nashorn.internal.runtime.Context;
     9.8  import jdk.nashorn.internal.runtime.JSType;
     9.9  import jdk.nashorn.internal.runtime.PropertyDescriptor;
    9.10  import jdk.nashorn.internal.runtime.ScriptFunction;
    9.11 @@ -182,7 +181,7 @@
    9.12              // Step 3g
    9.13              if (!oldLenDesc.isWritable()) {
    9.14                  if (reject) {
    9.15 -                    typeError(Global.instance(), "property.not.writable", "length", ScriptRuntime.safeToString(this));
    9.16 +                    typeError("property.not.writable", "length", ScriptRuntime.safeToString(this));
    9.17                  }
    9.18                  return false;
    9.19              }
    9.20 @@ -211,7 +210,7 @@
    9.21                      }
    9.22                      super.defineOwnProperty("length", newLenDesc, false);
    9.23                      if (reject) {
    9.24 -                        typeError(Global.instance(), "property.not.writable", "length", ScriptRuntime.safeToString(this));
    9.25 +                        typeError("property.not.writable", "length", ScriptRuntime.safeToString(this));
    9.26                      }
    9.27                      return false;
    9.28                  }
    9.29 @@ -236,7 +235,7 @@
    9.30              // setting an element beyond current length, but 'length' is not writable
    9.31              if (longIndex >= oldLen && !oldLenDesc.isWritable()) {
    9.32                  if (reject) {
    9.33 -                    typeError(Global.instance(), "property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
    9.34 +                    typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
    9.35                  }
    9.36                  return false;
    9.37              }
    9.38 @@ -248,7 +247,7 @@
    9.39              // Step 4d
    9.40              if (!succeeded) {
    9.41                  if (reject) {
    9.42 -                    typeError(Global.instance(), "cant.redefine.property", key, ScriptRuntime.safeToString(this));
    9.43 +                    typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
    9.44                  }
    9.45                  return false;
    9.46              }
    9.47 @@ -325,7 +324,7 @@
    9.48              }
    9.49          }
    9.50          if (reject) {
    9.51 -            rangeError(Global.instance(), "inappropriate.array.length", ScriptRuntime.safeToString(length));
    9.52 +            rangeError("inappropriate.array.length", ScriptRuntime.safeToString(length));
    9.53          }
    9.54          return -1;
    9.55      }
    9.56 @@ -371,7 +370,7 @@
    9.57              final Object obj = iter.next();
    9.58  
    9.59              if (obj != null && obj != ScriptRuntime.UNDEFINED) {
    9.60 -                final Object val = JSType.toObject(Global.instance(), obj);
    9.61 +                final Object val = JSType.toScriptObject(obj);
    9.62  
    9.63                  try {
    9.64                      if (val instanceof ScriptObject) {
    9.65 @@ -381,7 +380,7 @@
    9.66                          if (toLocaleString instanceof ScriptFunction) {
    9.67                              sb.append((String)TO_LOCALE_STRING.getInvoker().invokeExact(toLocaleString, sobj));
    9.68                          } else {
    9.69 -                            typeError(Global.instance(), "not.a.function", "toLocaleString");
    9.70 +                            typeError("not.a.function", "toLocaleString");
    9.71                          }
    9.72                      }
    9.73                  } catch (final Error|RuntimeException t) {
    9.74 @@ -434,7 +433,7 @@
    9.75                   */
    9.76                  final double numberLength = ((Number) len).doubleValue();
    9.77                  if (length != numberLength) {
    9.78 -                    rangeError(Global.instance(), "inappropriate.array.length", JSType.toString(numberLength));
    9.79 +                    rangeError("inappropriate.array.length", JSType.toString(numberLength));
    9.80                  }
    9.81  
    9.82                  return new NativeArray(length);
    9.83 @@ -624,7 +623,7 @@
    9.84  
    9.85              return element;
    9.86          } catch (final ClassCastException | NullPointerException e) {
    9.87 -            typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
    9.88 +            typeError("not.an.object", ScriptRuntime.safeToString(self));
    9.89              return ScriptRuntime.UNDEFINED;
    9.90          }
    9.91      }
    9.92 @@ -660,7 +659,7 @@
    9.93  
    9.94              return len;
    9.95          } catch (final ClassCastException | NullPointerException e) {
    9.96 -            typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
    9.97 +            typeError("not.an.object", ScriptRuntime.safeToString(self));
    9.98              return ScriptRuntime.UNDEFINED;
    9.99          }
   9.100      }
   9.101 @@ -699,7 +698,7 @@
   9.102              }
   9.103              return sobj;
   9.104          } catch (final ClassCastException | NullPointerException e) {
   9.105 -            typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
   9.106 +            typeError("not.an.object", ScriptRuntime.safeToString(self));
   9.107              return ScriptRuntime.UNDEFINED;
   9.108          }
   9.109      }
   9.110 @@ -805,7 +804,7 @@
   9.111          final ScriptFunction cmp = compareFunction(comparefn);
   9.112  
   9.113          final List<Object> list = Arrays.asList(array);
   9.114 -        final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Context.getGlobal();
   9.115 +        final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance();
   9.116  
   9.117          Collections.sort(list, new Comparator<Object>() {
   9.118              @Override
   9.119 @@ -865,7 +864,7 @@
   9.120  
   9.121              return sobj;
   9.122          } catch (final ClassCastException | NullPointerException e) {
   9.123 -            typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
   9.124 +            typeError("not.an.object", ScriptRuntime.safeToString(self));
   9.125              return ScriptRuntime.UNDEFINED;
   9.126          }
   9.127      }
   9.128 @@ -1080,7 +1079,7 @@
   9.129                  }
   9.130              }
   9.131          } catch (final ClassCastException | NullPointerException e) {
   9.132 -            typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
   9.133 +            typeError("not.an.object", ScriptRuntime.safeToString(self));
   9.134          }
   9.135  
   9.136          return -1;
   9.137 @@ -1202,14 +1201,14 @@
   9.138          Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;
   9.139  
   9.140          if (callbackfn == ScriptRuntime.UNDEFINED) {
   9.141 -            typeError(Global.instance(), "not.a.function", "undefined");
   9.142 +            typeError("not.a.function", "undefined");
   9.143          }
   9.144  
   9.145          if (!initialValuePresent) {
   9.146              if (iter.hasNext()) {
   9.147                  initialValue = iter.next();
   9.148              } else {
   9.149 -                typeError(Global.instance(), "array.reduce.invalid.init");
   9.150 +                typeError("array.reduce.invalid.init");
   9.151              }
   9.152          }
   9.153  
    10.1 --- a/src/jdk/nashorn/internal/objects/NativeBoolean.java	Tue Jan 22 14:36:28 2013 +0100
    10.2 +++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java	Tue Jan 22 22:07:12 2013 +0530
    10.3 @@ -145,7 +145,7 @@
    10.4          } else if (self != null && self == Global.instance().getBooleanPrototype()) {
    10.5              return false;
    10.6          } else {
    10.7 -            typeError(Global.instance(), "not.a.boolean", ScriptRuntime.safeToString(self));
    10.8 +            typeError("not.a.boolean", ScriptRuntime.safeToString(self));
    10.9              return false;
   10.10          }
   10.11      }
    11.1 --- a/src/jdk/nashorn/internal/objects/NativeDate.java	Tue Jan 22 14:36:28 2013 +0100
    11.2 +++ b/src/jdk/nashorn/internal/objects/NativeDate.java	Tue Jan 22 22:07:12 2013 +0530
    11.3 @@ -867,7 +867,7 @@
    11.4              if (func instanceof ScriptFunction) {
    11.5                  return TO_ISO_STRING.getInvoker().invokeExact(func, sobj, key);
    11.6              }
    11.7 -            typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(func));
    11.8 +            typeError("not.a.function", ScriptRuntime.safeToString(func));
    11.9          } catch (final RuntimeException | Error e) {
   11.10              throw e;
   11.11          } catch (final Throwable t) {
   11.12 @@ -1006,7 +1006,7 @@
   11.13              return sb.toString();
   11.14          }
   11.15  
   11.16 -        rangeError(Global.instance(), "invalid.date");
   11.17 +        rangeError("invalid.date");
   11.18  
   11.19          return INVALID_DATE;
   11.20      }
   11.21 @@ -1035,7 +1035,7 @@
   11.22              return sb.toString();
   11.23          }
   11.24  
   11.25 -        rangeError(Global.instance(), "invalid.date");
   11.26 +        rangeError("invalid.date");
   11.27  
   11.28          return INVALID_DATE;
   11.29      }
   11.30 @@ -1268,7 +1268,7 @@
   11.31          } else if (self != null && self == Global.instance().getDatePrototype()) {
   11.32              return Global.instance().DEFAULT_DATE;
   11.33          } else {
   11.34 -            typeError(Global.instance(), "not.a.date", ScriptRuntime.safeToString(self));
   11.35 +            typeError("not.a.date", ScriptRuntime.safeToString(self));
   11.36              return null;
   11.37          }
   11.38      }
    12.1 --- a/src/jdk/nashorn/internal/objects/NativeFunction.java	Tue Jan 22 14:36:28 2013 +0100
    12.2 +++ b/src/jdk/nashorn/internal/objects/NativeFunction.java	Tue Jan 22 22:07:12 2013 +0530
    12.3 @@ -60,7 +60,7 @@
    12.4      @Function(attributes = Attribute.NOT_ENUMERABLE)
    12.5      public static Object toString(final Object self) {
    12.6          if (!(self instanceof ScriptFunction)) {
    12.7 -            typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
    12.8 +            typeError("not.a.function", ScriptRuntime.safeToString(self));
    12.9              return UNDEFINED;
   12.10          }
   12.11          return ((ScriptFunction)self).toSource();
   12.12 @@ -71,7 +71,7 @@
   12.13              if (thiz == UNDEFINED || thiz == null) {
   12.14                  return Global.instance();
   12.15              }
   12.16 -            return JSType.toObject(Global.instance(), thiz);
   12.17 +            return JSType.toScriptObject(thiz);
   12.18          }
   12.19  
   12.20          return thiz;
   12.21 @@ -88,7 +88,7 @@
   12.22      @Function(attributes = Attribute.NOT_ENUMERABLE)
   12.23      public static Object apply(final Object self, final Object thiz, final Object array) {
   12.24          if (!(self instanceof ScriptFunction)) {
   12.25 -            typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
   12.26 +            typeError("not.a.function", ScriptRuntime.safeToString(self));
   12.27              return UNDEFINED;
   12.28          }
   12.29  
   12.30 @@ -102,12 +102,12 @@
   12.31              final Object       len  = sobj.getLength();
   12.32  
   12.33              if (len == UNDEFINED || len == null) {
   12.34 -                typeError(Global.instance(), "function.apply.expects.array");
   12.35 +                typeError("function.apply.expects.array");
   12.36              }
   12.37  
   12.38              final int n = (int)JSType.toUint32(len);
   12.39              if (n != JSType.toNumber(len)) {
   12.40 -                typeError(Global.instance(), "function.apply.expects.array");
   12.41 +                typeError("function.apply.expects.array");
   12.42              }
   12.43  
   12.44              args = new Object[(int)JSType.toUint32(len)];
   12.45 @@ -122,7 +122,7 @@
   12.46          } else if (array == null || array == UNDEFINED) {
   12.47              args = ScriptRuntime.EMPTY_ARRAY;
   12.48          } else {
   12.49 -            typeError(Global.instance(), "function.apply.expects.array");
   12.50 +            typeError("function.apply.expects.array");
   12.51          }
   12.52  
   12.53          final ScriptFunction func = (ScriptFunction)self;
   12.54 @@ -143,7 +143,7 @@
   12.55      @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
   12.56      public static Object call(final Object self, final Object... args) {
   12.57          if (!(self instanceof ScriptFunction)) {
   12.58 -            typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
   12.59 +            typeError("not.a.function", ScriptRuntime.safeToString(self));
   12.60              return UNDEFINED;
   12.61          }
   12.62  
   12.63 @@ -178,7 +178,7 @@
   12.64      @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
   12.65      public static Object bind(final Object self, final Object... args) {
   12.66          if (!(self instanceof ScriptFunction)) {
   12.67 -            typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
   12.68 +            typeError("not.a.function", ScriptRuntime.safeToString(self));
   12.69              return UNDEFINED;
   12.70          }
   12.71  
   12.72 @@ -209,7 +209,7 @@
   12.73      @Function(attributes = Attribute.NOT_ENUMERABLE)
   12.74      public static Object toSource(final Object self) {
   12.75          if (!(self instanceof ScriptFunction)) {
   12.76 -            typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
   12.77 +            typeError("not.a.function", ScriptRuntime.safeToString(self));
   12.78              return UNDEFINED;
   12.79          }
   12.80          return ((ScriptFunction)self).toSource();
    13.1 --- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java	Tue Jan 22 14:36:28 2013 +0100
    13.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java	Tue Jan 22 22:07:12 2013 +0530
    13.3 @@ -540,7 +540,7 @@
    13.4          Object adaptee;
    13.5  
    13.6          if (args == null || args.length == 0) {
    13.7 -            typeError(Global.instance(), "not.an.object", "null");
    13.8 +            typeError("not.an.object", "null");
    13.9              return null; //won't reach, but fixed warning
   13.10          }
   13.11  
   13.12 @@ -564,7 +564,7 @@
   13.13          }
   13.14  
   13.15          if (!(adaptee instanceof ScriptObject)) {
   13.16 -            typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(adaptee));
   13.17 +            typeError("not.an.object", ScriptRuntime.safeToString(adaptee));
   13.18          }
   13.19  
   13.20          if (proto != null && !(proto instanceof ScriptObject)) {
   13.21 @@ -623,7 +623,7 @@
   13.22                          func.makeBoundFunction(this, new Object[] { name })), 0, Object.class),
   13.23                          adaptee.getMap().getProtoGetSwitchPoint(__call__), testJSAdaptor(adaptee, null, null, null));
   13.24              }
   13.25 -            typeError(Global.instance(), "no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
   13.26 +            typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
   13.27              break;
   13.28          default:
   13.29              break;
   13.30 @@ -696,7 +696,7 @@
   13.31  
   13.32          switch (hook) {
   13.33          case __call__:
   13.34 -            typeError(Global.instance(), "no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
   13.35 +            typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
   13.36              throw new AssertionError("should not reach here");
   13.37          default:
   13.38              final MethodHandle methodHandle = hook.equals(__put__) ?
    14.1 --- a/src/jdk/nashorn/internal/objects/NativeJSON.java	Tue Jan 22 14:36:28 2013 +0100
    14.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSON.java	Tue Jan 22 22:07:12 2013 +0530
    14.3 @@ -101,7 +101,7 @@
    14.4          try {
    14.5              node = parser.parse();
    14.6          } catch (final ParserException e) {
    14.7 -            syntaxError(Global.instance(), e, "invalid.json", e.getMessage());
    14.8 +            syntaxError(e, "invalid.json", e.getMessage());
    14.9              return UNDEFINED;
   14.10          }
   14.11  
   14.12 @@ -404,7 +404,7 @@
   14.13      // Spec: The abstract operation JO(value) serializes an object.
   14.14      private static String JO(final ScriptObject value, final StringifyState state) {
   14.15          if (state.stack.containsKey(value)) {
   14.16 -            typeError(Global.instance(), "JSON.stringify.cyclic");
   14.17 +            typeError("JSON.stringify.cyclic");
   14.18          }
   14.19  
   14.20          state.stack.put(value, value);
   14.21 @@ -480,7 +480,7 @@
   14.22      // Spec: The abstract operation JA(value) serializes an array.
   14.23      private static Object JA(final NativeArray value, final StringifyState state) {
   14.24          if (state.stack.containsKey(value)) {
   14.25 -            typeError(Global.instance(), "JSON.stringify.cyclic");
   14.26 +            typeError("JSON.stringify.cyclic");
   14.27          }
   14.28  
   14.29          state.stack.put(value, value);
    15.1 --- a/src/jdk/nashorn/internal/objects/NativeJava.java	Tue Jan 22 14:36:28 2013 +0100
    15.2 +++ b/src/jdk/nashorn/internal/objects/NativeJava.java	Tue Jan 22 22:07:12 2013 +0530
    15.3 @@ -287,7 +287,7 @@
    15.4              return new NativeArray(copyArray((boolean[])objArray));
    15.5          }
    15.6  
    15.7 -        typeError(Global.instance(), "cant.convert.to.javascript.array", objArray.getClass().getName());
    15.8 +        typeError("cant.convert.to.javascript.array", objArray.getClass().getName());
    15.9  
   15.10          throw new AssertionError();
   15.11      }
   15.12 @@ -384,7 +384,7 @@
   15.13      @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   15.14      public static Object extend(final Object self, final Object... types) {
   15.15          if(types == null || types.length == 0) {
   15.16 -            typeError(Global.instance(), "extend.expects.at.least.one.argument");
   15.17 +            typeError("extend.expects.at.least.one.argument");
   15.18          }
   15.19          final Class<?>[] stypes = new Class<?>[types.length];
   15.20          try {
   15.21 @@ -392,7 +392,7 @@
   15.22                  stypes[i] = ((StaticClass)types[i]).getRepresentedClass();
   15.23              }
   15.24          } catch(final ClassCastException e) {
   15.25 -            typeError(Global.instance(), "extend.expects.java.types");
   15.26 +            typeError("extend.expects.java.types");
   15.27          }
   15.28          return JavaAdapterFactory.getAdapterClassFor(stypes);
   15.29      }
    16.1 --- a/src/jdk/nashorn/internal/objects/NativeNumber.java	Tue Jan 22 14:36:28 2013 +0100
    16.2 +++ b/src/jdk/nashorn/internal/objects/NativeNumber.java	Tue Jan 22 22:07:12 2013 +0530
    16.3 @@ -185,7 +185,7 @@
    16.4      public static Object toFixed(final Object self, final Object fractionDigits) {
    16.5          final int f = JSType.toInteger(fractionDigits);
    16.6          if (f < 0 || f > 20) {
    16.7 -            rangeError(Global.instance(), "invalid.fraction.digits", "toFixed");
    16.8 +            rangeError("invalid.fraction.digits", "toFixed");
    16.9              return UNDEFINED;
   16.10          }
   16.11  
   16.12 @@ -227,7 +227,7 @@
   16.13          }
   16.14  
   16.15          if (fractionDigits != UNDEFINED && (f < 0 || f > 20)) {
   16.16 -            rangeError(Global.instance(), "invalid.fraction.digits", "toExponential");
   16.17 +            rangeError("invalid.fraction.digits", "toExponential");
   16.18              return UNDEFINED;
   16.19          }
   16.20  
   16.21 @@ -258,7 +258,7 @@
   16.22          }
   16.23  
   16.24          if (p < 1 || p > 21) {
   16.25 -            rangeError(Global.instance(), "invalid.precision");
   16.26 +            rangeError("invalid.precision");
   16.27              return UNDEFINED;
   16.28          }
   16.29  
   16.30 @@ -283,7 +283,7 @@
   16.31              final int intRadix = JSType.toInteger(radix);
   16.32              if (intRadix != 10) {
   16.33                  if (intRadix < 2 || intRadix > 36) {
   16.34 -                    rangeError(Global.instance(), "invalid.radix");
   16.35 +                    rangeError("invalid.radix");
   16.36                  }
   16.37                  return JSType.toString(getNumberValue(self), intRadix);
   16.38              }
   16.39 @@ -338,7 +338,7 @@
   16.40          } else if (self != null && self == Global.instance().getNumberPrototype()) {
   16.41              return 0.0;
   16.42          } else {
   16.43 -            typeError(Global.instance(), "not.a.number", ScriptRuntime.safeToString(self));
   16.44 +            typeError("not.a.number", ScriptRuntime.safeToString(self));
   16.45              return Double.NaN;
   16.46          }
   16.47      }
    17.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java	Tue Jan 22 14:36:28 2013 +0100
    17.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java	Tue Jan 22 22:07:12 2013 +0530
    17.3 @@ -316,7 +316,7 @@
    17.4       */
    17.5      @Function(attributes = Attribute.NOT_ENUMERABLE)
    17.6      public static Object toLocaleString(final Object self) {
    17.7 -        final Object obj = JSType.toObject(Global.instance(), self);
    17.8 +        final Object obj = JSType.toScriptObject(self);
    17.9          if (obj instanceof ScriptObject) {
   17.10              final ScriptObject sobj = (ScriptObject)self;
   17.11              try {
   17.12 @@ -331,7 +331,7 @@
   17.13                  throw new RuntimeException(t);
   17.14              }
   17.15  
   17.16 -            typeError(Global.instance(), "not.a.function", "toString");
   17.17 +            typeError("not.a.function", "toString");
   17.18              throw new AssertionError(); // never reached
   17.19          }
   17.20  
    18.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java	Tue Jan 22 14:36:28 2013 +0100
    18.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java	Tue Jan 22 22:07:12 2013 +0530
    18.3 @@ -86,7 +86,7 @@
    18.4              regExp = new RegExp(input, flagString);
    18.5          } catch (final ParserException e) {
    18.6              // translate it as SyntaxError object and throw it
    18.7 -            e.throwAsEcmaException(Global.instance());
    18.8 +            e.throwAsEcmaException();
    18.9              throw new AssertionError(); //guard against null warnings below
   18.10          }
   18.11  
   18.12 @@ -221,7 +221,7 @@
   18.13                  if (!flagsDefined) {
   18.14                      return (NativeRegExp)regexp; // 15.10.3.1 - undefined flags and regexp as
   18.15                  }
   18.16 -                typeError(Global.instance(), "regex.cant.supply.flags");
   18.17 +                typeError("regex.cant.supply.flags");
   18.18              }
   18.19              patternString = JSType.toString(regexp);
   18.20          }
   18.21 @@ -716,7 +716,7 @@
   18.22          } else if (self != null && self == Global.instance().getRegExpPrototype()) {
   18.23              return Global.instance().DEFAULT_REGEXP;
   18.24          } else {
   18.25 -            typeError(Global.instance(), "not.a.regexp", ScriptRuntime.safeToString(self));
   18.26 +            typeError("not.a.regexp", ScriptRuntime.safeToString(self));
   18.27              return null;
   18.28          }
   18.29      }
    19.1 --- a/src/jdk/nashorn/internal/objects/NativeString.java	Tue Jan 22 14:36:28 2013 +0100
    19.2 +++ b/src/jdk/nashorn/internal/objects/NativeString.java	Tue Jan 22 22:07:12 2013 +0530
    19.3 @@ -288,7 +288,7 @@
    19.4      private boolean checkDeleteIndex(final int index, final boolean strict) {
    19.5          if (isValid(index)) {
    19.6              if (strict) {
    19.7 -                typeError(Global.instance(), "cant.delete.property", Integer.toString(index), ScriptRuntime.safeToString(this));
    19.8 +                typeError("cant.delete.property", Integer.toString(index), ScriptRuntime.safeToString(this));
    19.9              }
   19.10              return true;
   19.11          }
   19.12 @@ -904,7 +904,7 @@
   19.13          } else if (self != null && self == Global.instance().getStringPrototype()) {
   19.14              return "";
   19.15          } else {
   19.16 -            typeError(Global.instance(), "not.a.string", ScriptRuntime.safeToString(self));
   19.17 +            typeError("not.a.string", ScriptRuntime.safeToString(self));
   19.18              return null;
   19.19          }
   19.20      }
   19.21 @@ -919,7 +919,7 @@
   19.22          } else if (self != null && self == Global.instance().getStringPrototype()) {
   19.23              return "";
   19.24          } else {
   19.25 -            typeError(Global.instance(), "not.a.string", ScriptRuntime.safeToString(self));
   19.26 +            typeError( "not.a.string", ScriptRuntime.safeToString(self));
   19.27              return null;
   19.28          }
   19.29      }
    20.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Tue Jan 22 14:36:28 2013 +0100
    20.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Tue Jan 22 22:07:12 2013 +0530
    20.3 @@ -50,10 +50,12 @@
    20.4  import jdk.nashorn.internal.codegen.Compiler;
    20.5  import jdk.nashorn.internal.codegen.Namespace;
    20.6  import jdk.nashorn.internal.codegen.objects.ObjectClassGenerator;
    20.7 +import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
    20.8  import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
    20.9  import jdk.nashorn.internal.runtime.options.KeyValueOption;
   20.10  import jdk.nashorn.internal.runtime.options.Option;
   20.11  import jdk.nashorn.internal.runtime.options.Options;
   20.12 +import sun.reflect.Reflection;
   20.13  
   20.14  /**
   20.15   * This class manages the global state of execution. Context is immutable.
   20.16 @@ -72,11 +74,27 @@
   20.17          };
   20.18  
   20.19      /**
   20.20 -     * Return the current global scope
   20.21 -     * @return current global scope
   20.22 +     * Get the current global scope
   20.23 +     * @return the current global scope
   20.24       */
   20.25      public static ScriptObject getGlobal() {
   20.26 -        return currentGlobal.get();
   20.27 +        final SecurityManager sm = System.getSecurityManager();
   20.28 +        if (sm != null) {
   20.29 +            // skip getCallerClass and getGlobal and get to the real caller
   20.30 +            Class<?> caller = Reflection.getCallerClass(2);
   20.31 +            ClassLoader callerLoader = caller.getClassLoader();
   20.32 +
   20.33 +            // Allow this method only for nashorn's own classes, script
   20.34 +            // generated classes and Java adapter classes. Rest should
   20.35 +            // have the necessary security permission.
   20.36 +            if (callerLoader != myLoader &&
   20.37 +                !(callerLoader instanceof NashornLoader) &&
   20.38 +                !(JavaAdapterFactory.isAdapterClass(caller))) {
   20.39 +                sm.checkPermission(new RuntimePermission("getNashornGlobal"));
   20.40 +            }
   20.41 +        }
   20.42 +
   20.43 +        return getGlobalTrusted();
   20.44      }
   20.45  
   20.46      /**
   20.47 @@ -93,7 +111,7 @@
   20.48              throw new IllegalArgumentException("global does not implement GlobalObject!");
   20.49          }
   20.50  
   20.51 -        currentGlobal.set(global);
   20.52 +        setGlobalTrusted(global);
   20.53      }
   20.54  
   20.55      /**
   20.56 @@ -114,7 +132,7 @@
   20.57       * @return error writer of the current context
   20.58       */
   20.59      public static PrintWriter getCurrentErr() {
   20.60 -        final ScriptObject global = getGlobal();
   20.61 +        final ScriptObject global = getGlobalTrusted();
   20.62          return (global != null)? global.getContext().getErr() : new PrintWriter(System.err);
   20.63      }
   20.64  
   20.65 @@ -456,6 +474,14 @@
   20.66          return _timezone;
   20.67      }
   20.68  
   20.69 +    /*
   20.70 +     * Get the PropertyMap of the current global scope
   20.71 +     * @return the property map of the current global scope
   20.72 +     */
   20.73 +    public PropertyMap getGlobalMap() {
   20.74 +        return Context.getGlobalTrusted().getMap();
   20.75 +    }
   20.76 +
   20.77      /**
   20.78       * Compile a top level script.
   20.79       *
   20.80 @@ -501,7 +527,7 @@
   20.81          final String  file       = (location == UNDEFINED || location == null) ? "<eval>" : location.toString();
   20.82          final Source  source     = new Source(file, string);
   20.83          final boolean directEval = location != UNDEFINED; // is this direct 'eval' call or indirectly invoked eval?
   20.84 -        final ScriptObject global = Context.getGlobal();
   20.85 +        final ScriptObject global = Context.getGlobalTrusted();
   20.86  
   20.87          ScriptObject scope = initialScope;
   20.88  
   20.89 @@ -624,7 +650,7 @@
   20.90              }
   20.91          }
   20.92  
   20.93 -        typeError(Context.getGlobal(), "cant.load.script", ScriptRuntime.safeToString(source));
   20.94 +        typeError("cant.load.script", ScriptRuntime.safeToString(source));
   20.95  
   20.96          return UNDEFINED;
   20.97      }
   20.98 @@ -726,13 +752,13 @@
   20.99          final ScriptObject global = newGlobal();
  20.100          // Need only minimal global object, if we are just compiling.
  20.101          if (!_compile_only) {
  20.102 -            final ScriptObject oldGlobal = Context.getGlobal();
  20.103 +            final ScriptObject oldGlobal = Context.getGlobalTrusted();
  20.104              try {
  20.105 -                Context.setGlobal(global);
  20.106 +                Context.setGlobalTrusted(global);
  20.107                  // initialize global scope with builtin global objects
  20.108                  ((GlobalObject)global).initBuiltinObjects();
  20.109              } finally {
  20.110 -                Context.setGlobal(oldGlobal);
  20.111 +                Context.setGlobalTrusted(oldGlobal);
  20.112              }
  20.113          }
  20.114  
  20.115 @@ -740,10 +766,30 @@
  20.116      }
  20.117  
  20.118      /**
  20.119 -     * Trusted variant package-private
  20.120 +     * Trusted variants - package-private
  20.121 +     */
  20.122 +
  20.123 +    /**
  20.124 +     * Return the current global scope
  20.125 +     * @return current global scope
  20.126 +     */
  20.127 +    static ScriptObject getGlobalTrusted() {
  20.128 +        return currentGlobal.get();
  20.129 +    }
  20.130 +
  20.131 +    /**
  20.132 +     * Set the current global scope
  20.133 +     */
  20.134 +    static void setGlobalTrusted(ScriptObject global) {
  20.135 +         currentGlobal.set(global);
  20.136 +    }
  20.137 +
  20.138 +    /**
  20.139 +     * Return the current global's context
  20.140 +     * @return current global's context
  20.141       */
  20.142      static Context getContextTrusted() {
  20.143 -        return Context.getGlobal().getContext();
  20.144 +        return Context.getGlobalTrusted().getContext();
  20.145      }
  20.146  
  20.147      /**
  20.148 @@ -770,7 +816,7 @@
  20.149          try {
  20.150              script = compileScript(name, url, scope, new Context.ThrowErrorManager(), _strict);
  20.151          } catch (final ParserException e) {
  20.152 -            e.throwAsEcmaException(Context.getGlobal());
  20.153 +            e.throwAsEcmaException();
  20.154          }
  20.155  
  20.156          return ScriptRuntime.apply(script, thiz);
  20.157 @@ -782,7 +828,7 @@
  20.158          try {
  20.159              script = compileScript(source, scope, new Context.ThrowErrorManager(), _strict);
  20.160          } catch (final ParserException e) {
  20.161 -            e.throwAsEcmaException(Context.getGlobal());
  20.162 +            e.throwAsEcmaException();
  20.163          }
  20.164  
  20.165          return ScriptRuntime.apply(script, thiz);
  20.166 @@ -813,7 +859,7 @@
  20.167          }
  20.168  
  20.169          // Package as a JavaScript function and pass function back to shell.
  20.170 -        return ((GlobalObject)Context.getGlobal()).newScriptFunction(RUN_SCRIPT.tag(), runMethodHandle, scope, strict);
  20.171 +        return ((GlobalObject)Context.getGlobalTrusted()).newScriptFunction(RUN_SCRIPT.tag(), runMethodHandle, scope, strict);
  20.172      }
  20.173  
  20.174      private ScriptFunction compileScript(final String name, final URL url, final ScriptObject scope, final ErrorManager errMan, final boolean strict) throws IOException {
  20.175 @@ -836,7 +882,7 @@
  20.176          Class<?> script;
  20.177  
  20.178          if (_class_cache_size > 0) {
  20.179 -            global = (GlobalObject)Context.getGlobal();
  20.180 +            global = (GlobalObject)Context.getGlobalTrusted();
  20.181              script = global.findCachedClass(source);
  20.182              if (script != null) {
  20.183                  return script;
    21.1 --- a/src/jdk/nashorn/internal/runtime/ECMAErrors.java	Tue Jan 22 14:36:28 2013 +0100
    21.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAErrors.java	Tue Jan 22 22:07:12 2013 +0530
    21.3 @@ -56,6 +56,16 @@
    21.4          throw new ECMAException(thrown, cause);
    21.5      }
    21.6  
    21.7 +     /**
    21.8 +     * Error dispatch mechanism.
    21.9 +     * Throw a {@link ParserException} as the correct JavaScript error
   21.10 +     *
   21.11 +     * @param e {@code ParserException} for error dispatcher
   21.12 +     */
   21.13 +    public static void throwAsEcmaException(final ParserException e) {
   21.14 +        throwAsEcmaException(Context.getGlobalTrusted(), e);
   21.15 +    }
   21.16 +
   21.17      /**
   21.18       * Error dispatch mechanism.
   21.19       * Throw a {@link ParserException} as the correct JavaScript error
   21.20 @@ -103,6 +113,15 @@
   21.21          // should not happen - perhaps unknown error type?
   21.22          throw e;
   21.23      }
   21.24 +    /**
   21.25 +     * Throw a syntax error (ECMA 15.11.6.4)
   21.26 +     *
   21.27 +     * @param msgId   resource tag for error message
   21.28 +     * @param args    arguments to resource
   21.29 +     */
   21.30 +    public static void syntaxError(final String msgId, final String... args) {
   21.31 +        syntaxError(Context.getGlobalTrusted(), msgId, args);
   21.32 +    }
   21.33  
   21.34      /**
   21.35       * Throw a syntax error (ECMA 15.11.6.4)
   21.36 @@ -118,6 +137,17 @@
   21.37      /**
   21.38       * Throw a syntax error (ECMA 15.11.6.4)
   21.39       *
   21.40 +     * @param cause   native Java {@code Throwable} that is the cause of error
   21.41 +     * @param msgId   resource tag for error message
   21.42 +     * @param args    arguments to resource
   21.43 +     */
   21.44 +    public static void syntaxError(final Throwable cause, final String msgId, final String... args) {
   21.45 +        syntaxError(Context.getGlobalTrusted(), cause, msgId, args);
   21.46 +    }
   21.47 +
   21.48 +    /**
   21.49 +     * Throw a syntax error (ECMA 15.11.6.4)
   21.50 +     *
   21.51       * @param global  global scope object
   21.52       * @param cause   native Java {@code Throwable} that is the cause of error
   21.53       * @param msgId   resource tag for error message
   21.54 @@ -131,6 +161,16 @@
   21.55      /**
   21.56       * Throw a type error (ECMA 15.11.6.5)
   21.57       *
   21.58 +     * @param msgId   resource tag for error message
   21.59 +     * @param args    arguments to resource
   21.60 +     */
   21.61 +    public static void typeError(final String msgId, final String... args) {
   21.62 +        typeError(Context.getGlobalTrusted(), msgId, args);
   21.63 +    }
   21.64 +
   21.65 +    /**
   21.66 +     * Throw a type error (ECMA 15.11.6.5)
   21.67 +     *
   21.68       * @param global  global scope object
   21.69       * @param msgId   resource tag for error message
   21.70       * @param args    arguments to resource
   21.71 @@ -142,6 +182,17 @@
   21.72      /**
   21.73       * Throw a type error (ECMA 15.11.6.5)
   21.74       *
   21.75 +     * @param cause   native Java {@code Throwable} that is the cause of error
   21.76 +     * @param msgId   resource tag for error message
   21.77 +     * @param args    arguments to resource
   21.78 +     */
   21.79 +    public static void typeError(final Throwable cause, final String msgId, final String... args) {
   21.80 +        typeError(Context.getGlobalTrusted(), cause, msgId, args);
   21.81 +    }
   21.82 +
   21.83 +    /**
   21.84 +     * Throw a type error (ECMA 15.11.6.5)
   21.85 +     *
   21.86       * @param global  global scope object
   21.87       * @param cause   native Java {@code Throwable} that is the cause of error
   21.88       * @param msgId   resource tag for error message
   21.89 @@ -155,6 +206,16 @@
   21.90      /**
   21.91       * Throw a range error (ECMA 15.11.6.2)
   21.92       *
   21.93 +     * @param msgId   resource tag for error message
   21.94 +     * @param args    arguments to resource
   21.95 +     */
   21.96 +    public static void rangeError(final String msgId, final String... args) {
   21.97 +        rangeError(Context.getGlobalTrusted(), msgId, args);
   21.98 +    }
   21.99 +
  21.100 +    /**
  21.101 +     * Throw a range error (ECMA 15.11.6.2)
  21.102 +     *
  21.103       * @param global  global scope object
  21.104       * @param msgId   resource tag for error message
  21.105       * @param args    arguments to resource
  21.106 @@ -166,6 +227,17 @@
  21.107      /**
  21.108       * Throw a range error (ECMA 15.11.6.2)
  21.109       *
  21.110 +     * @param cause   native Java {@code Throwable} that is the cause of error
  21.111 +     * @param msgId   resource tag for error message
  21.112 +     * @param args    arguments to resource
  21.113 +     */
  21.114 +    public static void rangeError(final Throwable cause, final String msgId, final String... args) {
  21.115 +        rangeError(Context.getGlobalTrusted(), cause, msgId, args);
  21.116 +    }
  21.117 +
  21.118 +    /**
  21.119 +     * Throw a range error (ECMA 15.11.6.2)
  21.120 +     *
  21.121       * @param global  global scope object
  21.122       * @param cause   native Java {@code Throwable} that is the cause of error
  21.123       * @param msgId   resource tag for error message
  21.124 @@ -179,6 +251,16 @@
  21.125      /**
  21.126       * Throw a reference error (ECMA 15.11.6.3)
  21.127       *
  21.128 +     * @param msgId   resource tag for error message
  21.129 +     * @param args    arguments to resource
  21.130 +     */
  21.131 +    public static void referenceError(final String msgId, final String... args) {
  21.132 +        referenceError(Context.getGlobalTrusted(), msgId, args);
  21.133 +    }
  21.134 +
  21.135 +    /**
  21.136 +     * Throw a reference error (ECMA 15.11.6.3)
  21.137 +     *
  21.138       * @param global  global scope object
  21.139       * @param msgId   resource tag for error message
  21.140       * @param args    arguments to resource
  21.141 @@ -190,6 +272,17 @@
  21.142      /**
  21.143       * Throw a reference error (ECMA 15.11.6.3)
  21.144       *
  21.145 +     * @param cause   native Java {@code Throwable} that is the cause of error
  21.146 +     * @param msgId   resource tag for error message
  21.147 +     * @param args    arguments to resource
  21.148 +     */
  21.149 +    public static void referenceError(final Throwable cause, final String msgId, final String... args) {
  21.150 +        referenceError(Context.getGlobalTrusted(), cause, msgId, args);
  21.151 +    }
  21.152 +
  21.153 +    /**
  21.154 +     * Throw a reference error (ECMA 15.11.6.3)
  21.155 +     *
  21.156       * @param global  global scope object
  21.157       * @param cause   native Java {@code Throwable} that is the cause of error
  21.158       * @param msgId   resource tag for error message
  21.159 @@ -203,6 +296,16 @@
  21.160      /**
  21.161       * Throw a URI error (ECMA 15.11.6.6)
  21.162       *
  21.163 +     * @param msgId   resource tag for error message
  21.164 +     * @param args    arguments to resource
  21.165 +     */
  21.166 +    public static void uriError(final String msgId, final String... args) {
  21.167 +        uriError(Context.getGlobalTrusted(), msgId, args);
  21.168 +    }
  21.169 +
  21.170 +    /**
  21.171 +     * Throw a URI error (ECMA 15.11.6.6)
  21.172 +     *
  21.173       * @param global  global scope object
  21.174       * @param msgId   resource tag for error message
  21.175       * @param args    arguments to resource
  21.176 @@ -214,6 +317,17 @@
  21.177      /**
  21.178       * Throw a URI error (ECMA 15.11.6.6)
  21.179       *
  21.180 +     * @param cause   native Java {@code Throwable} that is the cause of error
  21.181 +     * @param msgId   resource tag for error message
  21.182 +     * @param args    arguments to resource
  21.183 +     */
  21.184 +    public static void uriError(final Throwable cause, final String msgId, final String... args) {
  21.185 +        uriError(Context.getGlobalTrusted(), cause, msgId, args);
  21.186 +    }
  21.187 +
  21.188 +    /**
  21.189 +     * Throw a URI error (ECMA 15.11.6.6)
  21.190 +     *
  21.191       * @param global  global scope object
  21.192       * @param cause   native Java {@code Throwable} that is the cause of error
  21.193       * @param msgId   resource tag for error message
    22.1 --- a/src/jdk/nashorn/internal/runtime/ErrorManager.java	Tue Jan 22 14:36:28 2013 +0100
    22.2 +++ b/src/jdk/nashorn/internal/runtime/ErrorManager.java	Tue Jan 22 22:07:12 2013 +0530
    22.3 @@ -79,7 +79,7 @@
    22.4          }
    22.5  
    22.6          if (limit != 0 && count > limit) {
    22.7 -            rangeError(Context.getGlobal(), "too.many.errors", Integer.toString(limit));
    22.8 +            rangeError("too.many.errors", Integer.toString(limit));
    22.9          }
   22.10      }
   22.11  
    23.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java	Tue Jan 22 14:36:28 2013 +0100
    23.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java	Tue Jan 22 22:07:12 2013 +0530
    23.3 @@ -248,7 +248,7 @@
    23.4          final Object       result = sobj.getDefaultValue(hint);
    23.5  
    23.6          if (!isPrimitive(result)) {
    23.7 -            typeError(Context.getGlobal(), "bad.default.value", result.toString());
    23.8 +            typeError("bad.default.value", result.toString());
    23.9          }
   23.10  
   23.11          return result;
   23.12 @@ -803,12 +803,25 @@
   23.13       * NativeObject type
   23.14       * See ECMA 9.9 ToObject
   23.15       *
   23.16 +     * @param obj     the object to convert
   23.17 +     *
   23.18 +     * @return the wrapped object
   23.19 +     */
   23.20 +    public static Object toScriptObject(final Object obj) {
   23.21 +        return toScriptObject(Context.getGlobalTrusted(), obj);
   23.22 +    }
   23.23 +
   23.24 +    /**
   23.25 +     * Object conversion. This is used to convert objects and numbers to their corresponding
   23.26 +     * NativeObject type
   23.27 +     * See ECMA 9.9 ToObject
   23.28 +     *
   23.29       * @param global  the global object
   23.30       * @param obj     the object to convert
   23.31       *
   23.32       * @return the wrapped object
   23.33       */
   23.34 -    public static Object toObject(final ScriptObject global, final Object obj) {
   23.35 +    public static Object toScriptObject(final ScriptObject global, final Object obj) {
   23.36          if (nullOrUndefined(obj)) {
   23.37              typeError(global, "not.an.object", ScriptRuntime.safeToString(obj));
   23.38          }
   23.39 @@ -851,7 +864,7 @@
   23.40          if (obj instanceof ScriptObject) {
   23.41              if (safe) {
   23.42                  final ScriptObject sobj = (ScriptObject)obj;
   23.43 -                final GlobalObject gobj = (GlobalObject)Context.getGlobal();
   23.44 +                final GlobalObject gobj = (GlobalObject)Context.getGlobalTrusted();
   23.45                  return gobj.isError(sobj) ?
   23.46                      ECMAException.safeToString(sobj) :
   23.47                      sobj.safeToString();
    24.1 --- a/src/jdk/nashorn/internal/runtime/ParserException.java	Tue Jan 22 14:36:28 2013 +0100
    24.2 +++ b/src/jdk/nashorn/internal/runtime/ParserException.java	Tue Jan 22 22:07:12 2013 +0530
    24.3 @@ -129,6 +129,13 @@
    24.4  
    24.5      /**
    24.6       * Throw this {@code ParserException} as one of the 7 native JavaScript errors
    24.7 +     */
    24.8 +    public void throwAsEcmaException() {
    24.9 +        ECMAErrors.throwAsEcmaException(this);
   24.10 +    }
   24.11 +
   24.12 +    /**
   24.13 +     * Throw this {@code ParserException} as one of the 7 native JavaScript errors
   24.14       * @param global global scope object
   24.15       */
   24.16      public void throwAsEcmaException(final ScriptObject global) {
    25.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java	Tue Jan 22 14:36:28 2013 +0100
    25.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java	Tue Jan 22 22:07:12 2013 +0530
    25.3 @@ -289,7 +289,7 @@
    25.4      @Override
    25.5      public boolean isInstance(final ScriptObject instance) {
    25.6          if (!(prototype instanceof ScriptObject)) {
    25.7 -            typeError(Context.getGlobal(), "prototype.not.an.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(prototype));
    25.8 +            typeError("prototype.not.an.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(prototype));
    25.9          }
   25.10  
   25.11          for (ScriptObject proto = instance.getProto(); proto != null; proto = proto.getProto()) {
   25.12 @@ -401,7 +401,7 @@
   25.13       */
   25.14      public Object construct(final Object self, final Object... args) throws Throwable {
   25.15          if (constructHandle == null) {
   25.16 -            typeError(Context.getGlobal(), "not.a.constructor", ScriptRuntime.safeToString(this));
   25.17 +            typeError("not.a.constructor", ScriptRuntime.safeToString(this));
   25.18          }
   25.19  
   25.20          if (isVarArg(constructHandle)) {
   25.21 @@ -480,7 +480,7 @@
   25.22          }
   25.23  
   25.24          if (getConstructHandle() == null) {
   25.25 -            typeError(Context.getGlobal(), "not.a.constructor", ScriptRuntime.safeToString(this));
   25.26 +            typeError("not.a.constructor", ScriptRuntime.safeToString(this));
   25.27          }
   25.28  
   25.29          ScriptObject object = null;
   25.30 @@ -863,7 +863,7 @@
   25.31          MethodHandle constructor = getConstructHandle(type);
   25.32  
   25.33          if (constructor == null) {
   25.34 -            typeError(Context.getGlobal(), "not.a.constructor", ScriptRuntime.safeToString(this));
   25.35 +            typeError("not.a.constructor", ScriptRuntime.safeToString(this));
   25.36              return null;
   25.37          }
   25.38  
   25.39 @@ -925,7 +925,7 @@
   25.40  
   25.41              if(NashornCallSiteDescriptor.isScope(desc)) {
   25.42                  // (this, callee, args...) => (callee, args...) => (callee, [this], args...)
   25.43 -                boundHandle = MH.bindTo(callHandle, isNonStrictFunction() ? Context.getGlobal(): ScriptRuntime.UNDEFINED);
   25.44 +                boundHandle = MH.bindTo(callHandle, isNonStrictFunction() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED);
   25.45                  boundHandle = MH.dropArguments(boundHandle, 1, Object.class);
   25.46              } else {
   25.47                  // (this, callee, args...) permute => (callee, this, args...) which is what we get in
   25.48 @@ -943,7 +943,7 @@
   25.49              final MethodHandle callHandle = getBestSpecializedInvokeHandle(type.dropParameterTypes(0, 1));
   25.50  
   25.51              if(NashornCallSiteDescriptor.isScope(desc)) {
   25.52 -                boundHandle = MH.bindTo(callHandle, isNonStrictFunction()? Context.getGlobal() : ScriptRuntime.UNDEFINED);
   25.53 +                boundHandle = MH.bindTo(callHandle, isNonStrictFunction()? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED);
   25.54                  boundHandle = MH.dropArguments(boundHandle, 0, Object.class, Object.class);
   25.55              } else {
   25.56                  boundHandle = MH.dropArguments(callHandle, 0, Object.class);
   25.57 @@ -952,7 +952,7 @@
   25.58  
   25.59          boundHandle = pairArguments(boundHandle, type);
   25.60          return new NashornGuardedInvocation(boundHandle, null, NashornGuards.getFunctionGuard(this), isNonStrictFunction());
   25.61 -    }
   25.62 +   }
   25.63  
   25.64      /**
   25.65       * Used for noSuchMethod/noSuchProperty and JSAdapter hooks.
    26.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Tue Jan 22 14:36:28 2013 +0100
    26.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Tue Jan 22 22:07:12 2013 +0530
    26.3 @@ -274,7 +274,7 @@
    26.4        * @return property descriptor
    26.5        */
    26.6      public final PropertyDescriptor toPropertyDescriptor() {
    26.7 -        final GlobalObject global = (GlobalObject) Context.getGlobal();
    26.8 +        final GlobalObject global = (GlobalObject) Context.getGlobalTrusted();
    26.9  
   26.10          final PropertyDescriptor desc;
   26.11          if (isDataDescriptor()) {
   26.12 @@ -324,7 +324,7 @@
   26.13      public Object getOwnPropertyDescriptor(final String key) {
   26.14          final Property property = getMap().findProperty(key);
   26.15  
   26.16 -        final GlobalObject global = (GlobalObject)Context.getGlobal();
   26.17 +        final GlobalObject global = (GlobalObject)Context.getGlobalTrusted();
   26.18  
   26.19          if (property != null) {
   26.20              final ScriptFunction get   = property.getGetterFunction(this);
   26.21 @@ -389,7 +389,7 @@
   26.22       * @return true if property was successfully defined
   26.23       */
   26.24      public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
   26.25 -        final ScriptObject       global  = Context.getGlobal();
   26.26 +        final ScriptObject       global  = Context.getGlobalTrusted();
   26.27          final PropertyDescriptor desc    = toPropertyDescriptor(global, propertyDesc);
   26.28          final Object             current = getOwnPropertyDescriptor(key);
   26.29          final String             name    = JSType.toString(key);
   26.30 @@ -594,7 +594,7 @@
   26.31          final int propFlags = Property.toFlags(pdesc);
   26.32  
   26.33          if (pdesc.type() == PropertyDescriptor.GENERIC) {
   26.34 -            final GlobalObject global = (GlobalObject) Context.getGlobal();
   26.35 +            final GlobalObject global = (GlobalObject) Context.getGlobalTrusted();
   26.36              final PropertyDescriptor dDesc = global.newDataDescriptor(UNDEFINED, false, false, false);
   26.37  
   26.38              dDesc.fillFrom((ScriptObject)pdesc);
   26.39 @@ -1142,8 +1142,8 @@
   26.40          if (newProto == null || newProto instanceof ScriptObject) {
   26.41              setProto((ScriptObject)newProto);
   26.42          } else {
   26.43 -            final ScriptObject global = Context.getGlobal();
   26.44 -            final Object  newProtoObject = JSType.toObject(global, newProto);
   26.45 +            final ScriptObject global = Context.getGlobalTrusted();
   26.46 +            final Object  newProtoObject = JSType.toScriptObject(global, newProto);
   26.47  
   26.48              if (newProtoObject instanceof ScriptObject) {
   26.49                  setProto((ScriptObject)newProtoObject);
   26.50 @@ -1246,7 +1246,7 @@
   26.51          // "valueOf" methods, and in order to avoid those call sites from becoming megamorphic when multiple contexts
   26.52          // are being executed in a long-running program, we move the code and their associated dynamic call sites
   26.53          // (Global.TO_STRING and Global.VALUE_OF) into per-context code.
   26.54 -        return ((GlobalObject)Context.getGlobal()).getDefaultValue(this, typeHint);
   26.55 +        return ((GlobalObject)Context.getGlobalTrusted()).getDefaultValue(this, typeHint);
   26.56      }
   26.57  
   26.58      /**
   26.59 @@ -1575,7 +1575,7 @@
   26.60      }
   26.61  
   26.62      private GuardedInvocation notAFunction() {
   26.63 -        typeError(Context.getGlobal(), "not.a.function", ScriptRuntime.safeToString(this));
   26.64 +        typeError("not.a.function", ScriptRuntime.safeToString(this));
   26.65          return null;
   26.66      }
   26.67  
   26.68 @@ -1754,7 +1754,7 @@
   26.69      private GuardedInvocation createEmptySetMethod(final CallSiteDescriptor desc, String strictErrorMessage, boolean canBeFastScope) {
   26.70          final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
   26.71          if (NashornCallSiteDescriptor.isStrict(desc)) {
   26.72 -               typeError(Context.getGlobal(), strictErrorMessage, name, ScriptRuntime.safeToString((this)));
   26.73 +               typeError(strictErrorMessage, name, ScriptRuntime.safeToString((this)));
   26.74             }
   26.75             assert canBeFastScope || !NashornCallSiteDescriptor.isFastScope(desc);
   26.76             final PropertyMap myMap = getMap();
   26.77 @@ -1781,7 +1781,7 @@
   26.78      private boolean trySetEmbedOrSpill(final CallSiteDescriptor desc, final PropertyMap oldMap, final PropertyMap newMap, final Object value) {
   26.79          final boolean isStrict = NashornCallSiteDescriptor.isStrict(desc);
   26.80          if (!isExtensible() && isStrict) {
   26.81 -            typeError(Context.getGlobal(), "object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(this));
   26.82 +            typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(this));
   26.83              throw new AssertionError(); // never reached
   26.84          } else if (compareAndSetMap(oldMap, newMap)) {
   26.85              return true;
   26.86 @@ -1798,7 +1798,7 @@
   26.87  
   26.88          if (!obj.isExtensible()) {
   26.89              if (isStrict) {
   26.90 -                typeError(Context.getGlobal(), "object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
   26.91 +                typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
   26.92              }
   26.93          } else if (obj.compareAndSetMap(oldMap, newMap)) {
   26.94              obj.spill = new Object[SPILL_RATE];
   26.95 @@ -1815,7 +1815,7 @@
   26.96  
   26.97          if (!obj.isExtensible()) {
   26.98              if (isStrict) {
   26.99 -                typeError(Context.getGlobal(), "object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
  26.100 +                typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
  26.101              }
  26.102          } else if (obj.compareAndSetMap(oldMap, newMap)) {
  26.103              final int oldLength = obj.spill.length;
  26.104 @@ -1870,7 +1870,7 @@
  26.105  
  26.106          if (find == null) {
  26.107              if (scopeCall) {
  26.108 -                ECMAErrors.referenceError(Context.getGlobal(), "not.defined", name);
  26.109 +                ECMAErrors.referenceError("not.defined", name);
  26.110                  throw new AssertionError(); // never reached
  26.111              }
  26.112              return createEmptyGetter(desc, name);
  26.113 @@ -1909,7 +1909,7 @@
  26.114          }
  26.115  
  26.116          if (scopeAccess) {
  26.117 -            referenceError(Context.getGlobal(), "not.defined", name);
  26.118 +            referenceError("not.defined", name);
  26.119          }
  26.120  
  26.121          return createEmptyGetter(desc, name);
  26.122 @@ -2510,7 +2510,7 @@
  26.123          if (longIndex >= oldLength) {
  26.124              if (!isExtensible()) {
  26.125                  if (strict) {
  26.126 -                    typeError(Context.getGlobal(), "object.non.extensible", JSType.toString(index), ScriptRuntime.safeToString(this));
  26.127 +                    typeError("object.non.extensible", JSType.toString(index), ScriptRuntime.safeToString(this));
  26.128                  }
  26.129                  return;
  26.130              }
  26.131 @@ -2559,7 +2559,7 @@
  26.132          if (f != null) {
  26.133              if (!f.isWritable()) {
  26.134                  if (strict) {
  26.135 -                    typeError(Context.getGlobal(), "property.not.writable", key, ScriptRuntime.safeToString(this));
  26.136 +                    typeError("property.not.writable", key, ScriptRuntime.safeToString(this));
  26.137                  }
  26.138  
  26.139                  return;
  26.140 @@ -2575,7 +2575,7 @@
  26.141              }
  26.142          } else if (!isExtensible()) {
  26.143              if (strict) {
  26.144 -                typeError(Context.getGlobal(), "object.non.extensible", key, ScriptRuntime.safeToString(this));
  26.145 +                typeError("object.non.extensible", key, ScriptRuntime.safeToString(this));
  26.146              }
  26.147          } else {
  26.148              spill(key, value);
  26.149 @@ -3062,7 +3062,7 @@
  26.150  
  26.151          if (!find.isConfigurable()) {
  26.152              if (strict) {
  26.153 -                typeError(Context.getGlobal(), "cant.delete.property", propName, ScriptRuntime.safeToString(this));
  26.154 +                typeError("cant.delete.property", propName, ScriptRuntime.safeToString(this));
  26.155              }
  26.156              return false;
  26.157          }
  26.158 @@ -3232,7 +3232,7 @@
  26.159                  throw new RuntimeException(t);
  26.160              }
  26.161          }  else if (name != null) {
  26.162 -            typeError(Context.getGlobal(), "property.has.no.setter", name, ScriptRuntime.safeToString(self));
  26.163 +            typeError("property.has.no.setter", name, ScriptRuntime.safeToString(self));
  26.164          }
  26.165      }
  26.166  
    27.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Tue Jan 22 14:36:28 2013 +0100
    27.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Tue Jan 22 22:07:12 2013 +0530
    27.3 @@ -385,14 +385,14 @@
    27.4       * @return {@link WithObject} that is the new scope
    27.5       */
    27.6      public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
    27.7 -        final ScriptObject global = Context.getGlobal();
    27.8 +        final ScriptObject global = Context.getGlobalTrusted();
    27.9          if (expression == UNDEFINED) {
   27.10              typeError(global, "cant.apply.with.to.undefined");
   27.11          } else if (expression == null) {
   27.12              typeError(global, "cant.apply.with.to.null");
   27.13          }
   27.14  
   27.15 -        final ScriptObject withObject = new WithObject(scope, JSType.toObject(global, expression));
   27.16 +        final ScriptObject withObject = new WithObject(scope, JSType.toScriptObject(global, expression));
   27.17  
   27.18          return withObject;
   27.19      }
   27.20 @@ -488,9 +488,9 @@
   27.21              } else if (object instanceof Undefined) {
   27.22                  obj = ((Undefined)obj).get(property);
   27.23              } else if (object == null) {
   27.24 -                typeError(Context.getGlobal(), "cant.get.property", safeToString(property), "null");
   27.25 +                typeError("cant.get.property", safeToString(property), "null");
   27.26              } else if (JSType.isPrimitive(obj)) {
   27.27 -                obj = ((ScriptObject)JSType.toObject(Context.getGlobal(), obj)).get(property);
   27.28 +                obj = ((ScriptObject)JSType.toScriptObject(obj)).get(property);
   27.29              } else {
   27.30                  obj = UNDEFINED;
   27.31              }
   27.32 @@ -526,7 +526,7 @@
   27.33       * @return undefined
   27.34       */
   27.35      public static Object REFERENCE_ERROR(final Object lhs, final Object rhs, final Object msg) {
   27.36 -        referenceError(Context.getGlobal(), "cant.be.used.as.lhs", Objects.toString(msg));
   27.37 +        referenceError("cant.be.used.as.lhs", Objects.toString(msg));
   27.38          return UNDEFINED;
   27.39      }
   27.40  
   27.41 @@ -549,11 +549,11 @@
   27.42          }
   27.43  
   27.44          if (obj == null) {
   27.45 -            typeError(Context.getGlobal(), "cant.delete.property", safeToString(property), "null");
   27.46 +            typeError("cant.delete.property", safeToString(property), "null");
   27.47          }
   27.48  
   27.49          if (JSType.isPrimitive(obj)) {
   27.50 -            return ((ScriptObject) JSType.toObject(Context.getGlobal(), obj)).delete(property, Boolean.TRUE.equals(strict));
   27.51 +            return ((ScriptObject) JSType.toScriptObject(obj)).delete(property, Boolean.TRUE.equals(strict));
   27.52          }
   27.53  
   27.54          // if object is not reference type, vacuously delete is successful.
   27.55 @@ -574,7 +574,7 @@
   27.56       */
   27.57      public static boolean FAIL_DELETE(final Object obj, final Object property, final Object strict) {
   27.58          if (Boolean.TRUE.equals(strict)) {
   27.59 -            syntaxError(Context.getGlobal(), "strict.cant.delete", safeToString(property));
   27.60 +            syntaxError("strict.cant.delete", safeToString(property));
   27.61          }
   27.62          return false;
   27.63      }
   27.64 @@ -751,7 +751,7 @@
   27.65              return false;
   27.66          }
   27.67  
   27.68 -        typeError(Context.getGlobal(), "in.with.non.object", rvalType.toString().toLowerCase());
   27.69 +        typeError("in.with.non.object", rvalType.toString().toLowerCase());
   27.70  
   27.71          return false;
   27.72      }
   27.73 @@ -776,7 +776,7 @@
   27.74              return ((StaticClass)clazz).getRepresentedClass().isInstance(obj);
   27.75          }
   27.76  
   27.77 -        typeError(Context.getGlobal(), "instanceof.on.non.object");
   27.78 +        typeError("instanceof.on.non.object");
   27.79  
   27.80          return false;
   27.81      }
    28.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Tue Jan 22 14:36:28 2013 +0100
    28.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Tue Jan 22 22:07:12 2013 +0530
    28.3 @@ -88,7 +88,7 @@
    28.4          }
    28.5  
    28.6          if (f == null || !f.isFile()) {
    28.7 -            typeError(Context.getGlobal(), "not.a.file", ScriptRuntime.safeToString(file));
    28.8 +            typeError("not.a.file", ScriptRuntime.safeToString(file));
    28.9              return UNDEFINED;
   28.10          }
   28.11  
    29.1 --- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java	Tue Jan 22 14:36:28 2013 +0100
    29.2 +++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java	Tue Jan 22 22:07:12 2013 +0530
    29.3 @@ -144,7 +144,7 @@
    29.4          // In strict mode, assignment can not create a new variable.
    29.5          // See also ECMA Annex C item 4. ReferenceError is thrown.
    29.6          if (NashornCallSiteDescriptor.isScope(desc) && NashornCallSiteDescriptor.isStrict(desc)) {
    29.7 -            referenceError(Context.getGlobal(), "not.defined", getName());
    29.8 +            referenceError("not.defined", getName());
    29.9          }
   29.10      }
   29.11  
   29.12 @@ -171,7 +171,7 @@
   29.13      }
   29.14  
   29.15      private SetMethod createGlobalPropertySetter() {
   29.16 -        final ScriptObject global = Context.getGlobal();
   29.17 +        final ScriptObject global = Context.getGlobalTrusted();
   29.18          return new SetMethod(ScriptObject.bindTo(global.addSpill(getName()), global), null, false);
   29.19      }
   29.20  
    30.1 --- a/src/jdk/nashorn/internal/runtime/URIUtils.java	Tue Jan 22 14:36:28 2013 +0100
    30.2 +++ b/src/jdk/nashorn/internal/runtime/URIUtils.java	Tue Jan 22 22:07:12 2013 +0530
    30.3 @@ -71,7 +71,7 @@
    30.4              }
    30.5  
    30.6              if (C >= 0xDC00 && C <= 0xDFFF) {
    30.7 -                return error(Context.getGlobal(), string, k);
    30.8 +                return error(string, k);
    30.9              }
   30.10  
   30.11              int V;
   30.12 @@ -80,12 +80,12 @@
   30.13              } else {
   30.14                  k++;
   30.15                  if (k == len) {
   30.16 -                    return error(Context.getGlobal(), string, k);
   30.17 +                    return error(string, k);
   30.18                  }
   30.19  
   30.20                  final char kChar = string.charAt(k);
   30.21                  if (kChar < 0xDC00 || kChar > 0xDFFF) {
   30.22 -                    return error(Context.getGlobal(), string, k);
   30.23 +                    return error(string, k);
   30.24                  }
   30.25                  V = ((C - 0xD800) * 0x400 + (kChar - 0xDC00) + 0x10000);
   30.26              }
   30.27 @@ -93,7 +93,7 @@
   30.28              try {
   30.29                  sb.append(toHexEscape(V));
   30.30              } catch (final Exception e) {
   30.31 -                uriError(Context.getGlobal(), e, "bad.uri", string, Integer.toString(k));
   30.32 +                uriError( e, "bad.uri", string, Integer.toString(k));
   30.33                  return null;
   30.34              }
   30.35          }
   30.36 @@ -118,12 +118,12 @@
   30.37              }
   30.38              final int start = k;
   30.39              if (k + 2 >= len) {
   30.40 -                return error(Context.getGlobal(), string, k);
   30.41 +                return error(string, k);
   30.42              }
   30.43  
   30.44              int B = toHexByte(string.charAt(k + 1), string.charAt(k + 2));
   30.45              if (B < 0) {
   30.46 -                return error(Context.getGlobal(), string, k + 1);
   30.47 +                return error(string, k + 1);
   30.48              }
   30.49  
   30.50              k += 2;
   30.51 @@ -146,11 +146,11 @@
   30.52                  }
   30.53  
   30.54                  if (n == 1 || n > 4) {
   30.55 -                    return error(Context.getGlobal(), string, k);
   30.56 +                    return error(string, k);
   30.57                  }
   30.58  
   30.59                  if ((k + (3 * (n - 1))) >= len) {
   30.60 -                    return error(Context.getGlobal(), string, k);
   30.61 +                    return error(string, k);
   30.62                  }
   30.63  
   30.64                  final byte[] bbuf = new byte[n];
   30.65 @@ -159,16 +159,16 @@
   30.66                  for (int j = 1; j < n; j++) {
   30.67                      k++;
   30.68                      if (string.charAt(k) != '%') {
   30.69 -                        return error(Context.getGlobal(), string, k);
   30.70 +                        return error(string, k);
   30.71                      }
   30.72  
   30.73                      if (k + 2 == len) {
   30.74 -                        return error(Context.getGlobal(), string, k);
   30.75 +                        return error(string, k);
   30.76                      }
   30.77  
   30.78                      B = toHexByte(string.charAt(k + 1), string.charAt(k + 2));
   30.79                      if (B < 0 || (B & 0xC0) != 0x80) {
   30.80 -                        return error(Context.getGlobal(), string, k + 1);
   30.81 +                        return error(string, k + 1);
   30.82                      }
   30.83  
   30.84                      k += 2;
   30.85 @@ -179,7 +179,7 @@
   30.86                  try {
   30.87                      V = ucs4Char(bbuf);
   30.88                  } catch (final Exception e) {
   30.89 -                    uriError(Context.getGlobal(), e, "bad.uri", string, Integer.toString(k));
   30.90 +                    uriError(e, "bad.uri", string, Integer.toString(k));
   30.91                      return null;
   30.92                  }
   30.93                  if (V < 0x10000) {
   30.94 @@ -193,7 +193,7 @@
   30.95                      }
   30.96                  } else { // V >= 0x10000
   30.97                      if (V > 0x10FFFF) {
   30.98 -                        return error(Context.getGlobal(), string, k);
   30.99 +                        return error(string, k);
  30.100                      }
  30.101                      final int L = ((V - 0x10000) & 0x3FF) + 0xDC00;
  30.102                      final int H = (((V - 0x10000) >> 10) & 0x3FF) + 0xD800;
  30.103 @@ -268,8 +268,8 @@
  30.104          return sb.toString();
  30.105      }
  30.106  
  30.107 -    private static String error(final ScriptObject global, final String string, final int index) {
  30.108 -        uriError(global, "bad.uri", string, Integer.toString(index));
  30.109 +    private static String error(final String string, final int index) {
  30.110 +        uriError("bad.uri", string, Integer.toString(index));
  30.111          return null;
  30.112      }
  30.113  
    31.1 --- a/src/jdk/nashorn/internal/runtime/Undefined.java	Tue Jan 22 14:36:28 2013 +0100
    31.2 +++ b/src/jdk/nashorn/internal/runtime/Undefined.java	Tue Jan 22 22:07:12 2013 +0530
    31.3 @@ -129,7 +129,7 @@
    31.4      }
    31.5  
    31.6      private static void lookupTypeError(final String msg, final CallSiteDescriptor desc) {
    31.7 -        typeError(Context.getGlobal(), msg, desc.getNameTokenCount() > 2 ? desc.getNameToken(2) : null);
    31.8 +        typeError(msg, desc.getNameTokenCount() > 2 ? desc.getNameToken(2) : null);
    31.9      }
   31.10  
   31.11      /**
   31.12 @@ -174,18 +174,18 @@
   31.13  
   31.14      @Override
   31.15      public Object get(final Object key) {
   31.16 -        typeError(Context.getGlobal(), "cant.read.property.of.undefined", ScriptRuntime.safeToString(key));
   31.17 +        typeError("cant.read.property.of.undefined", ScriptRuntime.safeToString(key));
   31.18          return ScriptRuntime.UNDEFINED;
   31.19      }
   31.20  
   31.21      @Override
   31.22      public void set(final Object key, final Object value, final boolean strict) {
   31.23 -        typeError(Context.getGlobal(), "cant.set.property.of.undefined", ScriptRuntime.safeToString(key));
   31.24 +        typeError("cant.set.property.of.undefined", ScriptRuntime.safeToString(key));
   31.25      }
   31.26  
   31.27      @Override
   31.28      public boolean delete(final Object key, final boolean strict) {
   31.29 -        typeError(Context.getGlobal(), "cant.delete.property.of.undefined", ScriptRuntime.safeToString(key));
   31.30 +        typeError("cant.delete.property.of.undefined", ScriptRuntime.safeToString(key));
   31.31          return false;
   31.32      }
   31.33  
    32.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java	Tue Jan 22 14:36:28 2013 +0100
    32.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java	Tue Jan 22 22:07:12 2013 +0530
    32.3 @@ -122,7 +122,7 @@
    32.4              return new ArrayIterator((ScriptObject) obj, includeUndefined);
    32.5          }
    32.6  
    32.7 -        obj = JSType.toObject(Context.getGlobal(), obj);
    32.8 +        obj = JSType.toScriptObject(obj);
    32.9          if (obj instanceof ScriptObject) {
   32.10              return new MapIterator((ScriptObject)obj, includeUndefined);
   32.11          }
   32.12 @@ -143,7 +143,7 @@
   32.13              return new ReverseArrayIterator((ScriptObject) obj, includeUndefined);
   32.14          }
   32.15  
   32.16 -        obj = JSType.toObject(Context.getGlobal(), obj);
   32.17 +        obj = JSType.toScriptObject(obj);
   32.18          if (obj instanceof ScriptObject) {
   32.19              return new ReverseMapIterator((ScriptObject)obj, includeUndefined);
   32.20          }
    33.1 --- a/src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java	Tue Jan 22 14:36:28 2013 +0100
    33.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java	Tue Jan 22 22:07:12 2013 +0530
    33.3 @@ -47,7 +47,7 @@
    33.4      @Override
    33.5      public ArrayData set(final int index, final int value, final boolean strict) {
    33.6          if (strict) {
    33.7 -            typeError(Context.getGlobal(), "cant.set.property", Integer.toString(index), "frozen array");
    33.8 +            typeError("cant.set.property", Integer.toString(index), "frozen array");
    33.9          }
   33.10          return this;
   33.11      }
   33.12 @@ -55,7 +55,7 @@
   33.13      @Override
   33.14      public ArrayData set(final int index, final long value, final boolean strict) {
   33.15          if (strict) {
   33.16 -            typeError(Context.getGlobal(), "cant.set.property", Integer.toString(index), "frozen array");
   33.17 +            typeError("cant.set.property", Integer.toString(index), "frozen array");
   33.18          }
   33.19          return this;
   33.20      }
   33.21 @@ -63,7 +63,7 @@
   33.22      @Override
   33.23      public ArrayData set(final int index, final double value, final boolean strict) {
   33.24          if (strict) {
   33.25 -            typeError(Context.getGlobal(), "cant.set.property", Integer.toString(index), "frozen array");
   33.26 +            typeError("cant.set.property", Integer.toString(index), "frozen array");
   33.27          }
   33.28          return this;
   33.29      }
   33.30 @@ -71,7 +71,7 @@
   33.31      @Override
   33.32      public ArrayData set(final int index, final Object value, final boolean strict) {
   33.33          if (strict) {
   33.34 -            typeError(Context.getGlobal(), "cant.set.property", Integer.toString(index), "frozen array");
   33.35 +            typeError("cant.set.property", Integer.toString(index), "frozen array");
   33.36          }
   33.37          return this;
   33.38      }
    34.1 --- a/src/jdk/nashorn/internal/runtime/arrays/IteratorAction.java	Tue Jan 22 14:36:28 2013 +0100
    34.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/IteratorAction.java	Tue Jan 22 22:07:12 2013 +0530
    34.3 @@ -97,7 +97,7 @@
    34.4       */
    34.5      public final T apply() {
    34.6          if (!(callbackfn instanceof ScriptFunction)) {
    34.7 -            typeError(Context.getGlobal(), "not.a.function", ScriptRuntime.safeToString(callbackfn));
    34.8 +            typeError("not.a.function", ScriptRuntime.safeToString(callbackfn));
    34.9              return result;
   34.10          }
   34.11          final ScriptFunction func = ((ScriptFunction)callbackfn);
   34.12 @@ -136,4 +136,5 @@
   34.13       * @throws Throwable if invocation throws an exception/error
   34.14       */
   34.15      protected abstract boolean forEach(final Object val, final int i) throws Throwable;
   34.16 +
   34.17  }
    35.1 --- a/src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java	Tue Jan 22 14:36:28 2013 +0100
    35.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java	Tue Jan 22 22:07:12 2013 +0530
    35.3 @@ -47,7 +47,7 @@
    35.4      @Override
    35.5      public boolean canDelete(final int index, final boolean strict) {
    35.6          if (strict) {
    35.7 -            typeError(Context.getGlobal(), "cant.delete.property", Integer.toString(index), "sealed array");
    35.8 +            typeError("cant.delete.property", Integer.toString(index), "sealed array");
    35.9          }
   35.10          return false;
   35.11      }
    36.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Tue Jan 22 14:36:28 2013 +0100
    36.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Tue Jan 22 22:07:12 2013 +0530
    36.3 @@ -430,6 +430,21 @@
    36.4          }
    36.5      }
    36.6  
    36.7 +    /**
    36.8 +     * Tells if the given Class is an adapter or support class
    36.9 +     * @param clazz Class object
   36.10 +     * @return true if the Class given is adapter or support class
   36.11 +     */
   36.12 +    public static boolean isAdapterClass(Class<?> clazz) {
   36.13 +        return clazz.getClassLoader() instanceof AdapterLoader;
   36.14 +    }
   36.15 +
   36.16 +    private static class AdapterLoader extends SecureClassLoader {
   36.17 +        AdapterLoader(ClassLoader parent) {
   36.18 +            super(parent);
   36.19 +        }
   36.20 +    }
   36.21 +
   36.22      // Creation of class loader is in a separate static method so that it doesn't retain a reference to the factory
   36.23      // instance. Note that the adapter class is created in the protection domain of the class/interface being
   36.24      // extended/implemented, and only the privileged global setter action class is generated in the protection domain
   36.25 @@ -440,7 +455,7 @@
   36.26      // security tradeoff...
   36.27      private static ClassLoader createClassLoader(final ClassLoader parentLoader, final String className,
   36.28              final byte[] classBytes, final String privilegedActionClassName) {
   36.29 -        return new SecureClassLoader(parentLoader) {
   36.30 +        return new AdapterLoader(parentLoader) {
   36.31              @Override
   36.32              protected Class<?> findClass(final String name) throws ClassNotFoundException {
   36.33                  if(name.equals(className)) {
   36.34 @@ -688,7 +703,7 @@
   36.35       */
   36.36      public static MethodHandle getHandle(final Object obj, final String name, final MethodType type, final boolean varArg) {
   36.37          if (! (obj instanceof ScriptObject)) {
   36.38 -            typeError(Context.getGlobal(), "not.an.object", ScriptRuntime.safeToString(obj));
   36.39 +            typeError("not.an.object", ScriptRuntime.safeToString(obj));
   36.40              throw new AssertionError();
   36.41          }
   36.42  
   36.43 @@ -704,7 +719,7 @@
   36.44          } else if(fnObj == null || fnObj instanceof Undefined) {
   36.45              return null;
   36.46          } else {
   36.47 -            typeError(Context.getGlobal(), "not.a.function", name);
   36.48 +            typeError("not.a.function", name);
   36.49              throw new AssertionError();
   36.50          }
   36.51      }
   36.52 @@ -1076,7 +1091,7 @@
   36.53  
   36.54          void typeError() {
   36.55              assert adaptationOutcome != AdaptationOutcome.SUCCESS;
   36.56 -            ECMAErrors.typeError(Context.getGlobal(), "extend." + adaptationOutcome, classList);
   36.57 +            ECMAErrors.typeError("extend." + adaptationOutcome, classList);
   36.58          }
   36.59      }
   36.60  
   36.61 @@ -1219,7 +1234,7 @@
   36.62          while(it.hasNext()) {
   36.63              b.append(", ").append(it.next().clazz.getCanonicalName());
   36.64          }
   36.65 -        typeError(Context.getGlobal(), "extend.ambiguous.defining.class", b.toString());
   36.66 +        typeError("extend.ambiguous.defining.class", b.toString());
   36.67          throw new AssertionError(); // never reached
   36.68      }
   36.69  
    37.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java	Tue Jan 22 14:36:28 2013 +0100
    37.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java	Tue Jan 22 22:07:12 2013 +0530
    37.3 @@ -34,7 +34,6 @@
    37.4  import java.util.HashMap;
    37.5  import java.util.Map;
    37.6  import jdk.nashorn.internal.runtime.ConsString;
    37.7 -import jdk.nashorn.internal.runtime.Context;
    37.8  import jdk.nashorn.internal.runtime.JSType;
    37.9  import jdk.nashorn.internal.runtime.ScriptObject;
   37.10  import org.dynalang.dynalink.support.TypeUtilities;
   37.11 @@ -110,7 +109,7 @@
   37.12                  return Character.valueOf((char) ival);
   37.13              }
   37.14  
   37.15 -            typeError(Context.getGlobal(), "cant.convert.number.to.char");
   37.16 +            typeError("cant.convert.number.to.char");
   37.17          }
   37.18  
   37.19          final String s = toString(o);
   37.20 @@ -119,7 +118,7 @@
   37.21          }
   37.22  
   37.23          if (s.length() != 1) {
   37.24 -            typeError(Context.getGlobal(), "cant.convert.string.to.char");
   37.25 +            typeError("cant.convert.string.to.char");
   37.26          }
   37.27  
   37.28          return s.charAt(0);
    38.1 --- a/src/jdk/nashorn/internal/runtime/linker/Lookup.java	Tue Jan 22 14:36:28 2013 +0100
    38.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Lookup.java	Tue Jan 22 22:07:12 2013 +0530
    38.3 @@ -31,7 +31,6 @@
    38.4  import java.lang.invoke.MethodHandle;
    38.5  import java.lang.invoke.MethodHandles;
    38.6  import java.lang.invoke.MethodType;
    38.7 -import jdk.nashorn.internal.runtime.Context;
    38.8  import jdk.nashorn.internal.runtime.JSType;
    38.9  import jdk.nashorn.internal.runtime.Property;
   38.10  import jdk.nashorn.internal.runtime.PropertyMap;
   38.11 @@ -112,7 +111,7 @@
   38.12       * @return undefined (but throws error before return point)
   38.13       */
   38.14      public static Object typeErrorThrowerGetter(final Object self) {
   38.15 -        typeError(Context.getGlobal(), "strict.getter.setter.poison", ScriptRuntime.safeToString(self));
   38.16 +        typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));
   38.17          return UNDEFINED;
   38.18      }
   38.19  
   38.20 @@ -123,7 +122,7 @@
   38.21       * @param value (ignored)
   38.22       */
   38.23      public static void typeErrorThrowerSetter(final Object self, final Object value) {
   38.24 -        typeError(Context.getGlobal(), "strict.getter.setter.poison", ScriptRuntime.safeToString(self));
   38.25 +        typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));
   38.26      }
   38.27  
   38.28      /**
    39.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java	Tue Jan 22 14:36:28 2013 +0100
    39.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java	Tue Jan 22 22:07:12 2013 +0530
    39.3 @@ -30,8 +30,6 @@
    39.4  import static jdk.nashorn.internal.runtime.linker.Lookup.MH;
    39.5  
    39.6  import java.lang.invoke.MethodHandle;
    39.7 -import jdk.nashorn.internal.runtime.Context;
    39.8 -import jdk.nashorn.internal.runtime.ScriptObject;
    39.9  import jdk.nashorn.internal.runtime.ScriptRuntime;
   39.10  import org.dynalang.dynalink.CallSiteDescriptor;
   39.11  import org.dynalang.dynalink.linker.GuardedInvocation;
   39.12 @@ -81,21 +79,21 @@
   39.13          switch (operator) {
   39.14          case "new":
   39.15              if(isJavaDynamicMethod(self)) {
   39.16 -                typeError(Context.getGlobal(), "method.not.constructor", ScriptRuntime.safeToString(self));
   39.17 +                typeError("method.not.constructor", ScriptRuntime.safeToString(self));
   39.18              } else {
   39.19 -                typeError(Context.getGlobal(), "not.a.function", ScriptRuntime.safeToString(self));
   39.20 +                typeError("not.a.function", ScriptRuntime.safeToString(self));
   39.21              }
   39.22              break;
   39.23          case "call":
   39.24              if(isJavaDynamicMethod(self)) {
   39.25 -                typeError(Context.getGlobal(), "no.method.matches.args", ScriptRuntime.safeToString(self));
   39.26 +                typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
   39.27              } else {
   39.28 -                typeError(Context.getGlobal(), "not.a.function", ScriptRuntime.safeToString(self));
   39.29 +                typeError("not.a.function", ScriptRuntime.safeToString(self));
   39.30              }
   39.31              break;
   39.32          case "callMethod":
   39.33          case "getMethod":
   39.34 -            typeError(Context.getGlobal(), "no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));
   39.35 +            typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));
   39.36              break;
   39.37          case "getProp":
   39.38          case "getElem":
   39.39 @@ -136,25 +134,24 @@
   39.40      }
   39.41  
   39.42      private static GuardedInvocation linkNull(final LinkRequest linkRequest) {
   39.43 -        final ScriptObject global = Context.getGlobal();
   39.44          final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor();
   39.45          final String operator = desc.getFirstOperator();
   39.46          switch (operator) {
   39.47          case "new":
   39.48          case "call":
   39.49 -            typeError(global, "not.a.function", "null");
   39.50 +            typeError("not.a.function", "null");
   39.51              break;
   39.52          case "callMethod":
   39.53          case "getMethod":
   39.54 -            typeError(global, "no.such.function", getArgument(linkRequest), "null");
   39.55 +            typeError("no.such.function", getArgument(linkRequest), "null");
   39.56              break;
   39.57          case "getProp":
   39.58          case "getElem":
   39.59 -            typeError(global, "cant.get.property", getArgument(linkRequest), "null");
   39.60 +            typeError("cant.get.property", getArgument(linkRequest), "null");
   39.61              break;
   39.62          case "setProp":
   39.63          case "setElem":
   39.64 -            typeError(global, "cant.set.property", getArgument(linkRequest), "null");
   39.65 +            typeError("cant.set.property", getArgument(linkRequest), "null");
   39.66              break;
   39.67          default:
   39.68              break;
    40.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java	Tue Jan 22 14:36:28 2013 +0100
    40.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java	Tue Jan 22 22:07:12 2013 +0530
    40.3 @@ -25,7 +25,6 @@
    40.4  
    40.5  package jdk.nashorn.internal.runtime.linker;
    40.6  
    40.7 -import jdk.nashorn.internal.runtime.Context;
    40.8  import jdk.nashorn.internal.runtime.ECMAErrors;
    40.9  import org.dynalang.dynalink.CallSiteDescriptor;
   40.10  import org.dynalang.dynalink.beans.BeansLinker;
   40.11 @@ -94,7 +93,7 @@
   40.12  
   40.13      private static GuardedInvocation checkNullConstructor(final GuardedInvocation ctorInvocation, final Class<?> receiverClass) {
   40.14          if(ctorInvocation == null) {
   40.15 -            ECMAErrors.typeError(Context.getGlobal(), "no.constructor.matches.args", receiverClass.getName());
   40.16 +            ECMAErrors.typeError("no.constructor.matches.args", receiverClass.getName());
   40.17          }
   40.18          return ctorInvocation;
   40.19      }

mercurial