OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --noharmony-for-in | 28 // Flags: --noharmony-for-in |
29 | 29 |
30 function props(x) { | 30 function props(x) { |
31 var array = []; | 31 var array = []; |
32 for (var p in x) array.push(p); | 32 for (var p in x) array.push(p); |
33 return array.sort(); | 33 return array; |
34 } | 34 } |
35 | 35 |
36 assertEquals(0, props({}).length, "olen0"); | 36 (function forInBasic() { |
37 assertEquals(1, props({x:1}).length, "olen1"); | 37 assertEquals(0, props({}).length, "olen0"); |
38 assertEquals(2, props({x:1, y:2}).length, "olen2"); | 38 assertEquals(1, props({x:1}).length, "olen1"); |
| 39 assertEquals(2, props({x:1, y:2}).length, "olen2"); |
39 | 40 |
40 assertArrayEquals(["x"], props({x:1}), "x"); | 41 assertArrayEquals(["x"], props({x:1}), "x"); |
41 assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy"); | 42 assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy"); |
42 assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom"); | 43 assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom"); |
43 | 44 |
44 assertEquals(0, props([]).length, "alen0"); | 45 assertEquals(0, props([]).length, "alen0"); |
45 assertEquals(1, props([1]).length, "alen1"); | 46 assertEquals(1, props([1]).length, "alen1"); |
46 assertEquals(2, props([1,2]).length, "alen2"); | 47 assertEquals(2, props([1,2]).length, "alen2"); |
47 | 48 |
48 assertArrayEquals(["0"], props([1]), "0"); | 49 assertArrayEquals(["0"], props([1]), "0"); |
49 assertArrayEquals(["0", "1"], props([1,2]), "01"); | 50 assertArrayEquals(["0", "1"], props([1,2]), "01"); |
50 assertArrayEquals(["0", "1", "2"], props([1,2,3]), "012"); | 51 assertArrayEquals(["0", "1", "2"], props([1,2,3]), "012"); |
| 52 })(); |
51 | 53 |
52 var o = {}; | 54 (function forInPrototype() { |
53 var a = []; | 55 // Fast properties + fast elements |
54 for (var i = 0x0020; i < 0x01ff; i+=2) { | 56 var obj = {a:true, 3:true, 4:true}; |
55 var s = 'char:' + String.fromCharCode(i); | 57 obj.__proto__ = {c:true, b:true, 2:true, 1:true, 5:true}; |
56 a.push(s); | 58 for (var i = 0; i < 3; i++) { |
57 o[s] = i; | 59 assertArrayEquals("34a125cb".split(""), props(obj)); |
58 } | 60 } |
59 assertArrayEquals(a, props(o), "charcodes"); | 61 // Fast properties + dictionary elements |
| 62 delete obj.__proto__[2]; |
| 63 for (var i = 0; i < 3; i++) { |
| 64 assertArrayEquals("34a15cb".split(""), props(obj)); |
| 65 } |
| 66 // Slow properties + dictionary elements |
| 67 delete obj.__proto__.c; |
| 68 for (var i = 0; i < 3; i++) { |
| 69 assertArrayEquals("34a15b".split(""), props(obj)); |
| 70 } |
| 71 // Slow properties on the receiver as well |
| 72 delete obj.a; |
| 73 for (var i = 0; i < 3; i++) { |
| 74 assertArrayEquals("3415b".split(""), props(obj)); |
| 75 } |
| 76 delete obj[3]; |
| 77 for (var i = 0; i < 3; i++) { |
| 78 assertArrayEquals("415b".split(""), props(obj)); |
| 79 } |
| 80 })(); |
60 | 81 |
61 var a = []; | 82 (function forInShadowing() { |
62 assertEquals(0, props(a).length, "proplen0"); | 83 var obj = {a:true, 3:true, 4:true}; |
63 a[Math.pow(2,30)-1] = 0; | 84 obj.__proto__ = { |
64 assertEquals(1, props(a).length, "proplen1"); | 85 c:true, b:true, x:true, |
65 a[Math.pow(2,31)-1] = 0; | 86 2:true, 1:true, 5:true, 9:true}; |
66 assertEquals(2, props(a).length, "proplen2"); | 87 Object.defineProperty(obj, 'x', {value:true, enumerable:false, configurable:tr
ue}); |
67 a[1] = 0; | 88 Object.defineProperty(obj, '9', {value:true, enumerable:false, configurable:tr
ue}); |
68 assertEquals(3, props(a).length, "proplen3"); | 89 for (var i = 0; i < 3; i++) { |
| 90 assertArrayEquals("34a125cb".split(""), props(obj)); |
| 91 } |
| 92 // Fast properties + dictionary elements |
| 93 delete obj.__proto__[2]; |
| 94 for (var i = 0; i < 3; i++) { |
| 95 assertArrayEquals("34a15cb".split(""), props(obj)); |
| 96 } |
| 97 // Slow properties + dictionary elements |
| 98 delete obj.__proto__.c; |
| 99 for (var i = 0; i < 3; i++) { |
| 100 assertArrayEquals("34a15b".split(""), props(obj)); |
| 101 } |
| 102 // Remove the shadowing properties |
| 103 delete obj.x; |
| 104 delete obj[9]; |
| 105 for (var i = 0; i < 3; i++) { |
| 106 assertArrayEquals("34a159bx".split(""), props(obj)); |
| 107 } |
| 108 // Slow properties on the receiver as well |
| 109 delete obj.a; |
| 110 for (var i = 0; i < 3; i++) { |
| 111 assertArrayEquals("34159bx".split(""), props(obj)); |
| 112 } |
| 113 delete obj[3]; |
| 114 for (var i = 0; i < 3; i++) { |
| 115 assertArrayEquals("4159bx".split(""), props(obj)); |
| 116 } |
| 117 })(); |
69 | 118 |
70 for (var hest = 'hest' in {}) { } | 119 (function forInCharCodes() { |
71 assertEquals('hest', hest, "empty-no-override"); | 120 var o = {}; |
| 121 var a = []; |
| 122 for (var i = 0x0020; i < 0x01ff; i+=2) { |
| 123 var s = 'char:' + String.fromCharCode(i); |
| 124 a.push(s); |
| 125 o[s] = i; |
| 126 } |
| 127 assertArrayEquals(a, props(o), "charcodes"); |
| 128 })(); |
72 | 129 |
73 var result = ''; | 130 (function forInArray() { |
74 for (var p in {a : [0], b : 1}) { result += p; } | 131 var a = []; |
75 assertEquals('ab', result, "ab"); | 132 assertEquals(0, props(a).length, "proplen0"); |
| 133 a[Math.pow(2,30)-1] = 0; |
| 134 assertEquals(1, props(a).length, "proplen1"); |
| 135 a[Math.pow(2,31)-1] = 0; |
| 136 assertEquals(2, props(a).length, "proplen2"); |
| 137 a[1] = 0; |
| 138 assertEquals(3, props(a).length, "proplen3"); |
| 139 })(); |
76 | 140 |
77 var result = ''; | 141 (function forInInitialize() { |
78 for (var p in {a : {v:1}, b : 1}) { result += p; } | 142 for (var hest = 'hest' in {}) { } |
79 assertEquals('ab', result, "ab-nodeep"); | 143 assertEquals('hest', hest, "empty-no-override"); |
| 144 })(); |
80 | 145 |
81 var result = ''; | 146 (function forInObjects() { |
82 for (var p in { get a() {}, b : 1}) { result += p; } | 147 var result = ''; |
83 assertEquals('ab', result, "abget"); | 148 for (var p in {a : [0], b : 1}) { result += p; } |
| 149 assertEquals('ab', result, "ab"); |
84 | 150 |
85 var result = ''; | 151 var result = ''; |
86 for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; } | 152 for (var p in {a : {v:1}, b : 1}) { result += p; } |
87 assertEquals('ab', result, "abgetset"); | 153 assertEquals('ab', result, "ab-nodeep"); |
| 154 |
| 155 var result = ''; |
| 156 for (var p in { get a() {}, b : 1}) { result += p; } |
| 157 assertEquals('ab', result, "abget"); |
| 158 |
| 159 var result = ''; |
| 160 for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; } |
| 161 assertEquals('ab', result, "abgetset"); |
| 162 })(); |
88 | 163 |
89 | 164 |
90 // Test that for-in in the global scope works with a keyed property as "each". | 165 // Test that for-in in the global scope works with a keyed property as "each". |
91 // Test outside a loop and in a loop for multiple iterations. | 166 // Test outside a loop and in a loop for multiple iterations. |
92 a = [1,2,3,4]; | 167 a = [1,2,3,4]; |
93 x = {foo:5, bar:6, zip:7, glep:9, 10:11}; | 168 x = {foo:5, bar:6, zip:7, glep:9, 10:11}; |
94 delete x.bar; | 169 delete x.bar; |
95 y = {} | 170 y = {} |
96 | 171 |
97 for (a[2] in x) { | 172 for (a[2] in x) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 assertUnreachable(); | 231 assertUnreachable(); |
157 } | 232 } |
158 })(); | 233 })(); |
159 | 234 |
160 (function testNonEnumerableSloppyArgumentsIndex(a) { | 235 (function testNonEnumerableSloppyArgumentsIndex(a) { |
161 Object.defineProperty(arguments, 0, {enumerable:false}); | 236 Object.defineProperty(arguments, 0, {enumerable:false}); |
162 for (var k in arguments) { | 237 for (var k in arguments) { |
163 assertUnreachable(); | 238 assertUnreachable(); |
164 } | 239 } |
165 })(true); | 240 })(true); |
OLD | NEW |