]>
Commit | Line | Data |
---|---|---|
1 | function Cons1() { | |
2 | } | |
3 | Cons1.prototype.f = 42; | |
4 | ||
5 | function Cons2() { | |
6 | this._values = [] | |
7 | } | |
8 | Cons2.prototype.__defineSetter__("f", function(value) { | |
9 | counter++; | |
10 | this._f = value; | |
11 | this._values[value] = 1; | |
12 | }); | |
13 | Cons2.prototype.__defineGetter__("f", function() { return this._f; }); | |
14 | ||
15 | function Cons3() { | |
16 | } | |
17 | Cons3.prototype.f = 42; | |
18 | Cons3.prototype.g = 43; | |
19 | ||
20 | function Cons4() { | |
21 | this._values = [] | |
22 | } | |
23 | Cons4.prototype.g = 16; | |
24 | Cons4.prototype.__defineSetter__("f", function(value) { | |
25 | counter++; | |
26 | this._f = value; | |
27 | this._values[value] = 1; | |
28 | }); | |
29 | Cons4.prototype.__defineGetter__("f", function() { return this._f; }); | |
30 | ||
31 | function foo(o, value) { | |
32 | o.f = value; | |
33 | return o.f; | |
34 | } | |
35 | ||
36 | noInline(foo); | |
37 | ||
38 | var counter = 0; | |
39 | ||
40 | function 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 | ||
48 | function 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 | ||
72 | for (var i = 0; i < 2; ++i) { | |
73 | runTestWithConstructors(Cons1, Cons2); | |
74 | runTestWithConstructors(Cons3, Cons2); | |
75 | runTestWithConstructors(Cons1, Cons4); | |
76 | runTestWithConstructors(Cons3, Cons4); | |
77 | } |