~ubuntu-branches/ubuntu/vivid/mozjs24/vivid

« back to all changes in this revision

Viewing changes to js/src/tests/ecma_2/Statements/try-006.js

  • Committer: Package Import Robot
  • Author(s): Tim Lunn
  • Date: 2014-02-11 21:55:34 UTC
  • Revision ID: package-import@ubuntu.com-20140211215534-m1zyq5aj59md3y07
Tags: upstream-24.2.0
ImportĀ upstreamĀ versionĀ 24.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* This Source Code Form is subject to the terms of the Mozilla Public
 
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
5
 
 
6
 
 
7
/**
 
8
 *  File Name:          try-006.js
 
9
 *  ECMA Section:
 
10
 *  Description:        The try statement
 
11
 *
 
12
 *  Throw an exception from within a With block in a try block.  Verify
 
13
 *  that any expected exceptions are caught.
 
14
 *
 
15
 *  Author:             christine@netscape.com
 
16
 *  Date:               11 August 1998
 
17
 */
 
18
var SECTION = "try-006";
 
19
var VERSION = "ECMA_2";
 
20
var TITLE   = "The try statement";
 
21
 
 
22
startTest();
 
23
writeHeaderToLog( SECTION + " "+ TITLE);
 
24
 
 
25
/**
 
26
 *  This is the "check" function for test objects that will
 
27
 *  throw an exception.
 
28
 */
 
29
function throwException() {
 
30
  throw EXCEPTION_STRING +": " + this.valueOf();
 
31
}
 
32
var EXCEPTION_STRING = "Exception thrown:";
 
33
 
 
34
/**
 
35
 *  This is the "check" function for test objects that do not
 
36
 *  throw an exception
 
37
 */
 
38
function noException() {
 
39
  return this.valueOf();
 
40
}
 
41
 
 
42
/**
 
43
 *  Add test cases here
 
44
 */
 
45
TryWith( new TryObject( "hello", throwException, true ));
 
46
TryWith( new TryObject( "hola",  noException, false ));
 
47
 
 
48
/**
 
49
 *  Run the test.
 
50
 */
 
51
 
 
52
test();
 
53
 
 
54
/**
 
55
 *  This is the object that will be the "this" in a with block.
 
56
 */
 
57
function TryObject( value, fun, exception ) {
 
58
  this.value = value;
 
59
  this.exception = exception;
 
60
 
 
61
  this.valueOf = new Function ( "return this.value" );
 
62
  this.check = fun;
 
63
}
 
64
 
 
65
/**
 
66
 *  This function has the try block that has a with block within it.
 
67
 *  Test cases are added in this function.  Within the with block, the
 
68
 *  object's "check" function is called.  If the test object's exception
 
69
 *  property is true, we expect the result to be the exception value.
 
70
 *  If exception is false, then we expect the result to be the value of
 
71
 *  the object.
 
72
 */
 
73
function TryWith( object ) {
 
74
  try {
 
75
    with ( object ) {
 
76
      result = check();
 
77
    }
 
78
  } catch ( e ) {
 
79
    result = e;
 
80
  }
 
81
 
 
82
  new TestCase(
 
83
    SECTION,
 
84
    "TryWith( " + object.value +" )",
 
85
    (object.exception ? EXCEPTION_STRING +": " + object.valueOf() : object.valueOf()),
 
86
    result );
 
87
}