8015814: loadWithNewGlobal needs to wrap createGlobal in AccessController.doPrivileged
authorjlaskey
Mon, 03 Jun 2013 12:57:53 -0300
changeset 17976 5615a31822a1
parent 17975 2fd9facd0169
child 17977 b7b3454fa026
8015814: loadWithNewGlobal needs to wrap createGlobal in AccessController.doPrivileged Reviewed-by: sundar Contributed-by: james.laskey@oracle.com
nashorn/src/jdk/nashorn/internal/runtime/Context.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Mon Jun 03 11:16:33 2013 -0300
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Mon Jun 03 12:57:53 2013 -0300
@@ -500,9 +500,21 @@
      *
      * @throws IOException if source cannot be found or loaded
      */
-    public Object loadWithNewGlobal(final Object from) throws IOException {
+    public Object loadWithNewGlobal(final Object from) throws IOException, RuntimeException {
         final ScriptObject oldGlobal = getGlobalTrusted();
-        final ScriptObject newGlobal = createGlobal();
+        final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() {
+           @Override
+           public ScriptObject run() {
+               try {
+                   return createGlobal();
+               } catch (final RuntimeException e) {
+                   if (Context.DEBUG) {
+                       e.printStackTrace();
+                   }
+                   throw e;
+               }
+           }
+        });
         setGlobalTrusted(newGlobal);
 
         try {