Tue, 09 Jun 2015 14:19:57 +0530
8086032: Add compiler error tests when syntax extensions are used with --no-syntax-extensions option
Reviewed-by: attila, hannesw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/samples/javahelp.js Tue Jun 09 14:19:57 2015 +0530 1.3 @@ -0,0 +1,67 @@ 1.4 +/* 1.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 1.6 + * 1.7 + * Redistribution and use in source and binary forms, with or without 1.8 + * modification, are permitted provided that the following conditions 1.9 + * are met: 1.10 + * 1.11 + * - Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * 1.14 + * - Redistributions in binary form must reproduce the above copyright 1.15 + * notice, this list of conditions and the following disclaimer in the 1.16 + * documentation and/or other materials provided with the distribution. 1.17 + * 1.18 + * - Neither the name of Oracle nor the names of its 1.19 + * contributors may be used to endorse or promote products derived 1.20 + * from this software without specific prior written permission. 1.21 + * 1.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 1.23 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 1.24 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.25 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.26 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.27 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.28 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.29 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.30 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.31 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.32 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.33 + */ 1.34 + 1.35 +// script helpers to print meta info on Java instances and classes 1.36 + 1.37 +// print instance methods info on a Java object or static methods info of a Java class 1.38 +function methods(jobj) { 1.39 + if (! Java.isJavaObject(jobj)) { 1.40 + throw new TypeError("not a Java object"); 1.41 + } 1.42 + 1.43 + var isStatic = Java.isType(jobj); 1.44 + var obj = Object.bindProperties({}, jobj); 1.45 + for each (var i in obj) { 1.46 + if (Java.isJavaMethod(i)) { 1.47 + var str = String(i); 1.48 + var idx = str.indexOf(' '); 1.49 + var overloaded = str.substring(0, idx).endsWith("OverloadedDynamicMethod"); 1.50 + var lastIdx = isStatic? str.lastIndexOf('] on') : str.lastIndexOf(']'); 1.51 + print(str.substring(idx + 1, lastIdx) + (overloaded? "*" : "")) 1.52 + } 1.53 + } 1.54 +} 1.55 + 1.56 +// print instance field names of a Java object or static field names of a Java class 1.57 +function fields(jobj) { 1.58 + if (! Java.isJavaObject(jobj)) { 1.59 + throw new TypeError("not a Java object"); 1.60 + } 1.61 + 1.62 + var obj = Object.bindProperties({}, jobj); 1.63 + for (var i in obj) { 1.64 + if (! Java.isJavaMethod(obj[i])) { 1.65 + print(i); 1.66 + } 1.67 + } 1.68 +} 1.69 + 1.70 +undefined;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/script/error/anon_func_stat_nse.js Tue Jun 09 14:19:57 2015 +0530 2.3 @@ -0,0 +1,31 @@ 2.4 +/* 2.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/** 2.28 + * Anonymous function statement should result in error in -nse 2.29 + * 2.30 + * @option -nse 2.31 + * @test/compile-error 2.32 + */ 2.33 + 2.34 +function() {}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/script/error/anon_func_stat_nse.js.EXPECTED Tue Jun 09 14:19:57 2015 +0530 3.3 @@ -0,0 +1,3 @@ 3.4 +test/script/error/anon_func_stat_nse.js:31:8 Expected ident but found ( 3.5 +function() {} 3.6 + ^
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/script/error/backquote_string_nse.js Tue Jun 09 14:19:57 2015 +0530 4.3 @@ -0,0 +1,32 @@ 4.4 +/* 4.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/** 4.28 + * Backquote string should result in error with -nse even with -scripting 4.29 + * 4.30 + * @option -nse 4.31 + * @option -scripting 4.32 + * @test/compile-error 4.33 + */ 4.34 + 4.35 +`ls -l`;
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/script/error/backquote_string_nse.js.EXPECTED Tue Jun 09 14:19:57 2015 +0530 5.3 @@ -0,0 +1,3 @@ 5.4 +test/script/error/backquote_string_nse.js:32:0 Expected an operand but found error 5.5 +`ls -l`; 5.6 +^
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/script/error/conditional_catch_nse.js Tue Jun 09 14:19:57 2015 +0530 6.3 @@ -0,0 +1,34 @@ 6.4 +/* 6.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/** 6.28 + * conditional catch should result in error with -nse 6.29 + * 6.30 + * @option -nse 6.31 + * @test/compile-error 6.32 + */ 6.33 + 6.34 +try { 6.35 + func(); 6.36 +} catch (e if e instanceof ReferenceError) { 6.37 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/script/error/conditional_catch_nse.js.EXPECTED Tue Jun 09 14:19:57 2015 +0530 7.3 @@ -0,0 +1,6 @@ 7.4 +test/script/error/conditional_catch_nse.js:33:11 Expected ) but found if 7.5 +} catch (e if e instanceof ReferenceError) { 7.6 + ^ 7.7 +test/script/error/conditional_catch_nse.js:34:0 Expected eof but found } 7.8 +} 7.9 +^
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/script/error/expr_closure_nse.js Tue Jun 09 14:19:57 2015 +0530 8.3 @@ -0,0 +1,31 @@ 8.4 +/* 8.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + */ 8.26 + 8.27 +/** 8.28 + * Expression closures should result in error with -nse 8.29 + * 8.30 + * @option -nse 8.31 + * @test/compile-error 8.32 + */ 8.33 + 8.34 +function square(x) x*x;
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/script/error/expr_closure_nse.js.EXPECTED Tue Jun 09 14:19:57 2015 +0530 9.3 @@ -0,0 +1,3 @@ 9.4 +test/script/error/expr_closure_nse.js:31:19 Expected { but found x 9.5 +function square(x) x*x; 9.6 + ^
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/script/error/for_each_nse.js Tue Jun 09 14:19:57 2015 +0530 10.3 @@ -0,0 +1,33 @@ 10.4 +/* 10.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. 10.11 + * 10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.15 + * version 2 for more details (a copy is included in the LICENSE file that 10.16 + * accompanied this code). 10.17 + * 10.18 + * You should have received a copy of the GNU General Public License version 10.19 + * 2 along with this work; if not, write to the Free Software Foundation, 10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.21 + * 10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.23 + * or visit www.oracle.com if you need additional information or have any 10.24 + * questions. 10.25 + */ 10.26 + 10.27 +/** 10.28 + * for..each should result in error with -nse 10.29 + * 10.30 + * @option -nse 10.31 + * @test/compile-error 10.32 + */ 10.33 + 10.34 +for each (var x in [3, 454, 4]) { 10.35 + print(x); 10.36 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/script/error/for_each_nse.js.EXPECTED Tue Jun 09 14:19:57 2015 +0530 11.3 @@ -0,0 +1,6 @@ 11.4 +test/script/error/for_each_nse.js:31:4 Expected ( but found each 11.5 +for each (var x in [3, 454, 4]) { 11.6 + ^ 11.7 +test/script/error/for_each_nse.js:33:0 Expected eof but found } 11.8 +} 11.9 +^
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/script/error/hash_comment_nse.js Tue Jun 09 14:19:57 2015 +0530 12.3 @@ -0,0 +1,32 @@ 12.4 +/* 12.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +/** 12.28 + * Hash comment should result in error with -nse even with -scripting 12.29 + * 12.30 + * @option -nse 12.31 + * @option -scripting 12.32 + * @test/compile-error 12.33 + */ 12.34 + 12.35 +# this is a comment
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/script/error/hash_comment_nse.js.EXPECTED Tue Jun 09 14:19:57 2015 +0530 13.3 @@ -0,0 +1,3 @@ 13.4 +test/script/error/hash_comment_nse.js:32:0 Expected an operand but found error 13.5 +# this is a comment 13.6 +^
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/script/error/heredoc_nse.js Tue Jun 09 14:19:57 2015 +0530 14.3 @@ -0,0 +1,35 @@ 14.4 +/* 14.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/** 14.28 + * Heredoc string should result in error with -nse even with -scripting 14.29 + * 14.30 + * @option -nse 14.31 + * @option -scripting 14.32 + * @test/compile-error 14.33 + */ 14.34 + 14.35 +var str = <<EOF 14.36 +This is a multiple line string 14.37 +inside a heredoc 14.38 +EOF;
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/script/error/heredoc_nse.js.EXPECTED Tue Jun 09 14:19:57 2015 +0530 15.3 @@ -0,0 +1,9 @@ 15.4 +test/script/error/heredoc_nse.js:32:10 Expected an operand but found << 15.5 +var str = <<EOF 15.6 + ^ 15.7 +test/script/error/heredoc_nse.js:33:5 Expected ; but found is 15.8 +This is a multiple line string 15.9 + ^ 15.10 +test/script/error/heredoc_nse.js:34:7 Expected ; but found a 15.11 +inside a heredoc 15.12 + ^
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/script/error/object_literal_in_new_nse.js Tue Jun 09 14:19:57 2015 +0530 16.3 @@ -0,0 +1,33 @@ 16.4 +/* 16.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +/** 16.28 + * Object literal outside 'new' should result in error in -nse 16.29 + * 16.30 + * @option -nse 16.31 + * @test/compile-error 16.32 + */ 16.33 + 16.34 +var r = new java.lang.Runnable() { 16.35 + run: function() { print("hello"); } 16.36 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/script/error/object_literal_in_new_nse.js.EXPECTED Tue Jun 09 14:19:57 2015 +0530 17.3 @@ -0,0 +1,9 @@ 17.4 +test/script/error/object_literal_in_new_nse.js:31:33 Expected ; but found { 17.5 +var r = new java.lang.Runnable() { 17.6 + ^ 17.7 +test/script/error/object_literal_in_new_nse.js:32:15 Expected ident but found ( 17.8 + run: function() { print("hello"); } 17.9 + ^ 17.10 +test/script/error/object_literal_in_new_nse.js:32:36 Expected eof but found } 17.11 + run: function() { print("hello"); } 17.12 + ^