Bug 458113. Fix syntax error that broke OS/2 build. r+wuno
[wine-gecko.git] / js / tests / js1_5 / extensions / getset-003.js
blob3fd0b47d61a6f00c2b26503efffa27958dfa97d9
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.prop getter/setter
43 * Note: this is a non-ECMA extension to the language.
45 //-----------------------------------------------------------------------------
46 var gTestfile = 'getset-003.js';
47 var UBound = 0;
48 var BUGNUMBER = '(none)';
49 var summary = 'Testing obj.prop getter/setter';
50 var statprefix = 'Status: ';
51 var status = '';
52 var statusitems = [ ];
53 var actual = '';
54 var actualvalues = [ ];
55 var expect= '';
56 var expectedvalues = [ ];
57 var cnDEFAULT = 'default name';
58 var cnFRED = 'Fred';
59 var obj = {};
60 var obj2 = {};
61 var s = '';
64 // SECTION1: define getter/setter directly on an object (not its prototype)
65 obj = new Object();
66 obj.nameSETS = 0;
67 obj.nameGETS = 0;
68 obj.name setter = function(newValue) {this._name=newValue; this.nameSETS++;}
69 obj.name getter = function() {this.nameGETS++; return this._name;}
71 status = 'In SECTION1 of test after 0 sets, 0 gets';
72 actual = [obj.nameSETS,obj.nameGETS];
73 expect = [0,0];
74 addThis();
76 s = obj.name;
77 status = 'In SECTION1 of test after 0 sets, 1 get';
78 actual = [obj.nameSETS,obj.nameGETS];
79 expect = [0,1];
80 addThis();
82 obj.name = cnFRED;
83 status = 'In SECTION1 of test after 1 set, 1 get';
84 actual = [obj.nameSETS,obj.nameGETS];
85 expect = [1,1];
86 addThis();
88 obj.name = obj.name;
89 status = 'In SECTION1 of test after 2 sets, 2 gets';
90 actual = [obj.nameSETS,obj.nameGETS];
91 expect = [2,2];
92 addThis();
95 // SECTION2: define getter/setter in Object.prototype
96 Object.prototype.nameSETS = 0;
97 Object.prototype.nameGETS = 0;
98 Object.prototype.name setter = function(newValue) {this._name=newValue; this.nameSETS++;}
99 Object.prototype.name getter = function() {this.nameGETS++; return this._name;}
101 obj = new Object();
102 status = 'In SECTION2 of test after 0 sets, 0 gets';
103 actual = [obj.nameSETS,obj.nameGETS];
104 expect = [0,0];
105 addThis();
107 s = obj.name;
108 status = 'In SECTION2 of test after 0 sets, 1 get';
109 actual = [obj.nameSETS,obj.nameGETS];
110 expect = [0,1];
111 addThis();
113 obj.name = cnFRED;
114 status = 'In SECTION2 of test after 1 set, 1 get';
115 actual = [obj.nameSETS,obj.nameGETS];
116 expect = [1,1];
117 addThis();
119 obj.name = obj.name;
120 status = 'In SECTION2 of test after 2 sets, 2 gets';
121 actual = [obj.nameSETS,obj.nameGETS];
122 expect = [2,2];
123 addThis();
126 // SECTION 3: define getter/setter in prototype of user-defined constructor
127 function TestObject()
130 TestObject.prototype.nameSETS = 0;
131 TestObject.prototype.nameGETS = 0;
132 TestObject.prototype.name setter = function(newValue) {this._name=newValue; this.nameSETS++;}
133 TestObject.prototype.name getter = function() {this.nameGETS++; return this._name;}
134 TestObject.prototype.name = cnDEFAULT;
136 obj = new TestObject();
137 status = 'In SECTION3 of test after 1 set, 0 gets'; // (we set a default value in the prototype)
138 actual = [obj.nameSETS,obj.nameGETS];
139 expect = [1,0];
140 addThis();
142 s = obj.name;
143 status = 'In SECTION3 of test after 1 set, 1 get';
144 actual = [obj.nameSETS,obj.nameGETS];
145 expect = [1,1];
146 addThis();
148 obj.name = cnFRED;
149 status = 'In SECTION3 of test after 2 sets, 1 get';
150 actual = [obj.nameSETS,obj.nameGETS];
151 expect = [2,1];
152 addThis();
154 obj.name = obj.name;
155 status = 'In SECTION3 of test after 3 sets, 2 gets';
156 actual = [obj.nameSETS,obj.nameGETS];
157 expect = [3,2];
158 addThis();
160 obj2 = new TestObject();
161 status = 'obj2 = new TestObject() after 1 set, 0 gets';
162 actual = [obj2.nameSETS,obj2.nameGETS];
163 expect = [1,0]; // we set a default value in the prototype -
164 addThis();
166 // Use both obj and obj2 -
167 obj2.name = obj.name + obj2.name;
168 status = 'obj2 = new TestObject() after 2 sets, 1 get';
169 actual = [obj2.nameSETS,obj2.nameGETS];
170 expect = [2,1];
171 addThis();
173 status = 'In SECTION3 of test after 3 sets, 3 gets';
174 actual = [obj.nameSETS,obj.nameGETS];
175 expect = [3,3]; // we left off at [3,2] above -
176 addThis();
179 //---------------------------------------------------------------------------------
180 test();
181 //---------------------------------------------------------------------------------
184 function addThis()
186 statusitems[UBound] = status;
187 actualvalues[UBound] = actual.toString();
188 expectedvalues[UBound] = expect.toString();
189 UBound++;
193 function test()
195 enterFunc ('test');
196 printBugNumber(BUGNUMBER);
197 printStatus (summary);
199 for (var i = 0; i < UBound; i++)
201 reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
204 exitFunc ('test');
208 function getStatus(i)
210 return statprefix + statusitems[i];