Mercurial > hg > openjdk > jigsaw > nashorn
changeset 106:671852e35ced
8008166: URL handling was broken on windows, causing "load" to malfunction
Reviewed-by: attila, jlaskey
Contributed-by: klara.ward@oracle.com
author | lagergren |
---|---|
date | Wed, 20 Feb 2013 16:43:21 +0100 |
parents | 58eea0e8f369 |
children | a971adb68f38 |
files | make/build.xml src/jdk/nashorn/internal/runtime/Context.java |
diffstat | 2 files changed, 22 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/make/build.xml Wed Feb 20 17:08:32 2013 +0530 +++ b/make/build.xml Wed Feb 20 16:43:21 2013 +0100 @@ -211,6 +211,8 @@ <echo message="" file="${build.dir}/nashorn.policy" append="true"/> <!-- test/script/basic .js scripts load other script tests --> <echo message=" permission java.io.FilePermission "${basedir}/test/script/-", "read";" file="${build.dir}/nashorn.policy" append="true"/> + <echo message=" permission java.io.FilePermission "user.dir", "read";" file="${build.dir}/nashorn.policy" append="true"/> + <echo message=" permission java.util.PropertyPermission "user.dir", "read";" file="${build.dir}/nashorn.policy" append="true"/> <echo message="" file="${build.dir}/nashorn.policy" append="true"/> <!-- test/script/basic .js scripts can read nashorn.test.* properties --> <echo message=" permission java.util.PropertyPermission "nashorn.test.*", "read";" file="${build.dir}/nashorn.policy" append="true"/>
--- a/src/jdk/nashorn/internal/runtime/Context.java Wed Feb 20 17:08:32 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/Context.java Wed Feb 20 16:43:21 2013 +0100 @@ -37,7 +37,6 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; -import java.net.MalformedURLException; import java.net.URL; import java.security.AccessController; import java.security.CodeSigner; @@ -620,34 +619,28 @@ // load accepts a String (which could be a URL or a file name), a File, a URL // or a ScriptObject that has "name" and "source" (string valued) properties. if (src instanceof String) { - String srcStr = (String)src; - final File file = new File((String)src); + final String srcStr = (String)src; + final File file = new File(srcStr); if (srcStr.indexOf(':') != -1) { - try { - final URL url = new URL((String)src); + if (srcStr.startsWith("nashorn:")) { + final String resource = "resources/" + srcStr.substring("nashorn:".length()); + // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme + // These scripts are always available and are loaded from nashorn.jar's resources. + source = AccessController.doPrivileged( + new PrivilegedAction<Source>() { + @Override + public Source run() { + try { + final URL resURL = Context.class.getResource(resource); + return (resURL != null)? new Source(srcStr, resURL) : null; + } catch (final IOException exp) { + return null; + } + } + }); + } else { + final URL url = file.toURI().toURL(); source = new Source(url.toString(), url); - } catch (final MalformedURLException e) { - // fallback URL - nashorn:foo.js - check under jdk/nashorn/internal/runtime/resources - final String str = (String)src; - if (str.startsWith("nashorn:")) { - final String resource = "resources/" + str.substring("nashorn:".length()); - // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme - // These scripts are always available and are loaded from nashorn.jar's resources. - source = AccessController.doPrivileged( - new PrivilegedAction<Source>() { - @Override - public Source run() { - try { - final URL resURL = Context.class.getResource(resource); - return (resURL != null)? new Source(str, resURL) : null; - } catch (final IOException exp) { - return null; - } - } - }); - } else { - throw e; - } } } else if (file.isFile()) { source = new Source(srcStr, file);