aboutsummaryrefslogtreecommitdiff
path: root/test
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 /test
parent01e9abb7690543c0f898556cfa5820a46004dec4 (diff)
downloadnashorn-ac2119fd92bbabe7b7b166f601e1a6313511e7bf.tar.gz
8027933: Add --const-as-var option
Reviewed-by: jlaskey, hannesw
Diffstat (limited to 'test')
-rw-r--r--test/script/basic/JDK-8008448.js1
-rw-r--r--test/script/basic/JDK-8027933.js38
-rw-r--r--test/script/basic/JDK-8027933.js.EXPECTED2
-rw-r--r--test/script/error/JDK-8027933.js31
-rw-r--r--test/script/error/JDK-8027933.js.EXPECTED3
-rw-r--r--test/src/jdk/nashorn/internal/codegen/CompilerTest.java1
-rw-r--r--test/src/jdk/nashorn/internal/parser/ParserTest.java1
-rw-r--r--test/src/jdk/nashorn/internal/runtime/TrustedScriptEngineTest.java15
8 files changed, 92 insertions, 0 deletions
diff --git a/test/script/basic/JDK-8008448.js b/test/script/basic/JDK-8008448.js
index b30e3417..240efd61 100644
--- a/test/script/basic/JDK-8008448.js
+++ b/test/script/basic/JDK-8008448.js
@@ -26,6 +26,7 @@
* Ensure that all parseable files can be parsed using parser API.
*
* @test
+ * @option --const-as-var
* @option -scripting
* @run
*/
diff --git a/test/script/basic/JDK-8027933.js b/test/script/basic/JDK-8027933.js
new file mode 100644
index 00000000..506abc23
--- /dev/null
+++ b/test/script/basic/JDK-8027933.js
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+/**
+ * JDK-8027933: Add const.as.var option
+ *
+ * @test
+ * @option --const-as-var
+ * @run
+ */
+
+const THE_ANSWER = 42;
+print("Answer to all questions: " + THE_ANSWER);
+
+print((function () {
+ const FORTY_TWO = 42;
+ return FORTY_TWO
+})())
diff --git a/test/script/basic/JDK-8027933.js.EXPECTED b/test/script/basic/JDK-8027933.js.EXPECTED
new file mode 100644
index 00000000..cb920ab6
--- /dev/null
+++ b/test/script/basic/JDK-8027933.js.EXPECTED
@@ -0,0 +1,2 @@
+Answer to all questions: 42
+42
diff --git a/test/script/error/JDK-8027933.js b/test/script/error/JDK-8027933.js
new file mode 100644
index 00000000..9b398fa5
--- /dev/null
+++ b/test/script/error/JDK-8027933.js
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+/**
+ * JDK-8027933: Add const.as.var option
+ *
+ * @test/compile-error
+ */
+
+// without --const-as-var the following should fail to compile
+const THE_ANSWER = 42;
diff --git a/test/script/error/JDK-8027933.js.EXPECTED b/test/script/error/JDK-8027933.js.EXPECTED
new file mode 100644
index 00000000..9389a5fc
--- /dev/null
+++ b/test/script/error/JDK-8027933.js.EXPECTED
@@ -0,0 +1,3 @@
+test/script/error/JDK-8027933.js:31:0 Expected an operand but found const
+const THE_ANSWER = 42;
+^
diff --git a/test/src/jdk/nashorn/internal/codegen/CompilerTest.java b/test/src/jdk/nashorn/internal/codegen/CompilerTest.java
index ac438101..14a9cb9c 100644
--- a/test/src/jdk/nashorn/internal/codegen/CompilerTest.java
+++ b/test/src/jdk/nashorn/internal/codegen/CompilerTest.java
@@ -69,6 +69,7 @@ public class CompilerTest {
options.set("print.ast", true);
options.set("print.parse", true);
options.set("scripting", true);
+ options.set("const.as.var", true);
final ErrorManager errors = new ErrorManager() {
@Override
diff --git a/test/src/jdk/nashorn/internal/parser/ParserTest.java b/test/src/jdk/nashorn/internal/parser/ParserTest.java
index 3e10a89e..e47ccee3 100644
--- a/test/src/jdk/nashorn/internal/parser/ParserTest.java
+++ b/test/src/jdk/nashorn/internal/parser/ParserTest.java
@@ -62,6 +62,7 @@ public class ParserTest {
options.set("anon.functions", true);
options.set("parse.only", true);
options.set("scripting", true);
+ options.set("const.as.var", true);
ErrorManager errors = new ErrorManager();
this.context = new Context(options, errors, Thread.currentThread().getContextClassLoader());
diff --git a/test/src/jdk/nashorn/internal/runtime/TrustedScriptEngineTest.java b/test/src/jdk/nashorn/internal/runtime/TrustedScriptEngineTest.java
index 469d890e..f6da6f82 100644
--- a/test/src/jdk/nashorn/internal/runtime/TrustedScriptEngineTest.java
+++ b/test/src/jdk/nashorn/internal/runtime/TrustedScriptEngineTest.java
@@ -220,4 +220,19 @@ public class TrustedScriptEngineTest {
// bar should be visible in default context
assertTrue(e.eval("typeof bar").equals("function"));
}
+
+
+ @Test public void nashornSwallowsConstKeyword() throws Exception {
+ final NashornScriptEngineFactory f = new NashornScriptEngineFactory();
+ final String[] args = new String[] { "--const-as-var" };
+ final ScriptEngine engine = f.getScriptEngine(args);
+
+ final Object ret = engine.eval(""
+ + "(function() {\n"
+ + " const x = 10;\n"
+ + " return x;\n"
+ + "})();"
+ );
+ assertEquals(ret, 10, "Parsed and executed OK");
+ }
}