js/src/tests/ecma_2/Statements/try-010.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-010.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     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-010.js
    1.12 + *  ECMA Section:
    1.13 + *  Description:        The try statement
    1.14 + *
    1.15 + *  This has a try block nested in the try block.  Verify that the
    1.16 + *  exception is caught by the right try block, and all finally blocks
    1.17 + *  are executed.
    1.18 + *
    1.19 + *  Author:             christine@netscape.com
    1.20 + *  Date:               11 August 1998
    1.21 + */
    1.22 +var SECTION = "try-010";
    1.23 +var VERSION = "ECMA_2";
    1.24 +var TITLE   = "The try statement: try in a tryblock";
    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 +NestedTry( new TryObject( "No Exceptions Thrown",  NoException, NoException, 43 ) );
    1.34 +NestedTry( new TryObject( "Throw Exception in Outer Try", ThrowException, NoException, 48 ));
    1.35 +NestedTry( new TryObject( "Throw Exception in Inner Try", NoException, ThrowException, 45 ));
    1.36 +NestedTry( new TryObject( "Throw Exception in Both Trys", ThrowException, ThrowException, 48 ));
    1.37 +
    1.38 +test();
    1.39 +
    1.40 +function TryObject( description, tryOne, tryTwo, result ) {
    1.41 +  this.description = description;
    1.42 +  this.tryOne = tryOne;
    1.43 +  this.tryTwo = tryTwo;
    1.44 +  this.result = result;
    1.45 +}
    1.46 +function ThrowException() {
    1.47 +  throw EXCEPTION_STRING + this.value;
    1.48 +}
    1.49 +function NoException() {
    1.50 +  return NO_EXCEPTION_STRING + this.value;
    1.51 +}
    1.52 +function NestedTry( object ) {
    1.53 +  result = 0;
    1.54 +  try {
    1.55 +    object.tryOne();
    1.56 +    result += 1;
    1.57 +    try {
    1.58 +      object.tryTwo();
    1.59 +      result += 2;
    1.60 +    } catch ( e ) {
    1.61 +      result +=4;
    1.62 +    } finally {
    1.63 +      result += 8;
    1.64 +    }
    1.65 +  } catch ( e ) {
    1.66 +    result += 16;
    1.67 +  } finally {
    1.68 +    result += 32;
    1.69 +  }
    1.70 +
    1.71 +  new TestCase(
    1.72 +    SECTION,
    1.73 +    object.description,
    1.74 +    object.result,
    1.75 +    result );
    1.76 +}

mercurial