Debian Codegraph @

rhino/testsrc/tests/ecma_3/Exceptions/regress-181914.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: 25 Nov 2002
9 * SUMMARY: Calling a user-defined superconstructor
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=181914, esp. Comment 10.
11 *
12 */
13 //-----------------------------------------------------------------------------
14 var gTestfile = 'regress-181914.js';
15 var UBound = 0;
16 var BUGNUMBER = '181914';
17 var summary = 'Calling a user-defined superconstructor';
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 // make a user-defined version of the Error constructor
29 function _Error(msg)
30 {
31 this.message = msg;
32 }
33 _Error.prototype = new Error();
34 _Error.prototype.name = '_Error';
35
36
37 // derive MyApplyError from _Error
38 function MyApplyError(msg)
39 {
40 if(this instanceof MyApplyError)
41 _Error.apply(this, arguments);
42 else
43 return new MyApplyError(msg);
44 }
45 MyApplyError.prototype = new _Error();
46 MyApplyError.prototype.name = "MyApplyError";
47
48
49 // derive MyCallError from _Error
50 function MyCallError(msg)
51 {
52 if(this instanceof MyCallError)
53 _Error.call(this, msg);
54 else
55 return new MyCallError(msg);
56 }
57 MyCallError.prototype = new _Error();
58 MyCallError.prototype.name = "MyCallError";
59
60
61 function otherScope(msg)
62 {
63 return MyApplyError(msg);
64 }
65
66
67 status = inSection(1);
68 var err1 = new MyApplyError('msg1');
69 actual = examineThis(err1, 'msg1');
70 expect = EXPECTED_FORMAT;
71 addThis();
72
73 status = inSection(2);
74 var err2 = new MyCallError('msg2');
75 actual = examineThis(err2, 'msg2');
76 expect = EXPECTED_FORMAT;
77 addThis();
78
79 status = inSection(3);
80 var err3 = MyApplyError('msg3');
81 actual = examineThis(err3, 'msg3');
82 expect = EXPECTED_FORMAT;
83 addThis();
84
85 status = inSection(4);
86 var err4 = MyCallError('msg4');
87 actual = examineThis(err4, 'msg4');
88 expect = EXPECTED_FORMAT;
89 addThis();
90
91 status = inSection(5);
92 var err5 = otherScope('msg5');
93 actual = examineThis(err5, 'msg5');
94 expect = EXPECTED_FORMAT;
95 addThis();
96
97 status = inSection(6);
98 var err6 = otherScope();
99 actual = examineThis(err6, EMPTY_STRING);
100 expect = EXPECTED_FORMAT;
101 addThis();
102
103 status = inSection(7);
104 var err7 = eval("MyApplyError('msg7')");
105 actual = examineThis(err7, 'msg7');
106 expect = EXPECTED_FORMAT;
107 addThis();
108
109 status = inSection(8);
110 var err8;
111 try
112 {
113 throw MyApplyError('msg8');
114 }
115 catch(e)
116 {
117 if(e instanceof Error)
118 err8 = e;
119 }
120 actual = examineThis(err8, 'msg8');
121 expect = EXPECTED_FORMAT;
122 addThis();
123
124
125
126 //-----------------------------------------------------------------------------
127 test();
128 //-----------------------------------------------------------------------------
129
130
131
132 // Searches |err.toString()| for |err.name + ':' + err.message|
133 function examineThis(err, msg)
134 {
135 var pattern = err.name + '\\s*:?\\s*' + msg;
136 return err.toString().search(RegExp(pattern));
137 }
138
139
140 function addThis()
141 {
142 statusitems[UBound] = status;
143 actualvalues[UBound] = actual;
144 expectedvalues[UBound] = expect;
145 UBound++;
146 }
147
148
149 function test()
150 {
151 enterFunc ('test');
152 printBugNumber(BUGNUMBER);
153 printStatus (summary);
154
155 for (var i = 0; i < UBound; i++)
156 {
157 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
158 }
159
160 exitFunc ('test');
161 }