nashorn/test/script/basic/JDK-8019473.js
author hannesw
Sat, 02 Sep 2017 14:26:29 +0200
changeset 47205 6ddad446ba23
parent 24778 2ff5d7041566
permissions -rw-r--r--
8169233: LengthNotWritableFilter extraElements.remove(index) has no effect Reviewed-by: sundar, jlaskey Contributed-by: priya.lakshmi.muthuswamy@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18625
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
     1
/*
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 18625
diff changeset
     4
 *
18625
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 18625
diff changeset
     8
 *
18625
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    13
 * accompanied this code).
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 18625
diff changeset
    14
 *
18625
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 18625
diff changeset
    18
 *
18625
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    21
 * questions.
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    22
 */
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    23
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    24
/**
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    25
 * JDK-8019473: Parser issues related to functions and blocks
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    26
 *
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    27
 * @test
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    28
 * @run
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    29
 */
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    30
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    31
function checkNoError(code) {
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    32
    try {
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    33
        Function(code);
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    34
    } catch (e) {
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    35
        print("no error expected for: " + code + " , got " + e);
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    36
    }
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    37
}
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    38
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    39
// implicit newlines at EOF should be accepted
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    40
checkNoError("for(;;) continue")
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    41
checkNoError("return")
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    42
checkNoError("yield")
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    43
checkNoError("for(;;) break")
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    44
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    45
function checkError(code) {
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    46
    try {
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    47
        eval(code);
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    48
        print("SyntaxError expected for: " + code);
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    49
    } catch (e) {
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    50
        if (! (e instanceof SyntaxError)) {
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    51
            fail("SyntaxError expected, got " + e);
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    52
        }
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    53
    }
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    54
}
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    55
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    56
checkError("function f() { case0: }");
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    57
checkError("function f() { if(0) }");
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    58
checkError("function f() { if(0); else }");
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    59
checkError("function f() { while(0) }");
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    60
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    61
// comma expression as closure expression
13558072545a 8019473: Parser issues related to functions and blocks
sundar
parents:
diff changeset
    62
checkError("function sq(x) x, x*x");