]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/poly-setter-combo.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / poly-setter-combo.js
CommitLineData
ed1e77d3
A
1function Cons1() {
2}
3Cons1.prototype.f = 42;
4
5function Cons2() {
6 this._values = []
7}
8Cons2.prototype.__defineSetter__("f", function(value) {
9 counter++;
10 this._f = value;
11 this._values[value] = 1;
12});
13Cons2.prototype.__defineGetter__("f", function() { return this._f; });
14
15function Cons3() {
16}
17Cons3.prototype.f = 42;
18Cons3.prototype.g = 43;
19
20function Cons4() {
21 this._values = []
22}
23Cons4.prototype.g = 16;
24Cons4.prototype.__defineSetter__("f", function(value) {
25 counter++;
26 this._f = value;
27 this._values[value] = 1;
28});
29Cons4.prototype.__defineGetter__("f", function() { return this._f; });
30
31function foo(o, value) {
32 o.f = value;
33 return o.f;
34}
35
36noInline(foo);
37
38var counter = 0;
39
40function test(o, value, expectedCount) {
41 var result = foo(o, value);
42 if (result != value)
43 throw new Error("Bad result: " + result);
44 if (counter != expectedCount)
45 throw new Error("Bad counter value: " + counter);
46}
47
48function runTestWithConstructors(constructor1, constructor2) {
49 for (var i = 0; i < 5000; ++i) {
50 test(new constructor1(), i, counter);
51 test(new constructor2(), i, counter + 1);
52
53 var o = {};
54 o.__defineGetter__("f", function() {
55 counter++;
56 return 84;
57 });
58 test(o, 84, counter + 1);
59
60 var o = {};
61 o.__defineSetter__("f", function(value) {
62 this._f = value;
63 counter++;
64 });
65 o.__defineGetter__("f", function() { return this._f; });
66 test(o, i, counter + 1);
67
68 test({f: 42}, i, counter);
69 }
70}
71
72for (var i = 0; i < 2; ++i) {
73 runTestWithConstructors(Cons1, Cons2);
74 runTestWithConstructors(Cons3, Cons2);
75 runTestWithConstructors(Cons1, Cons4);
76 runTestWithConstructors(Cons3, Cons4);
77}