Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/regress-50447.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.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
16 //-----------------------------------------------------------------------------
17 var BUGNUMBER = 50447;
18 var summary = 'Test (non-ECMA) Error object properties fileName, lineNumber';
19
20
21 //-----------------------------------------------------------------------------
22 test();
23 //-----------------------------------------------------------------------------
24
25
26 function test()
27 {
28 enterFunc ('test');
29 printBugNumber(BUGNUMBER);
30 printStatus (summary);
31
32 testRealError();
33 test1();
34 test2();
35 test3();
36 test4();
37
38 exitFunc('test');
39 }
40
41
42 function testRealError()
43 {
44 /* throw a real error, and see what it looks like */
45 enterFunc ("testRealError");
46
47 try
48 {
49 blabla;
50 }
51 catch (e)
52 {
53 if (e.fileName.search (/-50447\.js$/i) == -1)
54 reportCompare('PASS', 'FAIL',
55 "expected fileName to end with '-50447.js'");
56
57 reportCompare (49, e.lineNumber,
58 "lineNumber property returned unexpected value.");
59 }
60
61 exitFunc ("testRealError");
62 }
63
64
65 function test1()
66 {
67 /* generate an error with msg, file, and lineno properties */
68 enterFunc ("test1");
69
70 var e = new InternalError ("msg", "file", 2);
71 reportCompare ("(new InternalError(\"msg\", \"file\", 2))",
72 e.toSource(),
73 "toSource() returned unexpected result.");
74 reportCompare ("file", e.fileName,
75 "fileName property returned unexpected value.");
76 reportCompare (2, e.lineNumber,
77 "lineNumber property returned unexpected value.");
78
79 exitFunc ("test1");
80 }
81
82
83 function test2()
84 {
85 /* generate an error with only msg property */
86 enterFunc ("test2");
87
88 var e = new InternalError ("msg");
89 reportCompare ("(new InternalError(\"msg\", \"\"))",
90 e.toSource(),
91 "toSource() returned unexpected result.");
92 reportCompare ("", e.fileName,
93 "fileName property returned unexpected value.");
94 reportCompare (0, e.lineNumber,
95 "lineNumber property returned unexpected value.");
96
97 exitFunc ("test2");
98 }
99
100
101 function test3()
102 {
103 /* generate an error with only msg and lineNo properties */
104 enterFunc ("test3");
105
106 var e = new InternalError ("msg");
107 e.lineNumber = 10;
108 reportCompare ("(new InternalError(\"msg\", \"\", 10))",
109 e.toSource(),
110 "toSource() returned unexpected result.");
111 reportCompare ("", e.fileName,
112 "fileName property returned unexpected value.");
113 reportCompare (10, e.lineNumber,
114 "lineNumber property returned unexpected value.");
115
116 exitFunc ("test3");
117 }
118
119
120 function test4()
121 {
122 /* generate an error with only msg and filename properties */
123 enterFunc ("test4");
124
125 var e = new InternalError ("msg", "file");
126 reportCompare ("(new InternalError(\"msg\", \"file\"))",
127 e.toSource(),
128 "toSource() returned unexpected result.");
129 reportCompare ("file", e.fileName,
130 "fileName property returned unexpected value.");
131 reportCompare (0, e.lineNumber,
132 "lineNumber property returned unexpected value.");
133
134 exitFunc ("test4");
135 }