test/script/basic/NASHORN-73.js

changeset 3
da1e581c933b
child 7
5a1b0714df0e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/script/basic/NASHORN-73.js	Fri Dec 21 16:36:24 2012 -0400
     1.3 @@ -0,0 +1,122 @@
     1.4 +/*
     1.5 + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + * 
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + * 
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + * 
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + * 
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/**
    1.28 + * NASHORN-73 :  Loop break should not skip variable declarations.
    1.29 + *
    1.30 + * @test
    1.31 + * @run
    1.32 + */
    1.33 +
    1.34 +print("x = " + x);
    1.35 +do {
    1.36 +   break;
    1.37 +   var x;
    1.38 +} while (true);
    1.39 +
    1.40 +
    1.41 +print("y = " + y);
    1.42 +while (true) {
    1.43 +    break;
    1.44 +    var y;
    1.45 +}
    1.46 +
    1.47 +print("z = " + z);
    1.48 +for ( ; ; ) {
    1.49 +   break;
    1.50 +   var z;
    1.51 +   print("THIS SHOULD NEVER BE PRINTED!");
    1.52 +}
    1.53 +
    1.54 +while (true) {
    1.55 +    break;
    1.56 +    if (true) { 
    1.57 +	var s; 
    1.58 +    }
    1.59 +}
    1.60 +
    1.61 +print("s = "+s);
    1.62 +
    1.63 +print("u = "+u);
    1.64 +for ( ; ; ) {
    1.65 +    break;
    1.66 +    while (true) {
    1.67 +	do {
    1.68 +	    var u;
    1.69 +	} while (true);
    1.70 +    }    
    1.71 +}
    1.72 +
    1.73 +function terminal() {
    1.74 +    print("r = "+r);
    1.75 +    print("t = "+t);
    1.76 +    for (;;) {
    1.77 +	var r;
    1.78 +	return;
    1.79 +	var t;
    1.80 +	print("THIS SHOULD NEVER BE PRINTED!");
    1.81 +    }
    1.82 +    print("NEITHER SHOULD THIS");
    1.83 +}
    1.84 +
    1.85 +terminal();
    1.86 +
    1.87 +function terminal2() {
    1.88 +    print("q = "+q);
    1.89 +    for (;;) {
    1.90 +	return;
    1.91 +	print("THIS SHOULD NEVER BE PRINTED!");
    1.92 +    }
    1.93 +    print("NEITHER SHOULD THIS");
    1.94 +}
    1.95 +
    1.96 +try { 
    1.97 +    terminal2();
    1.98 +} catch (e) {
    1.99 +    print(e);
   1.100 +}
   1.101 +
   1.102 +function scope2() {
   1.103 +    var b = 10;
   1.104 +    print("b = "+b);
   1.105 +}
   1.106 +
   1.107 +scope2();
   1.108 +
   1.109 +try {
   1.110 +    print("b is = "+b);
   1.111 +}  catch (e) {
   1.112 +    print(e);
   1.113 +}
   1.114 +	
   1.115 +
   1.116 +function disp_a() {
   1.117 +    var a = 20;
   1.118 +    print("Value of 'a' inside the function " + a);
   1.119 +}
   1.120 +	
   1.121 +var a = 10;
   1.122 +
   1.123 +disp_a();
   1.124 +
   1.125 +print("Value of 'a' outside the function " + a);

mercurial