Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/regress-50447-1.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 var gTestfile = 'regress-50447-1.js';
8
9 /*
10 * SUMMARY: New properties fileName, lineNumber have been added to Error objects
11 * in SpiderMonkey. These are non-ECMA extensions and do not exist in Rhino.
12 *
13 * See http://bugzilla.mozilla.org/show_bug.cgi?id=50447
14 *
15 * 2005-04-05 Modified by bclary to support changes to error reporting
16 * which set default values for the error's fileName and
17 * lineNumber properties.
18 */
19
20 //-----------------------------------------------------------------------------
21 var BUGNUMBER = 50447;
22 var summary = 'Test (non-ECMA) Error object properties fileName, lineNumber';
23
24
25 //-----------------------------------------------------------------------------
26 test();
27 //-----------------------------------------------------------------------------
28
29
30 function test()
31 {
32 enterFunc ('test');
33 printBugNumber(BUGNUMBER);
34 printStatus (summary);
35
36 testRealError();
37 test1();
38 test2();
39 test3();
40 test4();
41
42 exitFunc('test');
43 }
44
45
46 function testRealError()
47 {
48 /* throw a real error, and see what it looks like */
49 enterFunc ("testRealError");
50
51 try
52 {
53 blabla;
54 }
55 catch (e)
56 {
57 if (e.fileName.search (/-50447-1\.js$/i) == -1)
58 reportCompare('PASS', 'FAIL', "expected fileName to end with '-50447-1.js'");
59
60 reportCompare(87, e.lineNumber,
61 "lineNumber property returned unexpected value.");
62 }
63
64 exitFunc ("testRealError");
65 }
66
67
68 function test1()
69 {
70 /* generate an error with msg, file, and lineno properties */
71 enterFunc ("test1");
72
73 var e = new InternalError ("msg", "file", 2);
74 reportCompare ("(new InternalError(\"msg\", \"file\", 2))",
75 e.toSource(),
76 "toSource() returned unexpected result.");
77 reportCompare ("file", e.fileName,
78 "fileName property returned unexpected value.");
79 reportCompare (2, e.lineNumber,
80 "lineNumber property returned unexpected value.");
81
82 exitFunc ("test1");
83 }
84
85
86 function test2()
87 {
88 /* generate an error with only msg property */
89 enterFunc ("test2");
90
91 /* note this test incorporates the path to the
92 test file and assumes the path to the test case
93 is a subdirectory of the directory containing jsDriver.pl
94 */
95 var expectedLine = 141;
96 var expectedFileName = 'js1_5/extensions/regress-50447-1.js';
97 if (typeof document == "undefined")
98 {
99 expectedFileName = './' + expectedFileName;
100 }
101 else
102 {
103 expectedFileName = document.location.href.
104 replace(/[^\/]*(\?.*)$/, '') +
105 expectedFileName;
106 }
107 var e = new InternalError ("msg");
108 reportCompare ("(new InternalError(\"msg\", \"" +
109 expectedFileName + "\", " + expectedLine + "))",
110 e.toSource(),
111 "toSource() returned unexpected result.");
112 reportCompare (expectedFileName, e.fileName,
113 "fileName property returned unexpected value.");
114 reportCompare (expectedLine, e.lineNumber,
115 "lineNumber property returned unexpected value.");
116
117 exitFunc ("test2");
118 }
119
120
121 function test3()
122 {
123 /* generate an error with only msg and lineNo properties */
124
125 /* note this test incorporates the path to the
126 test file and assumes the path to the test case
127 is a subdirectory of the directory containing jsDriver.pl
128 */
129
130 enterFunc ("test3");
131
132 var expectedFileName = 'js1_5/extensions/regress-50447-1.js';
133 if (typeof document == "undefined")
134 {
135 expectedFileName = './' + expectedFileName;
136 }
137 else
138 {
139 expectedFileName = document.location.href.
140 replace(/[^\/]*(\?.*)$/, '') +
141 expectedFileName;
142 }
143
144 var e = new InternalError ("msg");
145 e.lineNumber = 10;
146 reportCompare ("(new InternalError(\"msg\", \"" +
147 expectedFileName + "\", 10))",
148 e.toSource(),
149 "toSource() returned unexpected result.");
150 reportCompare (expectedFileName, e.fileName,
151 "fileName property returned unexpected value.");
152 reportCompare (10, e.lineNumber,
153 "lineNumber property returned unexpected value.");
154
155 exitFunc ("test3");
156 }
157
158
159 function test4()
160 {
161 /* generate an error with only msg and filename properties */
162 enterFunc ("test4");
163
164 var expectedLine = 200;
165
166 var e = new InternalError ("msg", "file");
167 reportCompare ("(new InternalError(\"msg\", \"file\", " + expectedLine + "))",
168 e.toSource(),
169 "toSource() returned unexpected result.");
170 reportCompare ("file", e.fileName,
171 "fileName property returned unexpected value.");
172 reportCompare (expectedLine, e.lineNumber,
173 "lineNumber property returned unexpected value.");
174
175 exitFunc ("test4");
176 }