|
1 /* |
|
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /** |
|
25 * 8006983: Introduce a command line option to switch off syntactic extensions of nashorn |
|
26 * |
|
27 * @test |
|
28 * @option -scripting |
|
29 * @option --no-syntax-extensions |
|
30 * @run |
|
31 */ |
|
32 |
|
33 try { |
|
34 eval("var r = new java.lang.Runnable() { run: function(){} }"); |
|
35 fail("should have thrown error for anon-class-style new"); |
|
36 } catch (e) { |
|
37 if (! (e instanceof SyntaxError)) { |
|
38 fail("SyntaxError expected, got " + e); |
|
39 } |
|
40 } |
|
41 |
|
42 try { |
|
43 eval("var sqr = function(x) x*x "); |
|
44 fail("should have thrown error for expression closures"); |
|
45 } catch (e) { |
|
46 if (! (e instanceof SyntaxError)) { |
|
47 fail("SyntaxError expected, got " + e); |
|
48 } |
|
49 } |
|
50 |
|
51 try { |
|
52 eval("function() {};"); |
|
53 fail("should have thrown error for anonymous function statement"); |
|
54 } catch (e) { |
|
55 if (! (e instanceof SyntaxError)) { |
|
56 fail("SyntaxError expected, got " + e); |
|
57 } |
|
58 } |
|
59 |
|
60 try { |
|
61 eval("for each (i in [22, 33, 33]) { print(i) }"); |
|
62 fail("should have thrown error for-each statement"); |
|
63 } catch (e) { |
|
64 if (! (e instanceof SyntaxError)) { |
|
65 fail("SyntaxError expected, got " + e); |
|
66 } |
|
67 } |
|
68 |
|
69 try { |
|
70 eval("# shell style comment"); |
|
71 fail("should have thrown error for shell style comment"); |
|
72 } catch (e) { |
|
73 if (! (e instanceof SyntaxError)) { |
|
74 fail("SyntaxError expected, got " + e); |
|
75 } |
|
76 } |
|
77 |
|
78 try { |
|
79 eval("print(<<EOF);\nhello\nworld\nEOF\n"); |
|
80 fail("should have thrown error heredoc"); |
|
81 } catch (e) { |
|
82 if (! (e instanceof SyntaxError)) { |
|
83 fail("SyntaxError expected, got " + e); |
|
84 } |
|
85 } |