test/script/basic/finally-catchalls.js

Tue, 21 Mar 2017 13:41:57 -0700

author
asaha
date
Tue, 21 Mar 2017 13:41:57 -0700
changeset 2160
1df40fe54cd6
parent 962
ac62e33a99b0
child 1205
4112748288bb
permissions
-rw-r--r--

Merge

     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  */
    24 /**
    25  * finally-catchalls: should not be able to read, write, call properties from null literal.
    26  *
    27  * @test
    28  * @run
    29  */
    31 function test1() {
    32     try {
    33     print("try");
    34     throw "ex";
    35     } finally {
    36     print("finally");
    37     }
    38 }
    40 function test2() {
    41     try {
    42     print("try");
    43     } finally {
    44     print("finally");
    45     }
    46 }
    48 function test3() {
    49     try {
    50     print("try");
    51     return;
    52     } finally {
    53     print("finally");
    54     }
    55 }
    57 function test4() {
    58     var i = 0;
    59     while (i<10) {
    60     try {
    61         print("try "+i);
    62         i++;
    63         continue;
    64     } finally {
    65         print("finally "+i);
    66     }
    67     }
    68     print(i);
    69 }
    71 function test5() {
    72     var i = 0;
    73     while (i<10) {
    74     try {
    75         print("try "+i);
    76         i++;
    77         break;
    78     } finally {
    79         print("finally "+i);
    80     }
    81     }
    82     print(i);
    83 }
    85 function test6() {
    86     var i = 0;
    87     while (i<10) {
    88     try {
    89         print("try "+i);
    90         if (i == 5)
    91         break;
    92         i++;
    93     } finally {
    94         print("finally "+i);
    95     }
    96     }
    97     print(i);
    98 }
   100 print("\ntest 1\n");
   101 try {
   102     test1();
   103 } catch (e) {
   104     print("got e");
   105 }
   107 print("\ntest 2\n");
   108 test2();
   110 print("\ntest 3\n");
   111 test3();
   113 print("\ntest 4\n");
   114 test4();
   116 print("\ntest 5\n");
   117 test5();
   119 print("\ntest 6\n");
   120 test6();

mercurial