Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_5 / extensions / regress-96284-001.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is mozilla.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   pschwartau@netscape.com
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  * Date: 03 September 2001
41  *
42  * SUMMARY: Double quotes should be escaped in Error.prototype.toSource()
43  * See http://bugzilla.mozilla.org/show_bug.cgi?id=96284
44  *
45  * The real point here is this: we should be able to reconstruct an object
46  * from its toSource() property. We'll test this on various types of objects.
47  *
48  * Method: define obj2 = eval(obj1.toSource()) and verify that
49  * obj2.toSource() == obj1.toSource().
50  */
51 //-----------------------------------------------------------------------------
52 var UBound = 0;
53 var BUGNUMBER = 96284;
54 var summary = 'Double quotes should be escaped in Error.prototype.toSource()';
55 var status = '';
56 var statusitems = [];
57 var actual = '';
58 var actualvalues = [];
59 var expect= '';
60 var expectedvalues = [];
61 var obj1 = {};
62 var obj2 = {};
63 var cnTestString = '"This is a \" STUPID \" test string!!!"\\';
64
65
66 // various NativeError objects -
67 status = inSection(1);
68 obj1 = Error(cnTestString);
69 obj2 = eval(obj1.toSource());
70 actual = obj2.toSource();
71 expect = obj1.toSource();
72 addThis();
73
74 status = inSection(2);
75 obj1 = EvalError(cnTestString);
76 obj2 = eval(obj1.toSource());
77 actual = obj2.toSource();
78 expect = obj1.toSource();
79 addThis();
80
81 status = inSection(3);
82 obj1 = RangeError(cnTestString);
83 obj2 = eval(obj1.toSource());
84 actual = obj2.toSource();
85 expect = obj1.toSource();
86 addThis();
87
88 status = inSection(4);
89 obj1 = ReferenceError(cnTestString);
90 obj2 = eval(obj1.toSource());
91 actual = obj2.toSource();
92 expect = obj1.toSource();
93 addThis();
94
95 status = inSection(5);
96 obj1 = SyntaxError(cnTestString);
97 obj2 = eval(obj1.toSource());
98 actual = obj2.toSource();
99 expect = obj1.toSource();
100 addThis();
101
102 status = inSection(6);
103 obj1 = TypeError(cnTestString);
104 obj2 = eval(obj1.toSource());
105 actual = obj2.toSource();
106 expect = obj1.toSource();
107 addThis();
108
109 status = inSection(7);
110 obj1 = URIError(cnTestString);
111 obj2 = eval(obj1.toSource());
112 actual = obj2.toSource();
113 expect = obj1.toSource();
114 addThis();
115
116
117 // other types of objects -
118 status = inSection(8);
119 obj1 = new String(cnTestString);
120 obj2 = eval(obj1.toSource());
121 actual = obj2.toSource();
122 expect = obj1.toSource();
123 addThis();
124
125 status = inSection(9);
126 obj1 = {color:'red', texture:cnTestString, hasOwnProperty:42};
127 obj2 = eval(obj1.toSource());
128 actual = obj2.toSource();
129 expect = obj1.toSource();
130 addThis();
131
132 status = inSection(10);
133 obj1 = function(x) {function g(y){return y+1;} return g(x);};
134 obj2 = eval(obj1.toSource());
135 actual = obj2.toSource();
136 expect = obj1.toSource();
137 addThis();
138
139 status = inSection(11);
140 obj1 = new Number(eval('6'));
141 obj2 = eval(obj1.toSource());
142 actual = obj2.toSource();
143 expect = obj1.toSource();
144 addThis();
145
146 status = inSection(12);
147 obj1 = /ad;(lf)kj(2309\/\/)\/\//;
148 obj2 = eval(obj1.toSource());
149 actual = obj2.toSource();
150 expect = obj1.toSource();
151 addThis();
152
153
154
155 //-----------------------------------------------------------------------------
156 test();
157 //-----------------------------------------------------------------------------
158
159
160 function addThis()
161 {
162   statusitems[UBound] = status;
163   actualvalues[UBound] = actual;
164   expectedvalues[UBound] = expect;
165   UBound++;
166 }
167
168
169 function test()
170 {
171   enterFunc ('test');
172   printBugNumber(BUGNUMBER);
173   printStatus (summary);
174
175   for (var i = 0; i < UBound; i++)
176   {
177     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
178   }
179
180   exitFunc ('test');
181 }