8fc2636defbbe1f1c847335c34ff20173d9b6698
[framework/web/webkit-efl.git] / LayoutTests / fast / js / script-tests / dictionary-prototype-caching.js
1 description("Test to ensure correct behaviour of prototype caching with dictionary prototypes");
2
3 function protoTest(o) {
4     return o.protoProp;
5 }
6
7 var proto = {protoProp: "PASS", propToRemove: "foo"};
8 var o = { __proto__: proto };
9
10 delete proto.propToRemove;
11
12 // Prototype lookup caching will attempt to convert proto back to an ordinary structure
13 protoTest(o);
14 protoTest(o);
15 protoTest(o);
16 shouldBe("protoTest(o)", "'PASS'");
17 delete proto.protoProp;
18 proto.fakeProtoProp = "FAIL";
19 shouldBeUndefined("protoTest(o)");
20
21 function protoTest2(o) {
22     return o.b;
23 }
24
25 var proto = {a:1, b:"meh", c:2};
26 var o = { __proto__: proto };
27
28 delete proto.b;
29 proto.d = 3;
30 protoTest2(o);
31 protoTest2(o);
32 protoTest2(o);
33 var protoKeys = [];
34 for (var i in proto)
35     protoKeys.push(proto[i]);
36
37 shouldBe("protoKeys", "[1,2,3]");
38
39 function protoTest3(o) {
40     return o.b;
41 }
42
43 var proto = {a:1, b:"meh", c:2};
44 var o = { __proto__: proto };
45
46 delete proto.b;
47 protoTest2(o);
48 protoTest2(o);
49 protoTest2(o);
50 proto.d = 3;
51 var protoKeys = [];
52 for (var i in proto)
53     protoKeys.push(proto[i]);
54
55 shouldBe("protoKeys", "[1,2,3]");
56
57 function testFunction(o) {
58     return o.test;
59 }
60
61 var proto = { test: true };
62 var subclass1 = { __proto__: proto };
63 var subclass2 = { __proto__: proto };
64 for (var i = 0; i < 500; i++)
65     subclass2["a"+i]="a"+i;
66
67 testFunction(subclass1);
68 shouldBeTrue("testFunction(subclass1)");
69 shouldBeTrue("testFunction(subclass2)");
70 proto.test = false
71 subclass2.test = true;
72 shouldBeTrue("testFunction(subclass2)");
73
74 successfullyParsed = true;