]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/for-in-tests.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / for-in-tests.js
CommitLineData
ed1e77d3
A
1(function() {
2 // Iterate over an array with normal indexed properties.
3 var foo = function() {
4 var a = [1, 2, 3, 4, 5];
5 var sum = 0;
6 var result = "";
7 for (var p in a)
8 result += a[p];
9 return result;
10 };
11 noInline(foo);
12 for (var i = 0; i < 10000; ++i) {
13 if (foo() !== "12345")
14 throw new Error("bad result");
15 }
16 foo(null);
17})();
18(function() {
19 // Iterate over an object with normal non-indexed properties.
20 var foo = function() {
21 var o = {};
22 o.x = 1;
23 o.y = 2;
24 o.z = 3;
25 var result = "";
26 for (var p in o)
27 result += o[p];
28 return result;
29 };
30 noInline(foo);
31 for (var i = 0; i < 10000; ++i) {
32 if (foo() !== "123")
33 throw new Error("bad result");
34 }
35 foo(null);
36})();
37(function() {
38 // Iterate over an object with both indexed and non-indexed properties.
39 var foo = function() {
40 var o = {};
41 o.x = 1;
42 o.y = 2;
43 o.z = 3;
44 o[0] = 4;
45 o[1] = 5;
46 o[2] = 6;
47 var result = "";
48 for (var p in o)
49 result += o[p];
50 return result;
51 };
52 noInline(foo);
53 for (var i = 0; i < 10000; ++i) {
54 if (foo() != "456123")
55 throw new Error("bad result");
56 }
57 foo(null);
58})();
59(function() {
60 // Iterate over an array with both indexed and non-indexed properties.
61 var foo = function() {
62 var a = [4, 5, 6];
63 a.x = 1;
64 a.y = 2;
65 a.z = 3;
66 var result = "";
67 for (var p in a)
68 result += a[p];
69 return result;
70 };
71 noInline(foo);
72 for (var i = 0; i < 10000; ++i) {
73 if (foo() !== "456123")
74 throw new Error("bad result");
75 }
76 foo(null);
77})();
78(function() {
79 var foo = function(a, b) {
80 for (var p in b) {
81 var f1 = a[p];
82 var f2 = b[p];
83 if (f1 === f2)
84 continue;
85 a[p] = b[p];
86 }
87 };
88 noInline(foo);
89 for (var i = 0; i < 10000; ++i) {
90 var o1 = {};
91 var o2 = {};
92 o2.x = 42;
93 o2.y = 53;
94 foo(o1, o2);
95 if (o1.x !== o2.x)
96 throw new Error("bad result: " + o1.x + "!==" + o2.x);
97 if (o1.y !== o2.y)
98 throw new Error("bad result: " + o1.y + "!==" + o2.y);
99 }
100})();