From 8eb9871445f67baab3756d3dc506a0c4be4131d9 Mon Sep 17 00:00:00 2001 From: Greg Brail Date: Sat, 14 Dec 2024 17:15:24 -0800 Subject: [PATCH] Address code review comments Add VERSION_ECMASCRIPT, which is clearer. --- .../javascript/engine/RhinoScriptEngine.java | 4 ++-- .../org/mozilla/javascript/tools/debugger/Main.java | 2 +- .../javascript/tools/shell/ShellContextFactory.java | 2 +- .../org/mozilla/javascript/CompilerEnvirons.java | 2 +- .../main/java/org/mozilla/javascript/Context.java | 13 ++++++++++--- 5 files changed, 15 insertions(+), 8 deletions(-) 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..b456ada619 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 @@ -60,7 +60,7 @@ public class RhinoScriptEngine extends AbstractScriptEngine implements Compilabl */ public static final String OPTIMIZATION_LEVEL = "org.mozilla.javascript.optimization_level"; - static final int DEFAULT_LANGUAGE_VERSION = Context.VERSION_ES6; + static final int DEFAULT_LANGUAGE_VERSION = Context.VERSION_ECMASCRIPT; private static final int DEFAULT_OPT = 9; private static final boolean DEFAULT_DEBUG = true; private static final String DEFAULT_FILENAME = "eval"; @@ -326,7 +326,7 @@ protected boolean hasFeature(Context cx, int featureIndex) { @Override protected void onContextCreated(Context cx) { - cx.setLanguageVersion(Context.VERSION_ES6); + cx.setLanguageVersion(Context.VERSION_ECMASCRIPT); cx.setOptimizationLevel(DEFAULT_OPT); cx.setGeneratingDebug(DEFAULT_DEBUG); } diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Main.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Main.java index 598cf659b3..38da7f1c1f 100644 --- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Main.java +++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Main.java @@ -169,7 +169,7 @@ public static void main(String[] args) { main.attachTo(org.mozilla.javascript.tools.shell.Main.shellContextFactory); try (Context cx = Context.enter()) { - cx.setLanguageVersion(Context.VERSION_ES6); + cx.setLanguageVersion(Context.VERSION_ECMASCRIPT); Global global = org.mozilla.javascript.tools.shell.Main.getGlobal(); global.init(cx); 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..36d1d99dc7 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 @@ -13,7 +13,7 @@ public class ShellContextFactory extends ContextFactory { private boolean strictMode; private boolean warningAsError; - private int languageVersion = Context.VERSION_ES6; + private int languageVersion = Context.VERSION_ECMASCRIPT; private int optimizationLevel; private boolean generatingDebug; private boolean allowReservedKeywords = true; diff --git a/rhino/src/main/java/org/mozilla/javascript/CompilerEnvirons.java b/rhino/src/main/java/org/mozilla/javascript/CompilerEnvirons.java index acfe73fd66..e19d2d25a4 100644 --- a/rhino/src/main/java/org/mozilla/javascript/CompilerEnvirons.java +++ b/rhino/src/main/java/org/mozilla/javascript/CompilerEnvirons.java @@ -12,7 +12,7 @@ public class CompilerEnvirons { public CompilerEnvirons() { errorReporter = DefaultErrorReporter.instance; - languageVersion = Context.VERSION_ES6; + languageVersion = Context.VERSION_ECMASCRIPT; generateDebugInfo = true; reservedKeywordAsIdentifier = true; allowMemberExprAsFunctionName = false; diff --git a/rhino/src/main/java/org/mozilla/javascript/Context.java b/rhino/src/main/java/org/mozilla/javascript/Context.java index 8bf8e89b16..cb039b7ce5 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Context.java +++ b/rhino/src/main/java/org/mozilla/javascript/Context.java @@ -104,15 +104,22 @@ public class Context implements Closeable { /** JavaScript 1.8 */ public static final int VERSION_1_8 = 180; + /** + * Old constant for ECMAScript 6 and after. This has been replaced with the more clearly-named + * {@link #VERSION_ECMASCRIPT}. Both constants have the same value, and this is retained for + * compatibility. + */ + public static final int VERSION_ES6 = 200; + /** * ECMAScript 6 and after. Since around version 1.7, this has been used to denote most new - * language features. + * language features. This has the same value as {@link #VERSION_ES6}. * *

As of version 1.8, the Rhino community has no plans to continue adding new language * versions, but instead plans to track the ECMAScript specification as it evolves and add new * features in new versions of Rhino. */ - public static final int VERSION_ES6 = 200; + public static final int VERSION_ECMASCRIPT = VERSION_ES6; /** * Controls behaviour of Date.prototype.getYear(). If @@ -407,7 +414,7 @@ protected Context(ContextFactory factory) { throw new IllegalArgumentException("factory == null"); } this.factory = factory; - version = VERSION_ES6; + version = VERSION_ECMASCRIPT; optimizationLevel = codegenClass != null ? 0 : -1; maximumInterpreterStackDepth = Integer.MAX_VALUE; }