js/src/tests/js1_5/extensions/regress-96284-001.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:c2ab6cc4b029
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 * Date: 03 September 2001
8 *
9 * SUMMARY: Double quotes should be escaped in Error.prototype.toSource()
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=96284
11 *
12 * The real point here is this: we should be able to reconstruct an object
13 * from its toSource() property. We'll test this on various types of objects.
14 *
15 * Method: define obj2 = eval(obj1.toSource()) and verify that
16 * obj2.toSource() == obj1.toSource().
17 */
18 //-----------------------------------------------------------------------------
19 var UBound = 0;
20 var BUGNUMBER = 96284;
21 var summary = 'Double quotes should be escaped in Error.prototype.toSource()';
22 var status = '';
23 var statusitems = [];
24 var actual = '';
25 var actualvalues = [];
26 var expect= '';
27 var expectedvalues = [];
28 var obj1 = {};
29 var obj2 = {};
30 var cnTestString = '"This is a \" STUPID \" test string!!!"\\';
31
32
33 // various NativeError objects -
34 status = inSection(1);
35 obj1 = Error(cnTestString);
36 obj2 = eval(obj1.toSource());
37 actual = obj2.toSource();
38 expect = obj1.toSource();
39 addThis();
40
41 status = inSection(2);
42 obj1 = EvalError(cnTestString);
43 obj2 = eval(obj1.toSource());
44 actual = obj2.toSource();
45 expect = obj1.toSource();
46 addThis();
47
48 status = inSection(3);
49 obj1 = RangeError(cnTestString);
50 obj2 = eval(obj1.toSource());
51 actual = obj2.toSource();
52 expect = obj1.toSource();
53 addThis();
54
55 status = inSection(4);
56 obj1 = ReferenceError(cnTestString);
57 obj2 = eval(obj1.toSource());
58 actual = obj2.toSource();
59 expect = obj1.toSource();
60 addThis();
61
62 status = inSection(5);
63 obj1 = SyntaxError(cnTestString);
64 obj2 = eval(obj1.toSource());
65 actual = obj2.toSource();
66 expect = obj1.toSource();
67 addThis();
68
69 status = inSection(6);
70 obj1 = TypeError(cnTestString);
71 obj2 = eval(obj1.toSource());
72 actual = obj2.toSource();
73 expect = obj1.toSource();
74 addThis();
75
76 status = inSection(7);
77 obj1 = URIError(cnTestString);
78 obj2 = eval(obj1.toSource());
79 actual = obj2.toSource();
80 expect = obj1.toSource();
81 addThis();
82
83
84 // other types of objects -
85 status = inSection(8);
86 obj1 = new String(cnTestString);
87 obj2 = eval(obj1.toSource());
88 actual = obj2.toSource();
89 expect = obj1.toSource();
90 addThis();
91
92 status = inSection(9);
93 obj1 = {color:'red', texture:cnTestString, hasOwnProperty:42};
94 obj2 = eval(obj1.toSource());
95 actual = obj2.toSource();
96 expect = obj1.toSource();
97 addThis();
98
99 status = inSection(10);
100 obj1 = function(x) {function g(y){return y+1;} return g(x);};
101 obj2 = eval(obj1.toSource());
102 actual = obj2.toSource();
103 expect = obj1.toSource();
104 addThis();
105
106 status = inSection(11);
107 obj1 = new Number(eval('6'));
108 obj2 = eval(obj1.toSource());
109 actual = obj2.toSource();
110 expect = obj1.toSource();
111 addThis();
112
113 status = inSection(12);
114 obj1 = /ad;(lf)kj(2309\/\/)\/\//;
115 obj2 = eval(obj1.toSource());
116 actual = obj2.toSource();
117 expect = obj1.toSource();
118 addThis();
119
120
121
122 //-----------------------------------------------------------------------------
123 test();
124 //-----------------------------------------------------------------------------
125
126
127 function addThis()
128 {
129 statusitems[UBound] = status;
130 actualvalues[UBound] = actual;
131 expectedvalues[UBound] = expect;
132 UBound++;
133 }
134
135
136 function test()
137 {
138 enterFunc ('test');
139 printBugNumber(BUGNUMBER);
140 printStatus (summary);
141
142 for (var i = 0; i < UBound; i++)
143 {
144 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
145 }
146
147 exitFunc ('test');
148 }

mercurial