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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 | |
29 | |
30 function props(x) { | 28 function props(x) { |
31 var array = []; | 29 var array = []; |
32 for (var p in x) array.push(p); | 30 for (var p in x) array.push(p); |
33 return array; | 31 return array; |
34 } | 32 } |
35 | 33 |
36 (function forInBasic() { | 34 (function forInBasic() { |
37 assertEquals(0, props({}).length, "olen0"); | 35 assertEquals(0, props({}).length, "olen0"); |
38 assertEquals(1, props({x:1}).length, "olen1"); | 36 assertEquals(1, props({x:1}).length, "olen1"); |
39 assertEquals(2, props({x:1, y:2}).length, "olen2"); | 37 assertEquals(2, props({x:1, y:2}).length, "olen2"); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 assertEquals(1, props(a).length, "proplen1"); | 132 assertEquals(1, props(a).length, "proplen1"); |
135 a[Math.pow(2,31)-1] = 0; | 133 a[Math.pow(2,31)-1] = 0; |
136 assertEquals(2, props(a).length, "proplen2"); | 134 assertEquals(2, props(a).length, "proplen2"); |
137 a[1] = 0; | 135 a[1] = 0; |
138 assertEquals(3, props(a).length, "proplen3"); | 136 assertEquals(3, props(a).length, "proplen3"); |
139 })(); | 137 })(); |
140 | 138 |
141 (function forInInitialize() { | 139 (function forInInitialize() { |
142 for (var hest = 'hest' in {}) { } | 140 for (var hest = 'hest' in {}) { } |
143 assertEquals('hest', hest, "empty-no-override"); | 141 assertEquals('hest', hest, "empty-no-override"); |
| 142 |
| 143 // Lexical variables are disallowed |
| 144 assertThrows("for (const x = 0 in {});", SyntaxError); |
| 145 assertThrows("for (let x = 0 in {});", SyntaxError); |
| 146 |
| 147 // In strict mode, var is disallowed |
| 148 assertThrows("'use strict'; for (var x = 0 in {});", SyntaxError); |
144 })(); | 149 })(); |
145 | 150 |
146 (function forInObjects() { | 151 (function forInObjects() { |
147 var result = ''; | 152 var result = ''; |
148 for (var p in {a : [0], b : 1}) { result += p; } | 153 for (var p in {a : [0], b : 1}) { result += p; } |
149 assertEquals('ab', result, "ab"); | 154 assertEquals('ab', result, "ab"); |
150 | 155 |
151 var result = ''; | 156 var result = ''; |
152 for (var p in {a : {v:1}, b : 1}) { result += p; } | 157 for (var p in {a : {v:1}, b : 1}) { result += p; } |
153 assertEquals('ab', result, "ab-nodeep"); | 158 assertEquals('ab', result, "ab-nodeep"); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 assertUnreachable(); | 236 assertUnreachable(); |
232 } | 237 } |
233 })(); | 238 })(); |
234 | 239 |
235 (function testNonEnumerableSloppyArgumentsIndex(a) { | 240 (function testNonEnumerableSloppyArgumentsIndex(a) { |
236 Object.defineProperty(arguments, 0, {enumerable:false}); | 241 Object.defineProperty(arguments, 0, {enumerable:false}); |
237 for (var k in arguments) { | 242 for (var k in arguments) { |
238 assertUnreachable(); | 243 assertUnreachable(); |
239 } | 244 } |
240 })(true); | 245 })(true); |
OLD | NEW |