JDK-8019473.js revision 386:02588d68399d
1158714Srodrigc/*
2158714Srodrigc * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3158714Srodrigc * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4158714Srodrigc *
5158714Srodrigc * This code is free software; you can redistribute it and/or modify it
6158714Srodrigc * under the terms of the GNU General Public License version 2 only, as
7158714Srodrigc * published by the Free Software Foundation.
8158714Srodrigc *
9158714Srodrigc * This code is distributed in the hope that it will be useful, but WITHOUT
10158714Srodrigc * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11158714Srodrigc * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12158714Srodrigc * version 2 for more details (a copy is included in the LICENSE file that
13158714Srodrigc * accompanied this code).
14158714Srodrigc *
15158714Srodrigc * You should have received a copy of the GNU General Public License version
16158714Srodrigc * 2 along with this work; if not, write to the Free Software Foundation,
17158714Srodrigc * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18158714Srodrigc *
19158714Srodrigc * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20158714Srodrigc * or visit www.oracle.com if you need additional information or have any
21158714Srodrigc * questions.
22158714Srodrigc */
23158714Srodrigc
24158714Srodrigc/**
25158714Srodrigc * JDK-8019473: Parser issues related to functions and blocks
26158714Srodrigc *
27158714Srodrigc * @test
28158714Srodrigc * @run
29255977Spluknet */
30158714Srodrigc
31158714Srodrigcfunction checkNoError(code) {
32158714Srodrigc    try {
33158714Srodrigc        Function(code);
34158714Srodrigc    } catch (e) {
35158714Srodrigc        print("no error expected for: " + code + " , got " + e);
36158714Srodrigc    }
37158714Srodrigc}
38158714Srodrigc
39158714Srodrigc// implicit newlines at EOF should be accepted
40158714SrodrigccheckNoError("for(;;) continue")
41158714SrodrigccheckNoError("return")
42158714SrodrigccheckNoError("yield")
43158714SrodrigccheckNoError("for(;;) break")
44158714Srodrigc
45158714Srodrigcfunction checkError(code) {
46158714Srodrigc    try {
47158714Srodrigc        eval(code);
48158714Srodrigc        print("SyntaxError expected for: " + code);
49158714Srodrigc    } catch (e) {
50162872Sru        if (! (e instanceof SyntaxError)) {
51158714Srodrigc            fail("SyntaxError expected, got " + e);
52158714Srodrigc        }
53158714Srodrigc    }
54158714Srodrigc}
55158714Srodrigc
56255977SpluknetcheckError("function f() { case0: }");
57158714SrodrigccheckError("function f() { if(0) }");
58255977SpluknetcheckError("function f() { if(0); else }");
59158714SrodrigccheckError("function f() { while(0) }");
60158714Srodrigc
61158714Srodrigc// comma expression as closure expression
62158714SrodrigccheckError("function sq(x) x, x*x");
63158714Srodrigc