1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Statements/dowhile-002.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,71 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + * File Name: dowhile-002 1.12 + * ECMA Section: 1.13 + * Description: do...while statements 1.14 + * 1.15 + * Verify that code after a labeled break is not executed. Verify that 1.16 + * a labeled break breaks you out of the whole labeled block, and not 1.17 + * just the current iteration statement. 1.18 + * 1.19 + * Author: christine@netscape.com 1.20 + * Date: 11 August 1998 1.21 + */ 1.22 +var SECTION = "dowhile-002"; 1.23 +var VERSION = "ECMA_2"; 1.24 +var TITLE = "do...while with a labeled continue statement"; 1.25 + 1.26 +startTest(); 1.27 +writeHeaderToLog( SECTION + " "+ TITLE); 1.28 + 1.29 +LabeledContinue( 0, 1 ); 1.30 +LabeledContinue( 1, 1 ); 1.31 +LabeledContinue( -1, 1 ); 1.32 +LabeledContinue( 5, 5 ); 1.33 + 1.34 +test(); 1.35 + 1.36 +// The labeled statement contains statements after the labeled break. 1.37 +// Verify that the statements after the break are not executed. 1.38 + 1.39 +function LabeledContinue( limit, expect ) { 1.40 + i = 0; 1.41 + result1 = "pass"; 1.42 + result2 = "pass"; 1.43 + 1.44 +woohoo: { 1.45 + do { 1.46 + i++; 1.47 + if ( ! (i < limit) ) { 1.48 + break woohoo; 1.49 + result1 = "fail: evaluated statement after a labeled break"; 1.50 + } 1.51 + } while ( true ); 1.52 + 1.53 + result2 = "failed: broke out of loop, but not out of labeled block"; 1.54 + } 1.55 + 1.56 + new TestCase( 1.57 + SECTION, 1.58 + "do while ( " + i +" < " + limit +" )", 1.59 + expect, 1.60 + i ); 1.61 + 1.62 + new TestCase( 1.63 + SECTION, 1.64 + "breaking out of a do... while loop", 1.65 + "pass", 1.66 + result1 ); 1.67 + 1.68 + 1.69 + new TestCase( 1.70 + SECTION, 1.71 + "breaking out of a labeled do...while loop", 1.72 + "pass", 1.73 + result2 ); 1.74 +}