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
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/
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
15 * The Original Code is mozilla.org code.
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.
23 * pschwartau@netscape.com
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.
37 * ***** END LICENSE BLOCK ***** */
40 * Date: 03 September 2001
42 * SUMMARY: Double quotes should be escaped in Error.prototype.toSource()
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=96284
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.
48 * Method: define obj2 = eval(obj1.toSource()) and verify that
49 * obj2.toSource() == obj1.toSource().
51 //-----------------------------------------------------------------------------
52 var gTestfile
= 'regress-96284-001.js';
54 var BUGNUMBER
= 96284;
55 var summary
= 'Double quotes should be escaped in Error.prototype.toSource()';
59 var actualvalues
= [];
61 var expectedvalues
= [];
64 var cnTestString
= '"This is a \" STUPID \" test string!!!"\\';
67 // various NativeError objects -
68 status
= inSection(1);
69 obj1
= Error(cnTestString
);
70 obj2
= eval(obj1
.toSource());
71 actual
= obj2
.toSource();
72 expect
= obj1
.toSource();
75 status
= inSection(2);
76 obj1
= EvalError(cnTestString
);
77 obj2
= eval(obj1
.toSource());
78 actual
= obj2
.toSource();
79 expect
= obj1
.toSource();
82 status
= inSection(3);
83 obj1
= RangeError(cnTestString
);
84 obj2
= eval(obj1
.toSource());
85 actual
= obj2
.toSource();
86 expect
= obj1
.toSource();
89 status
= inSection(4);
90 obj1
= ReferenceError(cnTestString
);
91 obj2
= eval(obj1
.toSource());
92 actual
= obj2
.toSource();
93 expect
= obj1
.toSource();
96 status
= inSection(5);
97 obj1
= SyntaxError(cnTestString
);
98 obj2
= eval(obj1
.toSource());
99 actual
= obj2
.toSource();
100 expect
= obj1
.toSource();
103 status
= inSection(6);
104 obj1
= TypeError(cnTestString
);
105 obj2
= eval(obj1
.toSource());
106 actual
= obj2
.toSource();
107 expect
= obj1
.toSource();
110 status
= inSection(7);
111 obj1
= URIError(cnTestString
);
112 obj2
= eval(obj1
.toSource());
113 actual
= obj2
.toSource();
114 expect
= obj1
.toSource();
118 // other types of objects -
119 status
= inSection(8);
120 obj1
= new String(cnTestString
);
121 obj2
= eval(obj1
.toSource());
122 actual
= obj2
.toSource();
123 expect
= obj1
.toSource();
126 status
= inSection(9);
127 obj1
= {color
:'red', texture
:cnTestString
, hasOwnProperty
:42};
128 obj2
= eval(obj1
.toSource());
129 actual
= obj2
.toSource();
130 expect
= obj1
.toSource();
133 status
= inSection(10);
134 obj1 = function(x
) {function g(y
){return y
+1;} return g(x
);};
135 obj2
= eval(obj1
.toSource());
136 actual
= obj2
.toSource();
137 expect
= obj1
.toSource();
140 status
= inSection(11);
141 obj1
= new Number(eval('6'));
142 obj2
= eval(obj1
.toSource());
143 actual
= obj2
.toSource();
144 expect
= obj1
.toSource();
147 status
= inSection(12);
148 obj1
= /ad;(lf)kj(2309\/\/)\/\//;
149 obj2
= eval(obj1
.toSource());
150 actual
= obj2
.toSource();
151 expect
= obj1
.toSource();
156 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
163 statusitems
[UBound
] = status
;
164 actualvalues
[UBound
] = actual
;
165 expectedvalues
[UBound
] = expect
;
173 printBugNumber(BUGNUMBER
);
174 printStatus (summary
);
176 for (var i
= 0; i
< UBound
; i
++)
178 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);