Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / jit-test / tests / basic / testInitDictionary.js
1
2 var shapes = {};
3
4 function stringify(a) {
5   assertEq(shapes[shapeOf(a)], undefined);
6   shapes[shapeOf(a)] = 1;
7   var b = "";
8   for (var c in a) {
9     b += c + ":";
10     if (typeof a[c] == "function")
11       b += "function,";
12     else
13       b += a[c] + ",";
14   }
15   return b;
16 }
17
18 function test1() {
19   return stringify({a: 0, b: 1, a: function() {} });
20 }
21 for (var i = 0; i < 3; i++)
22   assertEq(test1(), "a:function,b:1,");
23
24 // This does not cause the object to go to dictionary mode, unlike the above.
25 function test2() {
26   return stringify({a: 0, b: 1, a: 2, b: 3});
27 }
28 assertEq(test2(), "a:2,b:3,");
29
30 function test3() {
31   return stringify({
32     aa:0,ab:1,ac:2,ad:3,ae:4,af:5,ag:6,ah:7,ai:8,aj:9,
33     ba:0,bb:1,bc:2,bd:3,be:4,bf:5,bg:6,bh:7,bi:8,bj:9,
34     ca:0,cb:1,cc:2,cd:3,ce:4,cf:5,cg:6,ch:7,ci:8,cj:9,
35     da:0,db:1,dc:2,dd:3,de:4,df:5,dg:6,dh:7,di:8,dj:9,
36     ea:0,eb:1,ec:2,ed:3,ee:4,ef:5,eg:6,eh:7,ei:8,ej:9,
37     fa:0,fb:1,fc:2,fd:3,fe:4,ff:5,fg:6,fh:7,fi:8,fj:9,
38     ga:0,gb:1,gc:2,gd:3,ge:4,gf:5,gg:6,gh:7,gi:8,gj:9,
39     ha:0,hb:1,hc:2,hd:3,he:4,hf:5,hg:6,hh:7,hi:8,hj:9,
40     ia:0,ib:1,ic:2,id:3,ie:4,if:5,ig:6,ih:7,ii:8,ij:9,
41     ja:0,jb:1,jc:2,jd:3,je:4,jf:5,jg:6,jh:7,ji:8,jj:9,
42     ka:0,kb:1,kc:2,kd:3,ke:4,kf:5,kg:6,kh:7,ki:8,kj:9,
43     la:0,lb:1,lc:2,ld:3,le:4,lf:5,lg:6,lh:7,li:8,lj:9,
44     ma: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