]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/GetSet/getset-006.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an "AS IS"
8 * basis, WITHOUT WARRANTY OF ANY KIND, either expressed
9 * or implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
19 * Contributor(s): pschwartau@netscape.com
22 * SUMMARY: Testing obj.__lookupGetter__(), obj.__lookupSetter__()
23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=71992
25 * Brendan: "I see no need to provide more than the minimum:
26 * o.__lookupGetter__('p') returns the getter function for o.p,
27 * or undefined if o.p has no getter. Users can wrap and layer."
29 //-------------------------------------------------------------------------------------------------
32 var summary
= 'Testing obj.__lookupGetter__(), obj.__lookupSetter__()';
33 var statprefix
= 'Status: ';
35 var statusitems
= [ ];
37 var actualvalues
= [ ];
39 var expectedvalues
= [ ];
41 var cnColor
= 'color';
42 var cnNonExistingProp
= 'ASDF_#_$%';
43 var cnDEFAULT
= 'default name';
51 // The only setter and getter functions we'll use in the three sections below -
52 var cnNameSetter = function(newValue
) {this._name
=newValue
; this.nameSETS
++;};
53 var cnNameGetter = function() {this.nameGETS
++; return this._name
;};
57 // SECTION1: define getter/setter directly on an object (not its prototype)
61 obj
.__defineSetter__(cnName
, cnNameSetter
);
62 obj
.__defineGetter__(cnName
, cnNameGetter
);
66 status
='In SECTION1 of test; looking up extant getter/setter';
67 actual
= [obj
.__lookupSetter__(cnName
), obj
.__lookupGetter__(cnName
)];
68 expect
= [cnNameSetter
, cnNameGetter
];
71 status
= 'In SECTION1 of test; looking up nonexistent getter/setter';
72 actual
= [obj
.__lookupSetter__(cnColor
), obj
.__lookupGetter__(cnColor
)];
73 expect
= [undefined, undefined];
76 status
= 'In SECTION1 of test; looking up getter/setter on nonexistent property';
77 actual
= [obj
.__lookupSetter__(cnNonExistingProp
), obj
.__lookupGetter__(cnNonExistingProp
)];
78 expect
= [undefined, undefined];
83 // SECTION2: define getter/setter in Object.prototype
84 Object
.prototype.nameSETS
= 0;
85 Object
.prototype.nameGETS
= 0;
86 Object
.prototype.__defineSetter__(cnName
, cnNameSetter
);
87 Object
.prototype.__defineGetter__(cnName
, cnNameGetter
);
93 status
= 'In SECTION2 of test looking up extant getter/setter';
94 actual
= [obj
.__lookupSetter__(cnName
), obj
.__lookupGetter__(cnName
)];
95 expect
= [cnNameSetter
, cnNameGetter
];
98 status
= 'In SECTION2 of test; looking up nonexistent getter/setter';
99 actual
= [obj
.__lookupSetter__(cnColor
), obj
.__lookupGetter__(cnColor
)];
100 expect
= [undefined, undefined];
103 status
= 'In SECTION2 of test; looking up getter/setter on nonexistent property';
104 actual
= [obj
.__lookupSetter__(cnNonExistingProp
), obj
.__lookupGetter__(cnNonExistingProp
)];
105 expect
= [undefined, undefined];
110 // SECTION 3: define getter/setter in prototype of user-defined constructor
111 function TestObject()
114 TestObject
.prototype.nameSETS
= 0;
115 TestObject
.prototype.nameGETS
= 0;
116 TestObject
.prototype.__defineSetter__(cnName
, cnNameSetter
);
117 TestObject
.prototype.__defineGetter__(cnName
, cnNameGetter
);
118 TestObject
.prototype.name
= cnDEFAULT
;
120 obj
= new TestObject();
124 status
= 'In SECTION3 of test looking up extant getter/setter';
125 actual
= [obj
.__lookupSetter__(cnName
), obj
.__lookupGetter__(cnName
)];
126 expect
= [cnNameSetter
, cnNameGetter
];
129 status
= 'In SECTION3 of test; looking up non-existent getter/setter';
130 actual
= [obj
.__lookupSetter__(cnColor
), obj
.__lookupGetter__(cnColor
)];
131 expect
= [undefined, undefined];
134 status
= 'In SECTION3 of test; looking up getter/setter on nonexistent property';
135 actual
= [obj
.__lookupSetter__(cnNonExistingProp
), obj
.__lookupGetter__(cnNonExistingProp
)];
136 expect
= [undefined, undefined];
141 //---------------------------------------------------------------------------------
143 //---------------------------------------------------------------------------------
148 statusitems
[UBound
] = status
;
149 actualvalues
[UBound
] = actual
.toString();
150 expectedvalues
[UBound
] = expect
.toString();
158 printBugNumber (bug
);
159 printStatus (summary
);
161 for (var i
= 0; i
< UBound
; i
++)
163 reportCompare(expectedvalues
[i
], actualvalues
[i
], getStatus(i
));
170 function getStatus(i
)
172 return statprefix
+ statusitems
[i
];