changeset 776:83dd87a63ea3

8039047: Parser accepts conditional catch clauses even when --no-syntax-extensions / -nse option is passed Reviewed-by: lagergren, attila
author sundar
date Wed, 02 Apr 2014 15:52:31 +0530
parents 18f81e83fa8e
children 41f588adeb7a e0e2d72e6699
files src/jdk/nashorn/internal/parser/Parser.java test/script/error/JDK-8039047.js test/script/error/JDK-8039047.js.EXPECTED
diffstat 3 files changed, 45 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/parser/Parser.java	Tue Apr 01 11:44:05 2014 -0700
+++ b/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/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/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 }
+}
+^