Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/getset-006.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: 14 April 2001
8 *
9 * SUMMARY: Testing obj.__lookupGetter__(), obj.__lookupSetter__()
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=71992
11 *
12 * Brendan: "I see no need to provide more than the minimum:
13 * o.__lookupGetter__('p') returns the getter function for o.p,
14 * or undefined if o.p has no getter. Users can wrap and layer."
15 */
16 //-----------------------------------------------------------------------------
17 var gTestfile = 'getset-006.js';
18 var UBound = 0;
19 var BUGNUMBER = 71992;
20 var summary = 'Testing obj.__lookupGetter__(), obj.__lookupSetter__()';
21 var statprefix = 'Status: ';
22 var status = '';
23 var statusitems = [ ];
24 var actual = '';
25 var actualvalues = [ ];
26 var expect= '';
27 var expectedvalues = [ ];
28 var cnName = 'name';
29 var cnColor = 'color';
30 var cnNonExistingProp = 'ASDF_#_$%';
31 var cnDEFAULT = 'default name';
32 var cnFRED = 'Fred';
33 var cnRED = 'red';
34 var obj = {};
35 var obj2 = {};
36 var s;
37
38
39 // The only setter and getter functions we'll use in the three sections below -
40 var cnNameSetter = function(newValue) {this._name=newValue; this.nameSETS++;};
41 var cnNameGetter = function() {this.nameGETS++; return this._name;};
42
43
44
45 // SECTION1: define getter/setter directly on an object (not its prototype)
46 obj = new Object();
47 obj.nameSETS = 0;
48 obj.nameGETS = 0;
49 obj.__defineSetter__(cnName, cnNameSetter);
50 obj.__defineGetter__(cnName, cnNameGetter);
51 obj.name = cnFRED;
52 obj.color = cnRED;
53
54 status ='In SECTION1 of test; looking up extant getter/setter';
55 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
56 expect = [cnNameSetter, cnNameGetter];
57 addThis();
58
59 status = 'In SECTION1 of test; looking up nonexistent getter/setter';
60 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
61 expect = [undefined, undefined];
62 addThis();
63
64 status = 'In SECTION1 of test; looking up getter/setter on nonexistent property';
65 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
66 expect = [undefined, undefined];
67 addThis();
68
69
70
71 // SECTION2: define getter/setter in Object.prototype
72 Object.prototype.nameSETS = 0;
73 Object.prototype.nameGETS = 0;
74 Object.prototype.__defineSetter__(cnName, cnNameSetter);
75 Object.prototype.__defineGetter__(cnName, cnNameGetter);
76
77 obj = new Object();
78 obj.name = cnFRED;
79 obj.color = cnRED;
80
81 status = 'In SECTION2 of test looking up extant getter/setter';
82 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
83 expect = [cnNameSetter, cnNameGetter];
84 addThis();
85
86 status = 'In SECTION2 of test; looking up nonexistent getter/setter';
87 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
88 expect = [undefined, undefined];
89 addThis();
90
91 status = 'In SECTION2 of test; looking up getter/setter on nonexistent property';
92 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
93 expect = [undefined, undefined];
94 addThis();
95
96
97
98 // SECTION 3: define getter/setter in prototype of user-defined constructor
99 function TestObject()
100 {
101 }
102 TestObject.prototype.nameSETS = 0;
103 TestObject.prototype.nameGETS = 0;
104 TestObject.prototype.__defineSetter__(cnName, cnNameSetter);
105 TestObject.prototype.__defineGetter__(cnName, cnNameGetter);
106 TestObject.prototype.name = cnDEFAULT;
107
108 obj = new TestObject();
109 obj.name = cnFRED;
110 obj.color = cnRED;
111
112 status = 'In SECTION3 of test looking up extant getter/setter';
113 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
114 expect = [cnNameSetter, cnNameGetter];
115 addThis();
116
117 status = 'In SECTION3 of test; looking up non-existent getter/setter';
118 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
119 expect = [undefined, undefined];
120 addThis();
121
122 status = 'In SECTION3 of test; looking up getter/setter on nonexistent property';
123 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
124 expect = [undefined, undefined];
125 addThis();
126
127
128
129 //---------------------------------------------------------------------------------
130 test();
131 //---------------------------------------------------------------------------------
132
133
134 function addThis()
135 {
136 statusitems[UBound] = status;
137 actualvalues[UBound] = actual.toString();
138 expectedvalues[UBound] = expect.toString();
139 UBound++;
140 }
141
142
143 function test()
144 {
145 enterFunc ('test');
146 printBugNumber(BUGNUMBER);
147 printStatus (summary);
148
149 for (var i = 0; i < UBound; i++)
150 {
151 reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
152 }
153
154 exitFunc ('test');
155 }
156
157
158 function getStatus(i)
159 {
160 return statprefix + statusitems[i];
161 }