js/src/tests/js1_5/extensions/regress-50447-1.js

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

mercurial