aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsundar <none@none>2014-05-02 19:15:59 +0530
committersundar <none@none>2014-05-02 19:15:59 +0530
commitac2119fd92bbabe7b7b166f601e1a6313511e7bf (patch)
treecdf4da26e4adf19e44d1a3927cb38b2d0afb0e43 /src
parent01e9abb7690543c0f898556cfa5820a46004dec4 (diff)
downloadnashorn-ac2119fd92bbabe7b7b166f601e1a6313511e7bf.tar.gz
8027933: Add --const-as-var option
Reviewed-by: jlaskey, hannesw
Diffstat (limited to 'src')
-rw-r--r--src/jdk/nashorn/internal/parser/Parser.java12
-rw-r--r--src/jdk/nashorn/internal/parser/TokenType.java2
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptEnvironment.java4
-rw-r--r--src/jdk/nashorn/internal/runtime/resources/Options.properties7
4 files changed, 24 insertions, 1 deletions
diff --git a/src/jdk/nashorn/internal/parser/Parser.java b/src/jdk/nashorn/internal/parser/Parser.java
index 08ff725a..6ad60b58 100644
--- a/src/jdk/nashorn/internal/parser/Parser.java
+++ b/src/jdk/nashorn/internal/parser/Parser.java
@@ -33,6 +33,7 @@ import static jdk.nashorn.internal.parser.TokenType.CASE;
import static jdk.nashorn.internal.parser.TokenType.CATCH;
import static jdk.nashorn.internal.parser.TokenType.COLON;
import static jdk.nashorn.internal.parser.TokenType.COMMARIGHT;
+import static jdk.nashorn.internal.parser.TokenType.CONST;
import static jdk.nashorn.internal.parser.TokenType.DECPOSTFIX;
import static jdk.nashorn.internal.parser.TokenType.DECPREFIX;
import static jdk.nashorn.internal.parser.TokenType.ELSE;
@@ -849,6 +850,11 @@ loop:
expect(SEMICOLON);
break;
default:
+ if (env._const_as_var && type == CONST) {
+ variableStatement(true);
+ break;
+ }
+
if (type == IDENT || isNonStrictModeIdent()) {
if (T(k + 1) == COLON) {
labelStatement();
@@ -1110,6 +1116,12 @@ loop:
case SEMICOLON:
break;
default:
+ if (env._const_as_var && type == CONST) {
+ // Var statements captured in for outer block.
+ vars = variableStatement(false);
+ break;
+ }
+
final Expression expression = expression(unaryExpression(), COMMARIGHT.getPrecedence(), true);
forNode = forNode.setInit(lc, expression);
break;
diff --git a/src/jdk/nashorn/internal/parser/TokenType.java b/src/jdk/nashorn/internal/parser/TokenType.java
index 5c696cb9..59005077 100644
--- a/src/jdk/nashorn/internal/parser/TokenType.java
+++ b/src/jdk/nashorn/internal/parser/TokenType.java
@@ -111,7 +111,7 @@ public enum TokenType {
CATCH (KEYWORD, "catch"),
// CHAR (FUTURE, "char"),
CLASS (FUTURE, "class"),
- CONST (FUTURE, "const"),
+ CONST (KEYWORD, "const"),
CONTINUE (KEYWORD, "continue"),
DEBUGGER (KEYWORD, "debugger"),
DEFAULT (KEYWORD, "default"),
diff --git a/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java b/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
index 96982011..445106d7 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
@@ -62,6 +62,9 @@ public final class ScriptEnvironment {
/** Only compile script, do not run it or generate other ScriptObjects */
public final boolean _compile_only;
+ /** Accept "const" keyword and treat it as variable. Interim feature */
+ public final boolean _const_as_var;
+
/** Accumulated callsite flags that will be used when bootstrapping script callsites */
public final int _callsite_flags;
@@ -200,6 +203,7 @@ public final class ScriptEnvironment {
_class_cache_size = options.getInteger("class.cache.size");
_compile_only = options.getBoolean("compile.only");
+ _const_as_var = options.getBoolean("const.as.var");
_debug_lines = options.getBoolean("debug.lines");
_dest_dir = options.getString("d");
_dump_on_error = options.getBoolean("doe");
diff --git a/src/jdk/nashorn/internal/runtime/resources/Options.properties b/src/jdk/nashorn/internal/runtime/resources/Options.properties
index 033fcc25..9262a401 100644
--- a/src/jdk/nashorn/internal/runtime/resources/Options.properties
+++ b/src/jdk/nashorn/internal/runtime/resources/Options.properties
@@ -102,6 +102,13 @@ nashorn.option.compile.only = { \
type=Boolean \
}
+nashorn.option.const.as.var = { \
+ name="--const-as-var", \
+ is_undocumented=true, \
+ desc="Replace 'const' with 'var'.", \
+ type=Boolean \
+}
+
nashorn.option.d = { \
name="--dump-debug-dir", \
short_name="-d", \