jdk8/jdk8/nashorn: 8f7a86f82376 (original) (raw)
OpenJDK / jdk8 / jdk8 / nashorn
changeset 51:8f7a86f82376
8006983: Introduce a command line option to switch off syntactic extensions of nashorn Reviewed-by: lagergren, attila
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/objects/Global.java Fri Jan 25 17:35:31 2013 +0100 +++ b/src/jdk/nashorn/internal/objects/Global.java Mon Jan 28 18:10:16 2013 +0530 @@ -1456,8 +1456,8 @@ value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE); addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value);
value = ScriptFunctionImpl.makeFunction("read", ScriptingFunctions.READ);[](#l1.7)
addOwnProperty("read", Attribute.NOT_ENUMERABLE, value);[](#l1.8)
value = ScriptFunctionImpl.makeFunction("readFully", ScriptingFunctions.READFULLY);[](#l1.9)
addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value);[](#l1.10)
value = ScriptFunctionImpl.makeFunction("quit", ScriptingFunctions.QUIT); addOwnProperty("quit", Attribute.NOT_ENUMERABLE, value);
--- a/src/jdk/nashorn/internal/parser/Parser.java Fri Jan 25 17:35:31 2013 +0100 +++ b/src/jdk/nashorn/internal/parser/Parser.java Mon Jan 28 18:10:16 2013 +0530 @@ -147,7 +147,7 @@ public FunctionNode parse(final String scriptName) { try { stream = new TokenStream();
lexer = new Lexer(source, stream, context._scripting);[](#l2.7)
lexer = new Lexer(source, stream, context._scripting && !context._no_syntax_extensions);[](#l2.8)
// Set up first token (skips opening EOL.) k = -1; @@ -1065,7 +1065,7 @@ // Nashorn extension: for each expression. // iterate property values rather than property names.
if (type == IDENT && "each".equals(getValue())) {[](#l2.16)
if (!context._no_syntax_extensions && type == IDENT && "each".equals(getValue())) {[](#l2.17) forNode.setIsForEach();[](#l2.18) next();[](#l2.19) }[](#l2.20)
@@ -2312,7 +2312,8 @@ arguments = new ArrayList<>(); }
// This is to support the following interface impl. syntax:[](#l2.25)
// Nashorn extension: This is to support the following interface implementation[](#l2.26)
// syntax:[](#l2.27) //[](#l2.28) // var r = new java.lang.Runnable() {[](#l2.29) // run: function() { println("run"); }[](#l2.30)
@@ -2321,7 +2322,7 @@ // The object literal following the "new Constructor()" expresssion // is passed as an additional (last) argument to the constructor.
if (type == LBRACE) {[](#l2.35)
if (!context._no_syntax_extensions && type == LBRACE) {[](#l2.36) arguments.add(objectLiteral());[](#l2.37) }[](#l2.38)
@@ -2475,8 +2476,11 @@ if (type == IDENT || isNonStrictModeIdent()) { name = getIdent(); verifyStrictIdent(name, "function name");
} else if (isStatement && !context._anon_functions) {[](#l2.44)
expect(IDENT);[](#l2.45)
} else if (isStatement) {[](#l2.46)
// Nashorn extension: anonymous function statements[](#l2.47)
if (context._no_syntax_extensions || !context._anon_functions) {[](#l2.48)
expect(IDENT);[](#l2.49)
}[](#l2.50) }[](#l2.51)
// name is null, generate anonymous name @@ -2613,7 +2617,7 @@ functionNode.setFirstToken(firstToken); // Nashorn extension: expression closures
if (type != LBRACE) {[](#l2.58)
if (!context._no_syntax_extensions && type != LBRACE) {[](#l2.59) /*[](#l2.60) * Example:[](#l2.61) *[](#l2.62)
--- a/src/jdk/nashorn/internal/runtime/Context.java Fri Jan 25 17:35:31 2013 +0100 +++ b/src/jdk/nashorn/internal/runtime/Context.java Mon Jan 28 18:10:16 2013 +0530 @@ -229,6 +229,9 @@ /** Create a new class loaded for each compilation */ public final boolean _loader_per_compile;
+ /** Package to which generated class files are added */ public final String _package; @@ -341,29 +344,30 @@ this.out = out; this.err = err;
_anon_functions = options.getBoolean("anon.functions");[](#l3.17)
_class_cache_size = options.getInteger("class.cache.size");[](#l3.18)
_compile_only = options.getBoolean("compile.only");[](#l3.19)
_debug_lines = options.getBoolean("debug.lines");[](#l3.20)
_dest_dir = options.getString("d");[](#l3.21)
_dump_on_error = options.getBoolean("doe");[](#l3.22)
_early_lvalue_error = options.getBoolean("early.lvalue.error");[](#l3.23)
_empty_statements = options.getBoolean("empty.statements");[](#l3.24)
_fullversion = options.getBoolean("fullversion");[](#l3.25)
_loader_per_compile = options.getBoolean("loader.per.compile");[](#l3.26)
_package = options.getString("package");[](#l3.27)
_parse_only = options.getBoolean("parse.only");[](#l3.28)
_print_ast = options.getBoolean("print.ast");[](#l3.29)
_print_lower_ast = options.getBoolean("print.lower.ast");[](#l3.30)
_print_code = options.getBoolean("print.code");[](#l3.31)
_print_no_newline = options.getBoolean("print.no.newline");[](#l3.32)
_print_parse = options.getBoolean("print.parse");[](#l3.33)
_print_lower_parse = options.getBoolean("print.lower.parse");[](#l3.34)
_print_symbols = options.getBoolean("print.symbols");[](#l3.35)
_scripting = options.getBoolean("scripting");[](#l3.36)
_strict = options.getBoolean("strict");[](#l3.37)
_version = options.getBoolean("version");[](#l3.38)
_verify_code = options.getBoolean("verify.code");[](#l3.39)
_anon_functions = options.getBoolean("anon.functions");[](#l3.40)
_class_cache_size = options.getInteger("class.cache.size");[](#l3.41)
_compile_only = options.getBoolean("compile.only");[](#l3.42)
_debug_lines = options.getBoolean("debug.lines");[](#l3.43)
_dest_dir = options.getString("d");[](#l3.44)
_dump_on_error = options.getBoolean("doe");[](#l3.45)
_early_lvalue_error = options.getBoolean("early.lvalue.error");[](#l3.46)
_empty_statements = options.getBoolean("empty.statements");[](#l3.47)
_fullversion = options.getBoolean("fullversion");[](#l3.48)
_loader_per_compile = options.getBoolean("loader.per.compile");[](#l3.49)
_no_syntax_extensions = options.getBoolean("no.syntax.extensions");[](#l3.50)
_package = options.getString("package");[](#l3.51)
_parse_only = options.getBoolean("parse.only");[](#l3.52)
_print_ast = options.getBoolean("print.ast");[](#l3.53)
_print_lower_ast = options.getBoolean("print.lower.ast");[](#l3.54)
_print_code = options.getBoolean("print.code");[](#l3.55)
_print_no_newline = options.getBoolean("print.no.newline");[](#l3.56)
_print_parse = options.getBoolean("print.parse");[](#l3.57)
_print_lower_parse = options.getBoolean("print.lower.parse");[](#l3.58)
_print_symbols = options.getBoolean("print.symbols");[](#l3.59)
_scripting = options.getBoolean("scripting");[](#l3.60)
_strict = options.getBoolean("strict");[](#l3.61)
_version = options.getBoolean("version");[](#l3.62)
_verify_code = options.getBoolean("verify.code");[](#l3.63)
int callSiteFlags = 0; if (options.getBoolean("profile.callsites")) {
--- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Fri Jan 25 17:35:31 2013 +0100 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Mon Jan 28 18:10:16 2013 +0530 @@ -44,8 +44,8 @@ /** Handle to implementation of {@link ScriptingFunctions#read} - Nashorn extension */ public static final MethodHandle READLINE = findOwnMH("readLine", Object.class, Object.class);
- /** Handle to implementation of {@link ScriptingFunctions#read} - Nashorn extension */
- public static final MethodHandle READ = findOwnMH("read", Object.class, Object.class, Object.class);
- /** Handle to implementation of {@link ScriptingFunctions#readFully} - Nashorn extension */
- public static final MethodHandle READFULLY = findOwnMH("readFully", Object.class, Object.class, Object.class);
/** Handle to implementation of {@link ScriptingFunctions#read} - Nashorn extension */ public static final MethodHandle QUIT = findOwnMH("quit", Object.class, Object.class, Object.class); @@ -78,7 +78,7 @@ * * @throws IOException if an exception occurs */
- public static Object readFully(final Object self, final Object file) throws IOException { File f = null;
--- a/src/jdk/nashorn/internal/runtime/resources/Options.properties Fri Jan 25 17:35:31 2013 +0100 +++ b/src/jdk/nashorn/internal/runtime/resources/Options.properties Mon Jan 28 18:10:16 2013 +0530 @@ -172,6 +172,14 @@ default=true [](#l5.4) } +nashorn.option.no.syntax.extensions = { [](#l5.7)
- name="--no-syntax-extensions", [](#l5.8)
- short_name="--nse", [](#l5.9)
- is_undocumented=true, [](#l5.10)
- desc="No non-standard syntax extensions", [](#l5.11)
- default=-anon-functions=false [](#l5.12)
+} + nashorn.option.package = { [](#l5.15) name="--package", [](#l5.16) is_undocumented=true, [](#l5.17)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8006983.js Mon Jan 28 18:10:16 2013 +0530 @@ -0,0 +1,85 @@ +/*
- or visit www.oracle.com if you need additional information or have any
- */ + +/**
- *
- */ + +try {
- eval("var r = new java.lang.Runnable() { run: function(){} }");
- fail("should have thrown error for anon-class-style new");
- eval("for each (i in [22, 33, 33]) { print(i) }");
- fail("should have thrown error for-each statement");
--- a/test/script/basic/scripting.js Fri Jan 25 17:35:31 2013 +0100 +++ b/test/script/basic/scripting.js Mon Jan 28 18:10:16 2013 +0530 @@ -78,4 +78,4 @@ print(y); -print(read(FILE)); +print(readFully(FILE));
--- a/test/script/basic/scripting.js.EXPECTED Fri Jan 25 17:35:31 2013 +0100 +++ b/test/script/basic/scripting.js.EXPECTED Mon Jan 28 18:10:16 2013 +0530 @@ -99,5 +99,5 @@ print(y); -print(read(FILE)); +print(readFully(FILE));