test/script/basic/NASHORN-58.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

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@962 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation.
attila@962 8 *
jlaskey@3 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 12 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 13 * accompanied this code).
attila@962 14 *
jlaskey@3 15 * You should have received a copy of the GNU General Public License version
jlaskey@3 16 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@962 18 *
jlaskey@3 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 20 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 21 * questions.
jlaskey@3 22 */
jlaskey@3 23
jlaskey@3 24 /**
jlaskey@3 25 * NASHORN-58
jlaskey@3 26 *
jlaskey@3 27 * @test
jlaskey@3 28 * @run
jlaskey@3 29 */
jlaskey@3 30
jlaskey@3 31 function test1() {
jlaskey@3 32 var x = 1;
attila@962 33 try {
attila@962 34 print('try');
attila@962 35 x = 2;
jlaskey@3 36 } catch(e) {
attila@962 37 print('catch');
attila@962 38 } finally {
attila@962 39 print('finally');
attila@962 40 x = 3;
jlaskey@3 41 }
jlaskey@3 42 print(x);
jlaskey@3 43 }
jlaskey@3 44
jlaskey@3 45 function test2() {
jlaskey@3 46 var x = 1;
jlaskey@3 47 try {
attila@962 48 print('try');
jlaskey@3 49 } finally {
attila@962 50 print('finally');
attila@962 51 x = 2;
jlaskey@3 52 }
jlaskey@3 53 print(x);
jlaskey@3 54 }
jlaskey@3 55
jlaskey@3 56 function test3() {
jlaskey@3 57 try {
attila@962 58 return 2;
jlaskey@3 59 } finally {
attila@962 60 return 3;
jlaskey@3 61 }
jlaskey@3 62 }
jlaskey@3 63
jlaskey@3 64 function test4() {
jlaskey@3 65 try {
attila@962 66 x = 1;
attila@962 67 print(x);
attila@962 68 try {
attila@962 69 x = 2;
attila@962 70 print(x);
jlaskey@3 71 } finally {
attila@962 72 x = 3;
attila@962 73 print(x)
attila@962 74 try {
attila@962 75 x = 4;
attila@962 76 print(x);
attila@962 77 } finally {
attila@962 78 x = 5;
attila@962 79 print(x);
attila@962 80 }
attila@962 81 }
attila@962 82 print(x)
attila@962 83 } finally {
attila@962 84 x = 6;
attila@962 85 print(x);
jlaskey@3 86 }
jlaskey@3 87 print(x);
jlaskey@3 88 }
jlaskey@3 89
jlaskey@3 90 function test5() {
jlaskey@3 91 try {
attila@962 92 x = 1;
attila@962 93 print(x);
attila@962 94 try {
attila@962 95 x = 2;
attila@962 96 print(x);
jlaskey@3 97 } finally {
attila@962 98 x = 3;
attila@962 99 print(x)
attila@962 100 try {
attila@962 101 x = 4;
attila@962 102 print(x);
attila@962 103 } finally {
attila@962 104 x = 5;
attila@962 105 return x;
attila@962 106 }
attila@962 107 }
attila@962 108 print(x)
attila@962 109 } finally {
attila@962 110 x = 6;
attila@962 111 return x;
jlaskey@3 112 }
jlaskey@3 113 }
jlaskey@3 114
jlaskey@3 115 function test6() {
jlaskey@3 116 try {
attila@962 117 throw new Error("testing");
jlaskey@3 118 } catch (ex) {
attila@962 119 print(ex);
attila@962 120 return;
jlaskey@3 121 } finally {
attila@962 122 print("finally");
jlaskey@3 123 }
jlaskey@3 124 }
jlaskey@3 125
jlaskey@3 126 function test7() {
jlaskey@3 127 var e = new Error("no message");
jlaskey@3 128 var i = 3;
jlaskey@3 129 try {
jlaskey@3 130 throw e;
jlaskey@3 131 } catch (ex) {
jlaskey@3 132 } finally {
jlaskey@3 133 i++;
jlaskey@3 134 }
jlaskey@3 135 if (i != 4) {
attila@962 136 print("FAIL");
jlaskey@3 137 }
jlaskey@3 138 print("SUCCESS");
jlaskey@3 139 }
jlaskey@3 140
jlaskey@3 141
jlaskey@3 142 test1();
jlaskey@3 143 test2();
jlaskey@3 144 print(test3());
jlaskey@3 145 test4();
jlaskey@3 146 print(test5())
jlaskey@3 147 test6();
jlaskey@3 148 test7();
jlaskey@3 149

mercurial