1/*
2* The contents of this file are subject to the Netscape Public
3* License Version 1.1 (the "License"); you may not use this file
4* except in compliance with the License. You may obtain a copy of
5* the License at http://www.mozilla.org/NPL/
6*
7* Software distributed under the License is distributed on an "AS
8* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9* implied. See the License for the specific language governing
10* rights and limitations under the License.
11*
12* The Original Code is mozilla.org code.
13*
14* The Initial Developer of the Original Code is Netscape
15* Communications Corporation.  Portions created by Netscape are
16* Copyright (C) 1998 Netscape Communications Corporation.
17* All Rights Reserved.
18*
19* Contributor(s): pschwartau@netscape.com
20* Date: 03 September 2001
21*
22* SUMMARY: Double quotes should be escaped in uneval(new Error('""'))
23* See http://bugzilla.mozilla.org/show_bug.cgi?id=96284
24*
25* The real point here is this: we should be able to reconstruct an object
26* obj from uneval(obj). We'll test this on various types of objects.
27*
28* Method: define obj2 = eval(uneval(obj1)) and verify that
29* obj2.toSource() == obj1.toSource().
30*/
31//-----------------------------------------------------------------------------
32var UBound = 0;
33var bug = 96284;
34var summary = 'Double quotes should be escaped in Error.prototype.toSource()';
35var status = '';
36var statusitems = [];
37var actual = '';
38var actualvalues = [];
39var expect= '';
40var expectedvalues = [];
41var obj1 = {};
42var obj2 = {};
43var cnTestString = '"This is a \" STUPID \" test string!!!"\\';
44
45
46// various NativeError objects -
47status = inSection(1);
48obj1 = Error(cnTestString);
49obj2 = eval(uneval(obj1));
50actual = obj2.toSource();
51expect = obj1.toSource();
52addThis();
53
54status = inSection(2);
55obj1 = EvalError(cnTestString);
56obj2 = eval(uneval(obj1));
57actual = obj2.toSource();
58expect = obj1.toSource();
59addThis();
60
61status = inSection(3);
62obj1 = RangeError(cnTestString);
63obj2 = eval(uneval(obj1));
64actual = obj2.toSource();
65expect = obj1.toSource();
66addThis();
67
68status = inSection(4);
69obj1 = ReferenceError(cnTestString);
70obj2 = eval(uneval(obj1));
71actual = obj2.toSource();
72expect = obj1.toSource();
73addThis();
74
75status = inSection(5);
76obj1 = SyntaxError(cnTestString);
77obj2 = eval(uneval(obj1));
78actual = obj2.toSource();
79expect = obj1.toSource();
80addThis();
81
82status = inSection(6);
83obj1 = TypeError(cnTestString);
84obj2 = eval(uneval(obj1));
85actual = obj2.toSource();
86expect = obj1.toSource();
87addThis();
88
89status = inSection(7);
90obj1 = URIError(cnTestString);
91obj2 = eval(uneval(obj1));
92actual = obj2.toSource();
93expect = obj1.toSource();
94addThis();
95
96
97// other types of objects -
98status = inSection(8);
99obj1 = new String(cnTestString);
100obj2 = eval(uneval(obj1));
101actual = obj2.toSource();
102expect = obj1.toSource();
103addThis();
104
105status = inSection(9);
106obj1 = {color:'red', texture:cnTestString, hasOwnProperty:42};
107obj2 = eval(uneval(obj1));
108actual = obj2.toSource();
109expect = obj1.toSource();
110addThis();
111
112status = inSection(10);
113obj1 = function(x) {function g(y){return y+1;} return g(x);};
114obj2 = eval(uneval(obj1));
115actual = obj2.toSource();
116expect = obj1.toSource();
117addThis();
118
119status = inSection(11);
120obj1 = new Number(eval('6'));
121obj2 = eval(uneval(obj1));
122actual = obj2.toSource();
123expect = obj1.toSource();
124addThis();
125
126status = inSection(12);
127obj1 = /ad;(lf)kj(2309\/\/)\/\//;
128obj2 = eval(uneval(obj1));
129actual = obj2.toSource();
130expect = obj1.toSource();
131addThis();
132
133
134
135//-----------------------------------------------------------------------------
136test();
137//-----------------------------------------------------------------------------
138
139
140function addThis()
141{
142  statusitems[UBound] = status;
143  actualvalues[UBound] = actual;
144  expectedvalues[UBound] = expect;
145  UBound++;
146}
147
148
149function test()
150{
151  enterFunc ('test');
152  printBugNumber (bug);
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}
162