diff --git a/nashorn/src/jdk/nashorn/internal/runtime/Context.java b/nashorn/src/jdk/nashorn/internal/runtime/Context.java index 392d6f432e2abb30798c1bf9449ad64c486629ac..e75bb1b51e21a23e11cb1d8e4e70526c0abdc416 100644 --- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java +++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java @@ -500,9 +500,21 @@ public final class Context { * * @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() { + @Override + public ScriptObject run() { + try { + return createGlobal(); + } catch (final RuntimeException e) { + if (Context.DEBUG) { + e.printStackTrace(); + } + throw e; + } + } + }); setGlobalTrusted(newGlobal); try {