8039047: Parser accepts conditional catch clauses even when --no-syntax-extensions / -nse option is passed
authorsundar
Wed, 02 Apr 2014 15:52:31 +0530
changeset 23766 a3ef17770bab
parent 23765 0c4a328645ef
child 23767 7c0614b75e23
8039047: Parser accepts conditional catch clauses even when --no-syntax-extensions / -nse option is passed Reviewed-by: lagergren, attila
nashorn/src/jdk/nashorn/internal/parser/Parser.java
nashorn/test/script/error/JDK-8039047.js
nashorn/test/script/error/JDK-8039047.js.EXPECTED
--- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java	Tue Apr 01 17:28:17 2014 -0700
+++ b/nashorn/src/jdk/nashorn/internal/parser/Parser.java	Wed Apr 02 15:52:31 2014 +0530
@@ -1700,9 +1700,11 @@
                 // ECMA 12.4.1 strict mode restrictions
                 verifyStrictIdent(exception, "catch argument");
 
-                // Check for conditional catch.
+                // Nashorn extension: catch clause can have optional
+                // condition. So, a single try can have more than one
+                // catch clause each with it's own condition.
                 final Expression ifExpression;
-                if (type == IF) {
+                if (!env._no_syntax_extensions && type == IF) {
                     next();
                     // Get the exception condition.
                     ifExpression = expression();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/error/JDK-8039047.js	Wed Apr 02 15:52:31 2014 +0530
@@ -0,0 +1,35 @@
+/*
+ * 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-8039047: Parser accepts conditional catch clauses even when --no-syntax-extensions / -nse option is passed
+ *
+ * @option --no-syntax-extensions
+ * @test/compile-error
+ */
+
+try {
+    func()
+} catch (e if e instanceof ReferenceError) {
+    print("Got ReferenceError " + e);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/error/JDK-8039047.js.EXPECTED	Wed Apr 02 15:52:31 2014 +0530
@@ -0,0 +1,6 @@
+test/script/error/JDK-8039047.js:33:11 Expected ) but found if
+} catch (e if e instanceof ReferenceError) {
+           ^
+test/script/error/JDK-8039047.js:35:0 Expected eof but found }
+}
+^