Debian Codegraph @

rhino/testsrc/tests/ecma_3/Exceptions/regress-181654.js

raw symbols SCIP
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 * Date: 23 Nov 2002
9 * SUMMARY: Calling toString for an object derived from the Error class
10 * results in an TypeError (Rhino only)
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=181654
12 */
13 //-----------------------------------------------------------------------------
14 var gTestfile = 'regress-181654.js';
15 var UBound = 0;
16 var BUGNUMBER = '181654';
17 var summary = 'Calling toString for an object derived from the Error class should be possible.';
18 var status = '';
19 var statusitems = [];
20 var actual = '';
21 var actualvalues = [];
22 var expect= '';
23 var expectedvalues = [];
24 var EMPTY_STRING = '';
25 var EXPECTED_FORMAT = 0;
26
27
28 // derive MyError from Error
29 function MyError( msg )
30 {
31 this.message = msg;
32 }
33 MyError.prototype = new Error();
34 MyError.prototype.name = "MyError";
35
36
37 status = inSection(1);
38 var err1 = new MyError('msg1');
39 actual = examineThis(err1, 'msg1');
40 expect = EXPECTED_FORMAT;
41 addThis();
42
43 status = inSection(2);
44 var err2 = new MyError(String(err1));
45 actual = examineThis(err2, err1);
46 expect = EXPECTED_FORMAT;
47 addThis();
48
49 status = inSection(3);
50 var err3 = new MyError();
51 actual = examineThis(err3, EMPTY_STRING);
52 expect = EXPECTED_FORMAT;
53 addThis();
54
55 status = inSection(4);
56 var err4 = new MyError(EMPTY_STRING);
57 actual = examineThis(err4, EMPTY_STRING);
58 expect = EXPECTED_FORMAT;
59 addThis();
60
61 // now generate an error -
62 status = inSection(5);
63 try
64 {
65 throw new MyError("thrown");
66 }
67 catch(err5)
68 {
69 actual = examineThis(err5, "thrown");
70 }
71 expect = EXPECTED_FORMAT;
72 addThis();
73
74
75
76 //-----------------------------------------------------------------------------
77 test();
78 //-----------------------------------------------------------------------------
79
80
81
82 /*
83 * Searches err.toString() for err.name + ':' + err.message,
84 * with possible whitespace on each side of the colon sign.
85 *
86 * We allow for no colon in case err.message was not provided by the user.
87 * In such a case, SpiderMonkey and Rhino currently set err.message = '',
88 * as allowed for by ECMA 15.11.4.3. This makes |pattern| work in this case.
89 *
90 * If this is ever changed to a non-empty string, e.g. 'undefined',
91 * you may have to modify |pattern| to take that into account -
92 *
93 */
94 function examineThis(err, msg)
95 {
96 var pattern = err.name + '\\s*:?\\s*' + msg;
97 return err.toString().search(RegExp(pattern));
98 }
99
100
101 function addThis()
102 {
103 statusitems[UBound] = status;
104 actualvalues[UBound] = actual;
105 expectedvalues[UBound] = expect;
106 UBound++;
107 }
108
109
110 function test()
111 {
112 enterFunc ('test');
113 printBugNumber(BUGNUMBER);
114 printStatus (summary);
115
116 for (var i = 0; i < UBound; i++)
117 {
118 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
119 }
120
121 exitFunc ('test');
122 }