diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java
index 2e943bb443..9071d4f7bb 100644
--- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java
+++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java
@@ -22,7 +22,6 @@ public static class AbstractClassState {
public void init()
throws IllegalAccessException, InvocationTargetException, InstantiationException {
cx = Context.enter();
- cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = cx.initStandardObjects();
diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/MathBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/MathBenchmark.java
index 427e5a9897..e298919eff 100644
--- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/MathBenchmark.java
+++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/MathBenchmark.java
@@ -36,7 +36,6 @@ public static class MathState {
@Setup(Level.Trial)
public void setup() throws IOException {
cx = Context.enter();
- cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = cx.initStandardObjects();
diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/ObjectBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/ObjectBenchmark.java
index 53ed05195d..269469a2f1 100644
--- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/ObjectBenchmark.java
+++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/ObjectBenchmark.java
@@ -37,7 +37,6 @@ public static class FieldTestState {
@SuppressWarnings("unused")
public void create() throws IOException {
cx = Context.enter();
- cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = new Global(cx);
diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/PropertyBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/PropertyBenchmark.java
index 329e39a15d..402f003934 100644
--- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/PropertyBenchmark.java
+++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/PropertyBenchmark.java
@@ -27,7 +27,6 @@ public static class PropertyState {
@Setup(Level.Trial)
public void setup() throws IOException {
cx = Context.enter();
- cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = cx.initStandardObjects();
diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java
index 55a181b75f..12555f6c0a 100644
--- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java
+++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java
@@ -26,7 +26,6 @@ abstract static class AbstractState {
public void setUp() {
cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_ES6);
- cx.setOptimizationLevel(9);
scope = cx.initStandardObjects();
try (FileReader rdr = new FileReader(fileName)) {
diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/V8Benchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/V8Benchmark.java
index 5b7f92a483..9c38ffe717 100644
--- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/V8Benchmark.java
+++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/V8Benchmark.java
@@ -41,7 +41,6 @@ void evaluateSource(Context cx, Scriptable scope, String fileName) {
void initialize() {
cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_ES6);
- cx.setOptimizationLevel(9);
scope = cx.initStandardObjects();
evaluateSource(cx, scope, "testsrc/benchmarks/framework.js");
}
diff --git a/rhino-engine/src/main/java/org/mozilla/javascript/engine/RhinoScriptEngine.java b/rhino-engine/src/main/java/org/mozilla/javascript/engine/RhinoScriptEngine.java
index d49dd44e9b..2058f297b2 100644
--- a/rhino-engine/src/main/java/org/mozilla/javascript/engine/RhinoScriptEngine.java
+++ b/rhino-engine/src/main/java/org/mozilla/javascript/engine/RhinoScriptEngine.java
@@ -54,14 +54,21 @@
public class RhinoScriptEngine extends AbstractScriptEngine implements Compilable, Invocable {
/**
- * Reserved key for the Rhino optimization level. Default is "9," for optimized and compiled
- * code. Set this to "-1" to run Rhino in interpreted mode -- this is much much slower but the
- * only option on platforms like Android that don't support class files.
+ * Reserved key for the Rhino optimization level. This is supported for backward compatibility
+ * -- any value less than zero results in using interpreted mode.
+ *
+ * @deprecated Replaced in 1.8.0; use {@link #INTERPRETED_MODE} instead.
*/
+ @Deprecated
public static final String OPTIMIZATION_LEVEL = "org.mozilla.javascript.optimization_level";
+ /**
+ * Reserved key for interpreted mode, which is much slower than the default compiled mode but
+ * necessary on Android where Rhino can't generate class files.
+ */
+ public static final String INTERPRETED_MODE = "org.mozilla.javascript.interpreted_mode";
+
static final int DEFAULT_LANGUAGE_VERSION = Context.VERSION_ES6;
- private static final int DEFAULT_OPT = 9;
private static final boolean DEFAULT_DEBUG = true;
private static final String DEFAULT_FILENAME = "eval";
@@ -268,6 +275,7 @@ public ScriptEngineFactory getFactory() {
return factory;
}
+ @SuppressWarnings("deprecation")
private void configureContext(Context cx) throws ScriptException {
Object lv = get(ScriptEngine.LANGUAGE_VERSION);
if (lv != null) {
@@ -275,8 +283,13 @@ private void configureContext(Context cx) throws ScriptException {
}
Object ol = get(OPTIMIZATION_LEVEL);
if (ol != null) {
+ // Handle backwardly-compatible "optimization level".
cx.setOptimizationLevel(parseInteger(ol));
}
+ Object interpreted = get(INTERPRETED_MODE);
+ if (interpreted != null) {
+ cx.setInterpretedMode(parseBoolean(interpreted));
+ }
}
private static int parseInteger(Object v) throws ScriptException {
@@ -286,11 +299,21 @@ private static int parseInteger(Object v) throws ScriptException {
} catch (NumberFormatException nfe) {
throw new ScriptException("Invalid number " + v);
}
- } else if (v instanceof Integer) {
- return ((Integer) v).intValue();
- } else {
- throw new ScriptException("Value must be a string or number");
}
+ if (v instanceof Integer) {
+ return (Integer) v;
+ }
+ throw new ScriptException("Value must be a string or number");
+ }
+
+ private static boolean parseBoolean(Object v) throws ScriptException {
+ if (v instanceof String) {
+ return Boolean.parseBoolean((String) v);
+ }
+ if (v instanceof Boolean) {
+ return (Boolean) v;
+ }
+ throw new ScriptException("Value must be a string or boolean");
}
private String getFilename() {
@@ -327,7 +350,6 @@ protected boolean hasFeature(Context cx, int featureIndex) {
@Override
protected void onContextCreated(Context cx) {
cx.setLanguageVersion(Context.VERSION_ES6);
- cx.setOptimizationLevel(DEFAULT_OPT);
cx.setGeneratingDebug(DEFAULT_DEBUG);
}
}
diff --git a/rhino-engine/src/test/java/org/mozilla/javascript/tests/scriptengine/ScriptEngineTest.java b/rhino-engine/src/test/java/org/mozilla/javascript/tests/scriptengine/ScriptEngineTest.java
index 6b8e102737..33c6bc5079 100644
--- a/rhino-engine/src/test/java/org/mozilla/javascript/tests/scriptengine/ScriptEngineTest.java
+++ b/rhino-engine/src/test/java/org/mozilla/javascript/tests/scriptengine/ScriptEngineTest.java
@@ -47,7 +47,7 @@ public void hello() throws ScriptException {
@Test
public void helloInterpreted() throws ScriptException {
- engine.put(RhinoScriptEngine.OPTIMIZATION_LEVEL, -1);
+ engine.put(RhinoScriptEngine.INTERPRETED_MODE, true);
Object result = engine.eval("'Hello, World!';");
assertEquals(result, "Hello, World!");
}
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java
index 7749dd13aa..7a3fe99303 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java
@@ -738,10 +738,10 @@ private static String do_eval(Context cx, StackFrame frame, String expr) {
String resultString;
Debugger saved_debugger = cx.getDebugger();
Object saved_data = cx.getDebuggerContextData();
- int saved_level = cx.getOptimizationLevel();
+ boolean wasInterpreted = cx.isInterpretedMode();
cx.setDebugger(null, null);
- cx.setOptimizationLevel(-1);
+ cx.setInterpretedMode(false);
cx.setGeneratingDebug(false);
try {
Callable script = (Callable) cx.compileString(expr, "", 0, null);
@@ -755,7 +755,7 @@ private static String do_eval(Context cx, StackFrame frame, String expr) {
resultString = exc.getMessage();
} finally {
cx.setGeneratingDebug(true);
- cx.setOptimizationLevel(saved_level);
+ cx.setInterpretedMode(wasInterpreted);
cx.setDebugger(saved_debugger, saved_data);
}
if (resultString == null) {
@@ -874,7 +874,7 @@ public void contextCreated(Context cx) {
Debugger debugger = new DimIProxy(dim, IPROXY_DEBUG);
cx.setDebugger(debugger, contextData);
cx.setGeneratingDebug(true);
- cx.setOptimizationLevel(-1);
+ cx.setInterpretedMode(true);
}
/** Called when a Context is destroyed. */
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/jsc/Main.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/jsc/Main.java
index bd6a61a884..06101cc213 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/jsc/Main.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/jsc/Main.java
@@ -80,8 +80,10 @@ public String[] processOptions(String args[]) {
continue;
}
if ((arg.equals("-opt") || arg.equals("-O")) && ++i < args.length) {
- int optLevel = Integer.parseInt(args[i]);
- compilerEnv.setOptimizationLevel(optLevel);
+ // As of 1.8.0, optimization levels no longer have an effect, but
+ // parse this for backward compatibility with existing scripts.
+ // Technically the optimization level was replaced with "interpreted
+ // mode, but this tool only makes sense in compiled mode.
continue;
}
} catch (NumberFormatException e) {
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Main.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Main.java
index 1393d17ef6..f67d0d8798 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Main.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Main.java
@@ -285,6 +285,8 @@ public static String[] processOptions(String args[]) {
continue;
}
if (arg.equals("-opt") || arg.equals("-O")) {
+ // As of 1.8.0, this bit remains for backward compatibility,
+ // although it is no longer documented in the "help" message.
if (++i == args.length) {
usageError = arg;
break goodUsage;
@@ -296,14 +298,13 @@ public static String[] processOptions(String args[]) {
usageError = args[i];
break goodUsage;
}
- if (opt == -2) {
- // Compatibility with Cocoon Rhino fork
- opt = -1;
- } else if (!Context.isValidOptimizationLevel(opt)) {
- usageError = args[i];
- break goodUsage;
+ if (opt < 0) {
+ shellContextFactory.setInterpretedMode(true);
}
- shellContextFactory.setOptimizationLevel(opt);
+ continue;
+ }
+ if (arg.equals("-int") || arg.equals("-interpreted")) {
+ shellContextFactory.setInterpretedMode(true);
continue;
}
if (arg.equals("-encoding")) {
@@ -551,7 +552,7 @@ static void processFileSecure(Context cx, Scriptable scope, String path, Object
Object source = readFileOrUrl(path, !isClass);
byte[] digest = getDigest(source);
- String key = path + "_" + cx.getOptimizationLevel();
+ String key = path + "_" + (cx.isInterpretedMode() ? "interpreted" : "compiled");
ScriptReference ref = scriptCache.get(key, digest);
Script script = ref != null ? ref.get() : null;
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ShellContextFactory.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ShellContextFactory.java
index 61c96fc17c..cd8ae8ae23 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ShellContextFactory.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ShellContextFactory.java
@@ -14,7 +14,7 @@ public class ShellContextFactory extends ContextFactory {
private boolean strictMode;
private boolean warningAsError;
private int languageVersion = Context.VERSION_ES6;
- private int optimizationLevel;
+ private boolean interpretedMode;
private boolean generatingDebug;
private boolean allowReservedKeywords = true;
private ErrorReporter errorReporter;
@@ -43,7 +43,7 @@ protected boolean hasFeature(Context cx, int featureIndex) {
@Override
protected void onContextCreated(Context cx) {
cx.setLanguageVersion(languageVersion);
- cx.setOptimizationLevel(optimizationLevel);
+ cx.setInterpretedMode(interpretedMode);
if (errorReporter != null) {
cx.setErrorReporter(errorReporter);
}
@@ -67,10 +67,9 @@ public void setLanguageVersion(int version) {
this.languageVersion = version;
}
- public void setOptimizationLevel(int optimizationLevel) {
- Context.checkOptimizationLevel(optimizationLevel);
+ public void setInterpretedMode(boolean interpreted) {
checkNotSealed();
- this.optimizationLevel = optimizationLevel;
+ this.interpretedMode = interpreted;
}
public void setErrorReporter(ErrorReporter errorReporter) {
diff --git a/rhino-tools/src/main/resources/org/mozilla/javascript/tools/resources/Messages.properties b/rhino-tools/src/main/resources/org/mozilla/javascript/tools/resources/Messages.properties
index 154f1e5597..c86cf8d96e 100644
--- a/rhino-tools/src/main/resources/org/mozilla/javascript/tools/resources/Messages.properties
+++ b/rhino-tools/src/main/resources/org/mozilla/javascript/tools/resources/Messages.properties
@@ -34,7 +34,8 @@ msg.shell.usage =\
\ -w Enable warnings.\n\
\ -version 100|110|120|130|140|150|160|170|180|200\n\
\ Set a specific language version.\n\
- \ -opt [-1|0-9] Set optimization level.\n\
+ \ -int \n\
+ \ -interpreted Run in interpreted mode.\n\
\ -f script-filename Execute script file, or "-" for interactive.\n\
\ -e script-source Evaluate inline script.\n\
\ -modules [uri] Add a single path or URL element to the CommonJS\n\
@@ -114,8 +115,6 @@ Usage: java {0} [OPTION]... SOURCE...\n\
Valid options are: \n\
\ -version VERSION Use the specified language version.\n\
\ VERSION should be one of 100|110|120|130|140|150|160|170.\n\
-\ -opt LEVEL Use optimization with the specified level.\n\
-\ LEVEL should be one of 0..9.\n\
\ -debug, -g Include debug information.\n\
\ -nosource Do not include source to function objects.\n\
\ It makes f.toString() useless and violates ECMAScript\n\
diff --git a/rhino/src/main/java/org/mozilla/javascript/CompilerEnvirons.java b/rhino/src/main/java/org/mozilla/javascript/CompilerEnvirons.java
index d6bffde15f..fa9ecb9bf0 100644
--- a/rhino/src/main/java/org/mozilla/javascript/CompilerEnvirons.java
+++ b/rhino/src/main/java/org/mozilla/javascript/CompilerEnvirons.java
@@ -17,7 +17,7 @@ public CompilerEnvirons() {
reservedKeywordAsIdentifier = true;
allowMemberExprAsFunctionName = false;
xmlAvailable = true;
- optimizationLevel = 0;
+ interpretedMode = false;
generatingSource = true;
strictMode = false;
warningAsError = false;
@@ -35,7 +35,7 @@ public void initFromContext(Context cx) {
warningAsError = cx.hasFeature(Context.FEATURE_WARNING_AS_ERROR);
xmlAvailable = cx.hasFeature(Context.FEATURE_E4X);
- optimizationLevel = cx.getOptimizationLevel();
+ interpretedMode = cx.isInterpretedMode();
generatingSource = cx.isGeneratingSource();
activationNames = cx.activationNames;
@@ -98,13 +98,30 @@ public void setXmlAvailable(boolean flag) {
xmlAvailable = flag;
}
+ /**
+ * @deprecated As of 1.8.0, use {@link #isInterpretedMode()} instead.
+ */
+ @Deprecated
public final int getOptimizationLevel() {
- return optimizationLevel;
+ return interpretedMode ? -1 : 9;
+ }
+
+ public final boolean isInterpretedMode() {
+ return interpretedMode;
}
+ /**
+ * @deprecated As of 1.8.0, use {@link #setInterpretedMode(boolean)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("deprecation")
public void setOptimizationLevel(int level) {
Context.checkOptimizationLevel(level);
- this.optimizationLevel = level;
+ interpretedMode = (level < 0);
+ }
+
+ public void setInterpretedMode(boolean interpretedMode) {
+ this.interpretedMode = interpretedMode;
}
public final boolean isGeneratingSource() {
@@ -255,7 +272,7 @@ public static CompilerEnvirons ideEnvirons() {
private boolean reservedKeywordAsIdentifier;
private boolean allowMemberExprAsFunctionName;
private boolean xmlAvailable;
- private int optimizationLevel;
+ private boolean interpretedMode;
private boolean generatingSource;
private boolean strictMode;
private boolean warningAsError;
diff --git a/rhino/src/main/java/org/mozilla/javascript/Context.java b/rhino/src/main/java/org/mozilla/javascript/Context.java
index a28a6e75fb..221e607647 100644
--- a/rhino/src/main/java/org/mozilla/javascript/Context.java
+++ b/rhino/src/main/java/org/mozilla/javascript/Context.java
@@ -393,7 +393,7 @@ protected Context(ContextFactory factory) {
}
this.factory = factory;
version = VERSION_DEFAULT;
- optimizationLevel = codegenClass != null ? 0 : -1;
+ interpretedMode = codegenClass == null;
maximumInterpreterStackDepth = Integer.MAX_VALUE;
}
@@ -1893,14 +1893,11 @@ public final boolean isGeneratingDebug() {
/**
* Specify whether or not debug information should be generated.
*
- *
Setting the generation of debug information on will set the optimization level to zero.
- *
* @since 1.3
*/
public final void setGeneratingDebug(boolean generatingDebug) {
if (sealed) onSealedMutation();
generatingDebugChanged = true;
- if (generatingDebug && getOptimizationLevel() > 0) setOptimizationLevel(0);
this.generatingDebug = generatingDebug;
}
@@ -1930,42 +1927,62 @@ public final void setGeneratingSource(boolean generatingSource) {
/**
* Get the current optimization level.
*
- *
The optimization level is expressed as an integer between -1 and 9.
+ *
The optimization level is expressed as an integer between -1 and 9. Rhino now has only one
+ * optimization level, and we will always return either -1 or 9 here.
*
* @since 1.3
+ * @deprecated As of 1.8.0, use {@link #isInterpretedMode()} instead.
*/
+ @Deprecated
public final int getOptimizationLevel() {
- return optimizationLevel;
+ return interpretedMode ? -1 : 9;
+ }
+
+ /**
+ * Return whether Rhino is running in interpreted mode. In this mode, Rhino does not generate
+ * bytecode, but runs much more slowly. Some platforms, notably Android, use this mode.
+ */
+ public final boolean isInterpretedMode() {
+ return interpretedMode;
}
/**
* Set the current optimization level.
*
- *
The optimization level is expected to be an integer between -1 and 9. Any negative values
- * will be interpreted as -1, and any values greater than 9 will be interpreted as 9. An
- * optimization level of -1 indicates that interpretive mode will always be used. Levels 0
- * through 9 indicate that class files may be generated. Higher optimization levels trade off
- * compile time performance for runtime performance. The optimizer level can't be set greater
- * than -1 if the optimizer package doesn't exist at run time.
+ *
This function previously set multiple modes today. Any value less than zero sets up
+ * interpreted mode, and otherwise we run in compiled mode.
*
* @param optimizationLevel an integer indicating the level of optimization to perform
* @since 1.3
+ * @deprecated As of 1.8.0, use {@link #setInterpretedMode(boolean)} instead.
*/
+ @Deprecated
public final void setOptimizationLevel(int optimizationLevel) {
+ setInterpretedMode(optimizationLevel < 0);
+ }
+
+ /**
+ * Set Rhino to run in interpreted mode. In this mode, Rhino does not generate bytecode, but
+ * runs much more slowly. Some platforms, notably Android, must use this mode because they
+ * cannot generate bytecode.
+ */
+ public final void setInterpretedMode(boolean interpretedMode) {
if (sealed) onSealedMutation();
- if (optimizationLevel == -2) {
- // To be compatible with Cocoon fork
- optimizationLevel = -1;
- }
- checkOptimizationLevel(optimizationLevel);
- if (codegenClass == null) optimizationLevel = -1;
- this.optimizationLevel = optimizationLevel;
+ this.interpretedMode = interpretedMode;
}
+ /**
+ * @deprecated As of 1.8.0, no longer has any use.
+ */
+ @Deprecated
public static boolean isValidOptimizationLevel(int optimizationLevel) {
return -1 <= optimizationLevel && optimizationLevel <= 9;
}
+ /**
+ * @deprecated As of 1.8.0, no longer has any use.
+ */
+ @Deprecated
public static void checkOptimizationLevel(int optimizationLevel) {
if (isValidOptimizationLevel(optimizationLevel)) {
return;
@@ -2006,9 +2023,9 @@ public final int getMaximumInterpreterStackDepth() {
*/
public final void setMaximumInterpreterStackDepth(int max) {
if (sealed) onSealedMutation();
- if (optimizationLevel != -1) {
+ if (!interpretedMode) {
throw new IllegalStateException(
- "Cannot set maximumInterpreterStackDepth when optimizationLevel != -1");
+ "Cannot set maximumInterpreterStackDepth outside interpreted mode");
}
if (max < 1) {
throw new IllegalArgumentException(
@@ -2569,7 +2586,7 @@ private static void notifyDebugger_r(Context cx, DebuggableScript dscript, Strin
private Evaluator createCompiler() {
Evaluator result = null;
- if (optimizationLevel >= 0 && codegenClass != null) {
+ if (!interpretedMode && codegenClass != null) {
result = (Evaluator) Kit.newInstanceOrNull(codegenClass);
}
if (result == null) {
@@ -2718,7 +2735,7 @@ public static boolean isCurrentContextStrict() {
private boolean generatingDebugChanged;
private boolean generatingSource = true;
boolean useDynamicScope;
- private int optimizationLevel;
+ private boolean interpretedMode;
private int maximumInterpreterStackDepth;
private WrapFactory wrapFactory;
Debugger debugger;
diff --git a/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java b/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java
index a810d8cd13..a816f5087b 100644
--- a/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java
+++ b/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java
@@ -168,7 +168,7 @@ public static ScriptableObject initSafeStandardObjects(
NativeGlobal.init(cx, scope, sealed);
NativeArray.init(cx, scope, sealed);
- if (cx.getOptimizationLevel() > 0) {
+ if (!cx.isInterpretedMode()) {
// When optimizing, attempt to fulfill all requests for new Array(N)
// with a higher threshold before switching to a sparse
// representation
diff --git a/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java b/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java
index f079a071a8..08bd386616 100644
--- a/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java
+++ b/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java
@@ -177,10 +177,10 @@ public byte[] compileToClassFile(
private void transform(ScriptNode tree) {
initOptFunctions_r(tree);
- int optLevel = compilerEnv.getOptimizationLevel();
+ boolean optimizing = !compilerEnv.isInterpretedMode();
Map possibleDirectCalls = null;
- if (optLevel > 0) {
+ if (optimizing) {
/*
* Collect all of the contained functions into a hashtable
* so that the call optimizer can access the class name & parameter
@@ -210,7 +210,7 @@ private void transform(ScriptNode tree) {
OptTransformer ot = new OptTransformer(possibleDirectCalls, directCallTargets);
ot.transform(tree, compilerEnv);
- if (optLevel > 0) {
+ if (optimizing) {
new Optimizer().optimize(tree);
}
}
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug482203Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug482203Test.java
index 658c09bcad..26de80223a 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug482203Test.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug482203Test.java
@@ -19,7 +19,7 @@ public class Bug482203Test {
@Test
public void jsApi() throws Exception {
try (Context cx = Context.enter()) {
- cx.setOptimizationLevel(-1);
+ cx.setInterpretedMode(true);
InputStreamReader in =
new InputStreamReader(Bug482203Test.class.getResourceAsStream("Bug482203.js"));
Script script = cx.compileReader(in, "", 1, null);
@@ -42,7 +42,7 @@ public void jsApi() throws Exception {
@Test
public void javaApi() throws Exception {
try (Context cx = Context.enter()) {
- cx.setOptimizationLevel(-1);
+ cx.setInterpretedMode(true);
InputStreamReader in =
new InputStreamReader(Bug482203Test.class.getResourceAsStream("Bug482203.js"));
Script script = cx.compileReader(in, "", 1, null);
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug685403Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug685403Test.java
index 1624eb201c..9c9f49748a 100755
--- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug685403Test.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug685403Test.java
@@ -28,7 +28,7 @@ public class Bug685403Test {
@Before
public void setUp() {
cx = Context.enter();
- cx.setOptimizationLevel(-1);
+ cx.setInterpretedMode(true);
scope = cx.initStandardObjects();
}
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug708801Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug708801Test.java
index a8e884c373..3022e49fa9 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug708801Test.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug708801Test.java
@@ -37,13 +37,10 @@ public class Bug708801Test {
private static final ContextFactory factory =
new ContextFactory() {
- static final int COMPILER_MODE = 9;
-
@Override
protected Context makeContext() {
Context cx = super.makeContext();
cx.setLanguageVersion(Context.VERSION_1_8);
- cx.setOptimizationLevel(COMPILER_MODE);
return cx;
}
};
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug782363Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug782363Test.java
index 92c72c8992..16ff9a19e9 100755
--- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug782363Test.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug782363Test.java
@@ -41,7 +41,6 @@ public class Bug782363Test {
public void setUp() {
cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_1_8);
- cx.setOptimizationLevel(9);
}
@After
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/CatchTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/CatchTest.java
index ee086f6298..50df20797a 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/CatchTest.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/CatchTest.java
@@ -50,7 +50,7 @@ public String doCatchWrappedException(final ClassShutter shutter) throws Excepti
return factory.call(
context -> {
- context.setOptimizationLevel(-1);
+ context.setInterpretedMode(true);
if (shutter != null) {
context.setClassShutter(shutter);
}
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java
index 2f72ee02dc..ac8f64d057 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java
@@ -32,7 +32,7 @@ public void largeMethod() {
_cx -> {
Script script =
_cx.compileString(scriptSource.toString(), "test-source", 1, null);
- if (_cx.getOptimizationLevel() > -1) {
+ if (!_cx.isInterpretedMode()) {
Assert.assertTrue(
script.getClass().getName(),
script.getClass()
@@ -119,7 +119,7 @@ public void largeVarList() {
_cx -> {
Script script =
_cx.compileString(scriptSource.toString(), "test-source", 1, null);
- if (_cx.getOptimizationLevel() > -1) {
+ if (!_cx.isInterpretedMode()) {
Assert.assertTrue(
script.getClass().getName(),
script.getClass()
@@ -188,7 +188,7 @@ public void largeLocalVarList() {
_cx -> {
Script script =
_cx.compileString(scriptSource.toString(), "test-source", 1, null);
- if (_cx.getOptimizationLevel() > -1) {
+ if (!_cx.isInterpretedMode()) {
Assert.assertTrue(
script.getClass().getName(),
script.getClass()
@@ -259,7 +259,7 @@ public void tooManyMethods() {
_cx -> {
Script script =
_cx.compileString(scriptSource.toString(), "test-source", 1, null);
- if (_cx.getOptimizationLevel() > -1) {
+ if (!_cx.isInterpretedMode()) {
Assert.assertTrue(
script.getClass().getName(),
script.getClass()
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ContinuationsApiTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ContinuationsApiTest.java
index 1ae2e5607a..0e0d0d60fb 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/ContinuationsApiTest.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/ContinuationsApiTest.java
@@ -71,7 +71,7 @@ public String h() {
public void setUp() {
try (Context cx = Context.enter()) {
globalScope = cx.initStandardObjects();
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
globalScope.put("myObject", globalScope, Context.javaToJS(new MyClass(), globalScope));
}
}
@@ -80,7 +80,7 @@ public void setUp() {
public void scriptWithContinuations() {
try (Context cx = Context.enter()) {
try {
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
Script script = cx.compileString("myObject.f(3) + 1;", "test source", 1, null);
cx.executeScriptWithContinuations(script, globalScope);
fail("Should throw ContinuationPending");
@@ -99,7 +99,7 @@ public void scriptWithContinuations() {
public void scriptWithMultipleContinuations() {
try (Context cx = Context.enter()) {
try {
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
Script script =
cx.compileString(
"myObject.f(3) + myObject.g(3) + 2;", "test source", 1, null);
@@ -129,7 +129,7 @@ public void scriptWithMultipleContinuations() {
public void scriptWithNestedContinuations() {
try (Context cx = Context.enter()) {
try {
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
Script script =
cx.compileString(
"myObject.g( myObject.f(1) ) + 2;", "test source", 1, null);
@@ -159,7 +159,7 @@ public void scriptWithNestedContinuations() {
public void functionWithContinuations() {
try (Context cx = Context.enter()) {
try {
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
cx.evaluateString(
globalScope,
"function f(a) { return myObject.f(a); }",
@@ -189,7 +189,7 @@ public void functionWithContinuations() {
@Test
public void errorOnEvalCall() {
try (Context cx = Context.enter()) {
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
Script script = cx.compileString("eval('myObject.f(3);');", "test source", 1, null);
cx.executeScriptWithContinuations(script, globalScope);
fail("Should throw IllegalStateException");
@@ -204,7 +204,7 @@ public void errorOnEvalCall() {
public void serializationWithContinuations() throws IOException, ClassNotFoundException {
try (Context cx = Context.enter()) {
try {
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
cx.evaluateString(
globalScope,
"function f(a) { var k = myObject.f(a); var t = []; return k; }",
@@ -255,13 +255,13 @@ public void continuationsPrototypesAndSerialization()
try (Context cx = Context.enter()) {
globalScope = cx.initStandardObjects();
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
globalScope.put(
"myObject", globalScope, Context.javaToJS(new MyClass(), globalScope));
}
try (Context cx = Context.enter()) {
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
cx.evaluateString(
globalScope,
"function f(a) { Number.prototype.blargh = function() {return 'foo';}; var k = myObject.f(a); var t = []; return new Number(8).blargh(); }",
@@ -315,12 +315,12 @@ public void continuationsInlineFunctionsSerialization()
try (Context cx = Context.enter()) {
globalScope = cx.initStandardObjects();
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
globalScope.put("myObject", globalScope, Context.javaToJS(new MyClass(), globalScope));
}
try (Context cx = Context.enter()) {
- cx.setOptimizationLevel(-1); // must use interpreter mode
+ cx.setInterpretedMode(true); // must use interpreter mode
try {
cx.evaluateString(
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/DynamicScopeTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/DynamicScopeTest.java
index f35d7d11be..8cdbc2e788 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/DynamicScopeTest.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/DynamicScopeTest.java
@@ -38,7 +38,6 @@ protected boolean hasFeature(Context cx, int featureIndex) {
protected Context makeContext() {
Context cx = super.makeContext();
cx.setLanguageVersion(Context.VERSION_ES6);
- cx.setOptimizationLevel(0);
return cx;
}
}
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java
index 636655becb..e6add2db78 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java
@@ -20,15 +20,14 @@ public class ErrorPropertiesTest {
static final String LS = System.getProperty("line.separator");
private void testScriptStackTrace(final String script, final String expectedStackTrace) {
- testScriptStackTrace(script, expectedStackTrace, -1);
- testScriptStackTrace(script, expectedStackTrace, 0);
- testScriptStackTrace(script, expectedStackTrace, 1);
+ testScriptStackTrace(script, expectedStackTrace, false);
+ testScriptStackTrace(script, expectedStackTrace, true);
}
private void testScriptStackTrace(
- final String script, final String expectedStackTrace, final int optimizationLevel) {
+ final String script, final String expectedStackTrace, final boolean interpreted) {
try {
- Utils.executeScript(script, optimizationLevel);
+ Utils.executeScript(script, interpreted);
} catch (final RhinoException e) {
Assert.assertEquals(expectedStackTrace, e.getScriptStackTrace());
}
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Issue385Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Issue385Test.java
index 802be5e4aa..9e1746796b 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/Issue385Test.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/Issue385Test.java
@@ -29,7 +29,7 @@ public void setUp() {
cx.setLanguageVersion(Context.VERSION_1_8);
// errors are reported in the parsing stage,
// optimization level doesn't matter
- cx.setOptimizationLevel(-1);
+ cx.setInterpretedMode(true);
}
@After
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java
index 7dedbf2dad..7638cc24bd 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java
@@ -32,7 +32,7 @@ public void equivalentValuesUndefined() throws Exception {
"test",
1,
null);
- assertEquals("" + cx.getOptimizationLevel(), "true true", result);
+ assertEquals("" + cx.isInterpretedMode(), "true true", result);
return null;
});
@@ -56,7 +56,7 @@ public void equivalentValuesNull() throws Exception {
"test",
1,
null);
- assertEquals("" + cx.getOptimizationLevel(), "true true", result);
+ assertEquals("" + cx.isInterpretedMode(), "true true", result);
return null;
});
diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java
index 9991962d94..1886412f36 100644
--- a/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java
+++ b/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java
@@ -91,9 +91,9 @@ public class ToNumberConversionsTest {
public static Collection