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 //-----------------------------------------------------------------------------
53 var BUGNUMBER = 96284;
54 var summary = 'Double quotes should be escaped in Error.prototype.toSource()';
58 var actualvalues = [];
60 var expectedvalues = [];
63 var cnTestString = '"This is a \" STUPID \" test string!!!"\\';
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();
74 status = inSection(2);
75 obj1 = EvalError(cnTestString);
76 obj2 = eval(obj1.toSource());
77 actual = obj2.toSource();
78 expect = obj1.toSource();
81 status = inSection(3);
82 obj1 = RangeError(cnTestString);
83 obj2 = eval(obj1.toSource());
84 actual = obj2.toSource();
85 expect = obj1.toSource();
88 status = inSection(4);
89 obj1 = ReferenceError(cnTestString);
90 obj2 = eval(obj1.toSource());
91 actual = obj2.toSource();
92 expect = obj1.toSource();
95 status = inSection(5);
96 obj1 = SyntaxError(cnTestString);
97 obj2 = eval(obj1.toSource());
98 actual = obj2.toSource();
99 expect = obj1.toSource();
102 status = inSection(6);
103 obj1 = TypeError(cnTestString);
104 obj2 = eval(obj1.toSource());
105 actual = obj2.toSource();
106 expect = obj1.toSource();
109 status = inSection(7);
110 obj1 = URIError(cnTestString);
111 obj2 = eval(obj1.toSource());
112 actual = obj2.toSource();
113 expect = obj1.toSource();
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();
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();
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();
139 status = inSection(11);
140 obj1 = new Number(eval('6'));
141 obj2 = eval(obj1.toSource());
142 actual = obj2.toSource();
143 expect = obj1.toSource();
146 status = inSection(12);
147 obj1 = /ad;(lf)kj(2309\/\/)\/\//;
148 obj2 = eval(obj1.toSource());
149 actual = obj2.toSource();
150 expect = obj1.toSource();
155 //-----------------------------------------------------------------------------
157 //-----------------------------------------------------------------------------
162 statusitems[UBound] = status;
163 actualvalues[UBound] = actual;
164 expectedvalues[UBound] = expect;
172 printBugNumber(BUGNUMBER);
173 printStatus (summary);
175 for (var i = 0; i < UBound; i++)
177 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);