8086032: Add compiler error tests when syntax extensions are used with --no-syntax-extensions option
Reviewed-by: attila, hannesw
This commit is contained in:
parent
a1bb22a48c
commit
f5e449156c
67
nashorn/samples/javahelp.js
Normal file
67
nashorn/samples/javahelp.js
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// script helpers to print meta info on Java instances and classes
|
||||
|
||||
// print instance methods info on a Java object or static methods info of a Java class
|
||||
function methods(jobj) {
|
||||
if (! Java.isJavaObject(jobj)) {
|
||||
throw new TypeError("not a Java object");
|
||||
}
|
||||
|
||||
var isStatic = Java.isType(jobj);
|
||||
var obj = Object.bindProperties({}, jobj);
|
||||
for each (var i in obj) {
|
||||
if (Java.isJavaMethod(i)) {
|
||||
var str = String(i);
|
||||
var idx = str.indexOf(' ');
|
||||
var overloaded = str.substring(0, idx).endsWith("OverloadedDynamicMethod");
|
||||
var lastIdx = isStatic? str.lastIndexOf('] on') : str.lastIndexOf(']');
|
||||
print(str.substring(idx + 1, lastIdx) + (overloaded? "*" : ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// print instance field names of a Java object or static field names of a Java class
|
||||
function fields(jobj) {
|
||||
if (! Java.isJavaObject(jobj)) {
|
||||
throw new TypeError("not a Java object");
|
||||
}
|
||||
|
||||
var obj = Object.bindProperties({}, jobj);
|
||||
for (var i in obj) {
|
||||
if (! Java.isJavaMethod(obj[i])) {
|
||||
print(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
undefined;
|
31
nashorn/test/script/error/anon_func_stat_nse.js
Normal file
31
nashorn/test/script/error/anon_func_stat_nse.js
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Anonymous function statement should result in error in -nse
|
||||
*
|
||||
* @option -nse
|
||||
* @test/compile-error
|
||||
*/
|
||||
|
||||
function() {}
|
3
nashorn/test/script/error/anon_func_stat_nse.js.EXPECTED
Normal file
3
nashorn/test/script/error/anon_func_stat_nse.js.EXPECTED
Normal file
@ -0,0 +1,3 @@
|
||||
test/script/error/anon_func_stat_nse.js:31:8 Expected ident but found (
|
||||
function() {}
|
||||
^
|
32
nashorn/test/script/error/backquote_string_nse.js
Normal file
32
nashorn/test/script/error/backquote_string_nse.js
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Backquote string should result in error with -nse even with -scripting
|
||||
*
|
||||
* @option -nse
|
||||
* @option -scripting
|
||||
* @test/compile-error
|
||||
*/
|
||||
|
||||
`ls -l`;
|
@ -0,0 +1,3 @@
|
||||
test/script/error/backquote_string_nse.js:32:0 Expected an operand but found error
|
||||
`ls -l`;
|
||||
^
|
34
nashorn/test/script/error/conditional_catch_nse.js
Normal file
34
nashorn/test/script/error/conditional_catch_nse.js
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* conditional catch should result in error with -nse
|
||||
*
|
||||
* @option -nse
|
||||
* @test/compile-error
|
||||
*/
|
||||
|
||||
try {
|
||||
func();
|
||||
} catch (e if e instanceof ReferenceError) {
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
test/script/error/conditional_catch_nse.js:33:11 Expected ) but found if
|
||||
} catch (e if e instanceof ReferenceError) {
|
||||
^
|
||||
test/script/error/conditional_catch_nse.js:34:0 Expected eof but found }
|
||||
}
|
||||
^
|
31
nashorn/test/script/error/expr_closure_nse.js
Normal file
31
nashorn/test/script/error/expr_closure_nse.js
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Expression closures should result in error with -nse
|
||||
*
|
||||
* @option -nse
|
||||
* @test/compile-error
|
||||
*/
|
||||
|
||||
function square(x) x*x;
|
3
nashorn/test/script/error/expr_closure_nse.js.EXPECTED
Normal file
3
nashorn/test/script/error/expr_closure_nse.js.EXPECTED
Normal file
@ -0,0 +1,3 @@
|
||||
test/script/error/expr_closure_nse.js:31:19 Expected { but found x
|
||||
function square(x) x*x;
|
||||
^
|
33
nashorn/test/script/error/for_each_nse.js
Normal file
33
nashorn/test/script/error/for_each_nse.js
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* for..each should result in error with -nse
|
||||
*
|
||||
* @option -nse
|
||||
* @test/compile-error
|
||||
*/
|
||||
|
||||
for each (var x in [3, 454, 4]) {
|
||||
print(x);
|
||||
}
|
6
nashorn/test/script/error/for_each_nse.js.EXPECTED
Normal file
6
nashorn/test/script/error/for_each_nse.js.EXPECTED
Normal file
@ -0,0 +1,6 @@
|
||||
test/script/error/for_each_nse.js:31:4 Expected ( but found each
|
||||
for each (var x in [3, 454, 4]) {
|
||||
^
|
||||
test/script/error/for_each_nse.js:33:0 Expected eof but found }
|
||||
}
|
||||
^
|
32
nashorn/test/script/error/hash_comment_nse.js
Normal file
32
nashorn/test/script/error/hash_comment_nse.js
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Hash comment should result in error with -nse even with -scripting
|
||||
*
|
||||
* @option -nse
|
||||
* @option -scripting
|
||||
* @test/compile-error
|
||||
*/
|
||||
|
||||
# this is a comment
|
3
nashorn/test/script/error/hash_comment_nse.js.EXPECTED
Normal file
3
nashorn/test/script/error/hash_comment_nse.js.EXPECTED
Normal file
@ -0,0 +1,3 @@
|
||||
test/script/error/hash_comment_nse.js:32:0 Expected an operand but found error
|
||||
# this is a comment
|
||||
^
|
35
nashorn/test/script/error/heredoc_nse.js
Normal file
35
nashorn/test/script/error/heredoc_nse.js
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Heredoc string should result in error with -nse even with -scripting
|
||||
*
|
||||
* @option -nse
|
||||
* @option -scripting
|
||||
* @test/compile-error
|
||||
*/
|
||||
|
||||
var str = <<EOF
|
||||
This is a multiple line string
|
||||
inside a heredoc
|
||||
EOF;
|
9
nashorn/test/script/error/heredoc_nse.js.EXPECTED
Normal file
9
nashorn/test/script/error/heredoc_nse.js.EXPECTED
Normal file
@ -0,0 +1,9 @@
|
||||
test/script/error/heredoc_nse.js:32:10 Expected an operand but found <<
|
||||
var str = <<EOF
|
||||
^
|
||||
test/script/error/heredoc_nse.js:33:5 Expected ; but found is
|
||||
This is a multiple line string
|
||||
^
|
||||
test/script/error/heredoc_nse.js:34:7 Expected ; but found a
|
||||
inside a heredoc
|
||||
^
|
33
nashorn/test/script/error/object_literal_in_new_nse.js
Normal file
33
nashorn/test/script/error/object_literal_in_new_nse.js
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object literal outside 'new' should result in error in -nse
|
||||
*
|
||||
* @option -nse
|
||||
* @test/compile-error
|
||||
*/
|
||||
|
||||
var r = new java.lang.Runnable() {
|
||||
run: function() { print("hello"); }
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
test/script/error/object_literal_in_new_nse.js:31:33 Expected ; but found {
|
||||
var r = new java.lang.Runnable() {
|
||||
^
|
||||
test/script/error/object_literal_in_new_nse.js:32:15 Expected ident but found (
|
||||
run: function() { print("hello"); }
|
||||
^
|
||||
test/script/error/object_literal_in_new_nse.js:32:36 Expected eof but found }
|
||||
run: function() { print("hello"); }
|
||||
^
|
Loading…
Reference in New Issue
Block a user