提交 c86e1caa 编写于 作者: S sundar

6980447: Rhino JavaScript engine code in jdk-7 has to updated with the latest...

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
上级 3ca4f57a
......@@ -61,26 +61,43 @@ public final class RhinoScriptEngine extends AbstractScriptEngine
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 @@ public final class RhinoScriptEngine extends AbstractScriptEngine
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 @@ public final class RhinoScriptEngine extends AbstractScriptEngine
engine.eval(r);
System.out.println(engine.get("x"));
}
*/
}
......@@ -58,11 +58,11 @@ public class RhinoScriptEngineFactory extends ScriptEngineFactoryBase {
} 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 @@ public class RhinoScriptEngineFactory extends ScriptEngineFactoryBase {
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;
......
......@@ -37,15 +37,6 @@ import javax.script.*;
* @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 @@ public final class RhinoTopLevel extends ImporterTopLevel {
String names[] = { "bindings", "scope", "sync" };
defineFunctionProperties(names, RhinoTopLevel.class,
ScriptableObject.DONTENUM);
// define built-in variables
cx.evaluateString(this, builtinVariables, "<builtin>", 1, null);
}
/**
......
......@@ -311,9 +311,9 @@ function load(str) {
try {
engine.eval(reader);
} finally {
engine.put(engine.FILENAME, oldFilename);
engine.put(engine.FILENAME, oldFilename);
streamClose(stream);
}
streamClose(stream);
}
// file system utilities
......
/*
* 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??");
}
}
......@@ -32,8 +32,8 @@ import java.io.*;
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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册