Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/regress-96284-001.js

raw symbols SCIP
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 gTestfile = 'regress-96284-001.js';
20 var UBound = 0;
21 var BUGNUMBER = 96284;
22 var summary = 'Double quotes should be escaped in Error.prototype.toSource()';
23 var status = '';
24 var statusitems = [];
25 var actual = '';
26 var actualvalues = [];
27 var expect= '';
28 var expectedvalues = [];
29 var obj1 = {};
30 var obj2 = {};
31 var cnTestString = '"This is a \" STUPID \" test string!!!"\\';
32
33
34 // various NativeError objects -
35 status = inSection(1);
36 obj1 = Error(cnTestString);
37 obj2 = eval(obj1.toSource());
38 actual = obj2.toSource();
39 expect = obj1.toSource();
40 addThis();
41
42 status = inSection(2);
43 obj1 = EvalError(cnTestString);
44 obj2 = eval(obj1.toSource());
45 actual = obj2.toSource();
46 expect = obj1.toSource();
47 addThis();
48
49 status = inSection(3);
50 obj1 = RangeError(cnTestString);
51 obj2 = eval(obj1.toSource());
52 actual = obj2.toSource();
53 expect = obj1.toSource();
54 addThis();
55
56 status = inSection(4);
57 obj1 = ReferenceError(cnTestString);
58 obj2 = eval(obj1.toSource());
59 actual = obj2.toSource();
60 expect = obj1.toSource();
61 addThis();
62
63 status = inSection(5);
64 obj1 = SyntaxError(cnTestString);
65 obj2 = eval(obj1.toSource());
66 actual = obj2.toSource();
67 expect = obj1.toSource();
68 addThis();
69
70 status = inSection(6);
71 obj1 = TypeError(cnTestString);
72 obj2 = eval(obj1.toSource());
73 actual = obj2.toSource();
74 expect = obj1.toSource();
75 addThis();
76
77 status = inSection(7);
78 obj1 = URIError(cnTestString);
79 obj2 = eval(obj1.toSource());
80 actual = obj2.toSource();
81 expect = obj1.toSource();
82 addThis();
83
84
85 // other types of objects -
86 status = inSection(8);
87 obj1 = new String(cnTestString);
88 obj2 = eval(obj1.toSource());
89 actual = obj2.toSource();
90 expect = obj1.toSource();
91 addThis();
92
93 status = inSection(9);
94 obj1 = {color:'red', texture:cnTestString, hasOwnProperty:42};
95 obj2 = eval(obj1.toSource());
96 actual = obj2.toSource();
97 expect = obj1.toSource();
98 addThis();
99
100 status = inSection(10);
101 obj1 = function(x) {function g(y){return y+1;} return g(x);};
102 obj2 = eval(obj1.toSource());
103 actual = obj2.toSource();
104 expect = obj1.toSource();
105 addThis();
106
107 status = inSection(11);
108 obj1 = new Number(eval('6'));
109 obj2 = eval(obj1.toSource());
110 actual = obj2.toSource();
111 expect = obj1.toSource();
112 addThis();
113
114 status = inSection(12);
115 obj1 = /ad;(lf)kj(2309\/\/)\/\//;
116 obj2 = eval(obj1.toSource());
117 actual = obj2.toSource();
118 expect = obj1.toSource();
119 addThis();
120
121
122
123 //-----------------------------------------------------------------------------
124 test();
125 //-----------------------------------------------------------------------------
126
127
128 function addThis()
129 {
130 statusitems[UBound] = status;
131 actualvalues[UBound] = actual;
132 expectedvalues[UBound] = expect;
133 UBound++;
134 }
135
136
137 function test()
138 {
139 enterFunc ('test');
140 printBugNumber(BUGNUMBER);
141 printStatus (summary);
142
143 for (var i = 0; i < UBound; i++)
144 {
145 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
146 }
147
148 exitFunc ('test');
149 }