Bug 458113. Fix syntax error that broke OS/2 build. r+wuno
[wine-gecko.git] / js / tests / js1_5 / extensions / getset-005.js
blob88813c05d4fb11395d2ca8ed901741cdff207692
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
13 * License.
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.
22 * Contributor(s):
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: 14 April 2001
42 * SUMMARY: Testing obj.__defineSetter__(), obj.__defineGetter__()
43 * Note: this is a non-ECMA language extension
45 * This test is the same as getset-004.js, except that here we
46 * store the getter/setter functions in global variables.
48 //-----------------------------------------------------------------------------
49 var gTestfile = 'getset-005.js';
50 var UBound = 0;
51 var BUGNUMBER = '(none)';
52 var summary = 'Testing obj.__defineSetter__(), obj.__defineGetter__()';
53 var statprefix = 'Status: ';
54 var status = '';
55 var statusitems = [ ];
56 var actual = '';
57 var actualvalues = [ ];
58 var expect= '';
59 var expectedvalues = [ ];
60 var cnName = 'name';
61 var cnDEFAULT = 'default name';
62 var cnFRED = 'Fred';
63 var obj = {};
64 var obj2 = {};
65 var s = '';
68 // The getter/setter functions we'll use in all three sections below -
69 var cnNameSetter = function(newValue) {this._name=newValue; this.nameSETS++;};
70 var cnNameGetter = function() {this.nameGETS++; return this._name;};
73 // SECTION1: define getter/setter directly on an object (not its prototype)
74 obj = new Object();
75 obj.nameSETS = 0;
76 obj.nameGETS = 0;
77 obj.__defineSetter__(cnName, cnNameSetter);
78 obj.__defineGetter__(cnName, cnNameGetter);
80 status = 'In SECTION1 of test after 0 sets, 0 gets';
81 actual = [obj.nameSETS,obj.nameGETS];
82 expect = [0,0];
83 addThis();
85 s = obj.name;
86 status = 'In SECTION1 of test after 0 sets, 1 get';
87 actual = [obj.nameSETS,obj.nameGETS];
88 expect = [0,1];
89 addThis();
91 obj.name = cnFRED;
92 status = 'In SECTION1 of test after 1 set, 1 get';
93 actual = [obj.nameSETS,obj.nameGETS];
94 expect = [1,1];
95 addThis();
97 obj.name = obj.name;
98 status = 'In SECTION1 of test after 2 sets, 2 gets';
99 actual = [obj.nameSETS,obj.nameGETS];
100 expect = [2,2];
101 addThis();
104 // SECTION2: define getter/setter in Object.prototype
105 Object.prototype.nameSETS = 0;
106 Object.prototype.nameGETS = 0;
107 Object.prototype.__defineSetter__(cnName, cnNameSetter);
108 Object.prototype.__defineGetter__(cnName, cnNameGetter);
110 obj = new Object();
111 status = 'In SECTION2 of test after 0 sets, 0 gets';
112 actual = [obj.nameSETS,obj.nameGETS];
113 expect = [0,0];
114 addThis();
116 s = obj.name;
117 status = 'In SECTION2 of test after 0 sets, 1 get';
118 actual = [obj.nameSETS,obj.nameGETS];
119 expect = [0,1];
120 addThis();
122 obj.name = cnFRED;
123 status = 'In SECTION2 of test after 1 set, 1 get';
124 actual = [obj.nameSETS,obj.nameGETS];
125 expect = [1,1];
126 addThis();
128 obj.name = obj.name;
129 status = 'In SECTION2 of test after 2 sets, 2 gets';
130 actual = [obj.nameSETS,obj.nameGETS];
131 expect = [2,2];
132 addThis();
135 // SECTION 3: define getter/setter in prototype of user-defined constructor
136 function TestObject()
139 TestObject.prototype.nameSETS = 0;
140 TestObject.prototype.nameGETS = 0;
141 TestObject.prototype.__defineSetter__(cnName, cnNameSetter);
142 TestObject.prototype.__defineGetter__(cnName, cnNameGetter);
143 TestObject.prototype.name = cnDEFAULT;
145 obj = new TestObject();
146 status = 'In SECTION3 of test after 1 set, 0 gets'; // (we set a default value in the prototype)
147 actual = [obj.nameSETS,obj.nameGETS];
148 expect = [1,0];
149 addThis();
151 s = obj.name;
152 status = 'In SECTION3 of test after 1 set, 1 get';
153 actual = [obj.nameSETS,obj.nameGETS];
154 expect = [1,1];
155 addThis();
157 obj.name = cnFRED;
158 status = 'In SECTION3 of test after 2 sets, 1 get';
159 actual = [obj.nameSETS,obj.nameGETS];
160 expect = [2,1];
161 addThis();
163 obj.name = obj.name;
164 status = 'In SECTION3 of test after 3 sets, 2 gets';
165 actual = [obj.nameSETS,obj.nameGETS];
166 expect = [3,2];
167 addThis();
169 obj2 = new TestObject();
170 status = 'obj2 = new TestObject() after 1 set, 0 gets';
171 actual = [obj2.nameSETS,obj2.nameGETS];
172 expect = [1,0]; // we set a default value in the prototype -
173 addThis();
175 // Use both obj and obj2 -
176 obj2.name = obj.name + obj2.name;
177 status = 'obj2 = new TestObject() after 2 sets, 1 get';
178 actual = [obj2.nameSETS,obj2.nameGETS];
179 expect = [2,1];
180 addThis();
182 status = 'In SECTION3 of test after 3 sets, 3 gets';
183 actual = [obj.nameSETS,obj.nameGETS];
184 expect = [3,3]; // we left off at [3,2] above -
185 addThis();
188 //---------------------------------------------------------------------------------
189 test();
190 //---------------------------------------------------------------------------------
193 function addThis()
195 statusitems[UBound] = status;
196 actualvalues[UBound] = actual.toString();
197 expectedvalues[UBound] = expect.toString();
198 UBound++;
202 function test()
204 enterFunc ('test');
205 printBugNumber(BUGNUMBER);
206 printStatus (summary);
208 for (var i = 0; i < UBound; i++)
210 reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
213 exitFunc ('test');
217 function getStatus(i)
219 return statprefix + statusitems[i];