Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / pic / cached-getter-setter.html
blob6adc5720a87cc99dbfa965c39937b94580581155
1 <p>
2 This page tests cached access to getters and setters. If the test passes,
3 you'll see a series of PASS messages below.
4 </p>
6 <pre id="console"></pre>
8 <script>
9 (function() {
10 if (window.testRunner)
11 testRunner.dumpAsText();
13 function log(s)
15 if (this.document)
16 document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
17 else
18 print(s + "\n");
21 function shouldBe(a, aDescription, b)
23 if (a === b) {
24 log("PASS: " + aDescription + " should be " + b + " and is.");
25 } else {
26 log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
30 (function() {
31 var o = {
32 x_ : 0,
33 y_ : 0,
35 get x() { return this.x_; },
36 set x(x) { this.x_ = x; },
38 __proto__ : {
39 get y() { return this.y_; },
40 set y(y) { this.y_ = y; }
44 for (var i = 0; i < 3; ++i) {
45 o.x = i;
46 shouldBe(o.x, "o.x", i);
49 for (var i = 0; i < 3; ++i) {
50 o.y = i;
51 shouldBe(o.y, "o.y", i);
53 })();
55 function testGetter(o) {
56 var result;
57 for (var i = 0; i < 10; i++)
58 result = o.getter;
59 return result;
61 function testProtoGetter(o) {
62 var result;
63 for (var i = 0; i < 10; i++)
64 result = o.getter;
65 return result;
67 function testProtoChainGetter(o) {
68 var result;
69 for (var i = 0; i < 10; i++)
70 result = o.getter;
71 return result;
73 shouldBe(testGetter({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0}),
74 "testGetter({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0})", 10);
75 shouldBe(testGetter({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, newProperty: 0}),
76 "testGetter({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, newProperty: 0})", 10);
77 shouldBe(testGetter({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, newProperty2: 0}),
78 "testGetter({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, newProperty2: 0})", 10);
79 shouldBe(testProtoGetter({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}, count: 0}),
80 "testProtoGetter({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}, count: 0})", 10);
81 shouldBe(testProtoGetter({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}, count: 0, newProperty: 0}),
82 "testProtoGetter({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}, count: 0, newProperty: 0})", 10);
83 shouldBe(testProtoGetter({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}, count: 0, newProperty2: 0}),
84 "testProtoGetter({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}, count: 0, newProperty2: 0})", 10);
85 shouldBe(testProtoChainGetter({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}}, count: 0}),
86 "testProtoChainGetter({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}}, count: 0})", 10);
87 shouldBe(testProtoChainGetter({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}}, count: 0, newProperty: 0}),
88 "testProtoChainGetter({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}}, count: 0, newProperty: 0})", 10);
89 shouldBe(testProtoChainGetter({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}}, count: 0, newProperty2: 0}),
90 "testProtoChainGetter({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }}}, count: 0, newProperty2: 0})", 10);
92 function testGetterBigObject(o) {
93 var result;
94 for (var i = 0; i < 10; i++)
95 result = o.getter;
96 return result;
98 function testProtoGetterBigObject(o) {
99 var result;
100 for (var i = 0; i < 10; i++)
101 result = o.getter;
102 return result;
104 function testProtoChainGetterBigObject(o) {
105 var result;
106 for (var i = 0; i < 10; i++)
107 result = o.getter;
108 return result;
110 shouldBe(testGetterBigObject({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}),
111 "testGetterBigObject({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9})", 10);
112 shouldBe(testGetterBigObject({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, newProperty: 0, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}),
113 "testGetterBigObject({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, newProperty: 0, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9})", 10);
114 shouldBe(testGetterBigObject({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, newProperty2: 0, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}),
115 "testGetterBigObject({__proto__: {count: 'FAIL'}, get getter(){ return ++this.count; }, count: 0, newProperty2: 0, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9})", 10);
116 shouldBe(testProtoGetterBigObject({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}, count: 0}),
117 "testProtoGetterBigObject({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}, count: 0})", 10);
118 shouldBe(testProtoGetterBigObject({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}, count: 0, newProperty: 0}),
119 "testProtoGetterBigObject({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}, count: 0, newProperty: 0})", 10);
120 shouldBe(testProtoGetterBigObject({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}, count: 0, newProperty2: 0}),
121 "testProtoGetterBigObject({__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}, count: 0, newProperty2: 0})", 10);
122 shouldBe(testProtoChainGetterBigObject({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}}, count: 0}),
123 "testProtoChainGetterBigObject({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}}, count: 0})", 10);
124 shouldBe(testProtoChainGetterBigObject({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}}, count: 0, newProperty: 0}),
125 "testProtoChainGetterBigObject({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}}, count: 0, newProperty: 0})", 10);
126 shouldBe(testProtoChainGetterBigObject({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}}, count: 0, newProperty2: 0}),
127 "testProtoChainGetterBigObject({__proto__: {__proto__: {count: 'FAIL', get getter(){ return ++this.count; }, a:1, b:2, c:3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}}, count: 0, newProperty2: 0})", 10);
129 (function() {
130 var o = {
131 x : 1,
132 y : 1
135 function getX(o)
137 return o.x;
140 function setX(o, x)
142 o.x = x;
145 getX(o);
146 getX(o);
148 setX(o, 2);
149 setX(o, 2);
151 o.__defineGetter__("x", function() { return 3; });
152 o.__defineSetter__("x", function(x) { });
154 shouldBe(getX(o), "getX(o)", 3);
155 setX(o, 2);
156 shouldBe(getX(o), "getX(o)", 3);
157 })();
158 })();
159 </script>