js/src/tests/ecma_2/Statements/try-009.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_2/Statements/try-009.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     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:          try-009.js
    1.12 + *  ECMA Section:
    1.13 + *  Description:        The try statement
    1.14 + *
    1.15 + *  This test has a try block within a while block.  Verify that an exception
    1.16 + *  breaks out of the while.  I don't really know why this is an interesting
    1.17 + *  test case but Mike Shaver had two of these so what the hey.
    1.18 + *
    1.19 + *  Author:             christine@netscape.com
    1.20 + *  Date:               11 August 1998
    1.21 + */
    1.22 +var SECTION = "try-009";
    1.23 +var VERSION = "ECMA_2";
    1.24 +var TITLE   = "The try statement: try in a while block";
    1.25 +
    1.26 +startTest();
    1.27 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.28 +
    1.29 +var EXCEPTION_STRING = "Exception thrown: ";
    1.30 +var NO_EXCEPTION_STRING = "No exception thrown: ";
    1.31 +
    1.32 +
    1.33 +TryInWhile( new TryObject( "hello", ThrowException, true ) );
    1.34 +TryInWhile( new TryObject( "aloha", NoException, false ));
    1.35 +
    1.36 +test();
    1.37 +
    1.38 +function TryObject( value, throwFunction, result ) {
    1.39 +  this.value = value;
    1.40 +  this.thrower = throwFunction;
    1.41 +  this.result = result;
    1.42 +}
    1.43 +function ThrowException() {
    1.44 +  throw EXCEPTION_STRING + this.value;
    1.45 +}
    1.46 +function NoException() {
    1.47 +  return NO_EXCEPTION_STRING + this.value;
    1.48 +}
    1.49 +function TryInWhile( object ) {
    1.50 +  result = null;
    1.51 +  while ( true ) {
    1.52 +    try {
    1.53 +      object.thrower();
    1.54 +      result = NO_EXCEPTION_STRING + object.value;
    1.55 +      break;
    1.56 +    } catch ( e ) {
    1.57 +      result = e;
    1.58 +      break;
    1.59 +    }
    1.60 +  }
    1.61 +
    1.62 +  new TestCase(
    1.63 +    SECTION,
    1.64 +    "( "+ object  +".thrower() )",
    1.65 +    (object.result
    1.66 +     ? EXCEPTION_STRING + object.value :
    1.67 +     NO_EXCEPTION_STRING + object.value),
    1.68 +    result );
    1.69 +}

mercurial