6980447: Rhino JavaScript engine code in jdk-7 has to updated with the latest code from Rhino 1.7R3.
Summary: Updating Rhino javascript engine with version 1.7R3. Issue 6427783 (E4X support is missing from Sun's Mozilla JavaScript implementation) is also fixed as a side-effect.
Reviewed-by: alanb, jjh
--- a/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java Wed Dec 15 22:42:37 2010 -0800
+++ b/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java Thu Dec 16 20:52:09 2010 +0530
@@ -61,26 +61,43 @@
private ScriptEngineFactory factory;
private InterfaceImplementor implementor;
+ private static final int languageVersion = getLanguageVersion();
+ private static final int optimizationLevel = getOptimizationLevel();
static {
ContextFactory.initGlobal(new ContextFactory() {
protected Context makeContext() {
Context cx = super.makeContext();
+ cx.setLanguageVersion(languageVersion);
+ cx.setOptimizationLevel(optimizationLevel);
cx.setClassShutter(RhinoClassShutter.getInstance());
cx.setWrapFactory(RhinoWrapFactory.getInstance());
return cx;
}
-
- public boolean hasFeature(Context cx, int feature) {
- // we do not support E4X (ECMAScript for XML)!
- if (feature == Context.FEATURE_E4X) {
- return false;
- } else {
- return super.hasFeature(cx, feature);
- }
- }
});
}
+ private static final String RHINO_JS_VERSION = "rhino.js.version";
+ private static int getLanguageVersion() {
+ int version;
+ String tmp = java.security.AccessController.doPrivileged(
+ new sun.security.action.GetPropertyAction(RHINO_JS_VERSION));
+ if (tmp != null) {
+ version = Integer.parseInt((String)tmp);
+ } else {
+ version = Context.VERSION_1_8;
+ }
+ return version;
+ }
+
+ private static final String RHINO_OPT_LEVEL = "rhino.opt.level";
+ private static int getOptimizationLevel() {
+ int optLevel = -1;
+ // disable optimizer under security manager, for now.
+ if (System.getSecurityManager() == null) {
+ optLevel = Integer.getInteger(RHINO_OPT_LEVEL, -1);
+ }
+ return optLevel;
+ }
/**
* Creates a new instance of RhinoScriptEngine
@@ -333,6 +350,7 @@
return result instanceof Undefined ? null : result;
}
+ /*
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("No file specified");
@@ -347,4 +365,5 @@
engine.eval(r);
System.out.println(engine.get("x"));
}
+ */
}
--- a/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngineFactory.java Wed Dec 15 22:42:37 2010 -0800
+++ b/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngineFactory.java Thu Dec 16 20:52:09 2010 +0530
@@ -58,11 +58,11 @@
} else if (key.equals(ScriptEngine.ENGINE)) {
return "Mozilla Rhino";
} else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
- return "1.6 release 2";
+ return "1.7 release 3 PRERELEASE";
} else if (key.equals(ScriptEngine.LANGUAGE)) {
return "ECMAScript";
} else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
- return "1.6";
+ return "1.8";
} else if (key.equals("THREADING")) {
return "MULTITHREADED";
} else {
@@ -128,10 +128,12 @@
return ret;
}
+ /*
public static void main(String[] args) {
RhinoScriptEngineFactory fact = new RhinoScriptEngineFactory();
System.out.println(fact.getParameter(ScriptEngine.ENGINE_VERSION));
}
+ */
private static List<String> names;
private static List<String> mimeTypes;
--- a/jdk/src/share/classes/com/sun/script/javascript/RhinoTopLevel.java Wed Dec 15 22:42:37 2010 -0800
+++ b/jdk/src/share/classes/com/sun/script/javascript/RhinoTopLevel.java Thu Dec 16 20:52:09 2010 +0530
@@ -37,15 +37,6 @@
* @since 1.6
*/
public final class RhinoTopLevel extends ImporterTopLevel {
-
- // variables defined always to help Java access from JavaScript
- private static final String builtinVariables =
- "var com = Packages.com; \n" +
- "var edu = Packages.edu; \n" +
- "var javax = Packages.javax; \n" +
- "var net = Packages.net; \n" +
- "var org = Packages.org; \n";
-
RhinoTopLevel(Context cx, RhinoScriptEngine engine) {
super(cx);
this.engine = engine;
@@ -67,9 +58,6 @@
String names[] = { "bindings", "scope", "sync" };
defineFunctionProperties(names, RhinoTopLevel.class,
ScriptableObject.DONTENUM);
-
- // define built-in variables
- cx.evaluateString(this, builtinVariables, "<builtin>", 1, null);
}
/**
--- a/jdk/src/share/classes/com/sun/tools/script/shell/init.js Wed Dec 15 22:42:37 2010 -0800
+++ b/jdk/src/share/classes/com/sun/tools/script/shell/init.js Thu Dec 16 20:52:09 2010 +0530
@@ -311,9 +311,9 @@
try {
engine.eval(reader);
} finally {
- engine.put(engine.FILENAME, oldFilename);
+ engine.put(engine.FILENAME, oldFilename);
+ streamClose(stream);
}
- streamClose(stream);
}
// file system utilities
--- a/jdk/test/javax/script/E4XErrorTest.java Wed Dec 15 22:42:37 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6346734 6705893
- * @summary We do *not* support E4X (ECMAScript for XML) in our
- * implementation. We want to throw error on XML literals
- * as early as possible rather than at "runtime" - i.e., when
- * engine looks for "XML" constructor.
- */
-
-import javax.script.*;
-import java.util.Locale;
-
-public class E4XErrorTest {
-
- public static void main(String[] args) throws Exception {
- ScriptEngineManager manager = new ScriptEngineManager();
- ScriptEngine jsengine = Helper.getJsEngine(manager);
- if (jsengine == null) {
- System.out.println("Warning: No js engine found; test vacuously passes.");
- return;
- }
-
- // The test below depends on the error message content
- // that is loaded from resource bundles. So, we force
- // English Locale to compare correct value..
- Locale.setDefault(Locale.US);
-
- try {
- jsengine.eval("var v = <html></html>;");
- } catch (ScriptException se) {
- String msg = se.getMessage();
- if (msg.indexOf("syntax error") == -1) {
- throw new RuntimeException("syntax error expected, got " +
- msg);
- }
- return;
- }
- // should not reach here.. exception should have been thrown.
- throw new RuntimeException("Huh! E4X is supported??");
- }
-}
--- a/jdk/test/javax/script/VersionTest.java Wed Dec 15 22:42:37 2010 -0800
+++ b/jdk/test/javax/script/VersionTest.java Thu Dec 16 20:52:09 2010 +0530
@@ -32,8 +32,8 @@
public class VersionTest {
- private static final String JS_LANG_VERSION = "1.6";
- private static final String JS_ENGINE_VERSION = "1.6 release 2";
+ private static final String JS_LANG_VERSION = "1.8";
+ private static final String JS_ENGINE_VERSION = "1.7 release 3 PRERELEASE";
public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();