OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
6 #include "src/compilation-info.h" | 6 #include "src/compilation-info.h" |
7 #include "src/compiler/ast-loop-assignment-analyzer.h" | 7 #include "src/compiler/ast-loop-assignment-analyzer.h" |
8 #include "src/parsing/parse-info.h" | 8 #include "src/parsing/parse-info.h" |
9 #include "src/parsing/parsing.h" | 9 #include "src/parsing/parsing.h" |
10 #include "src/parsing/rewriter.h" | 10 #include "src/parsing/rewriter.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 }; | 64 }; |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 | 67 |
68 TEST(SimpleLoop1) { | 68 TEST(SimpleLoop1) { |
69 TestHelper f("var x = 0; while (x) ;"); | 69 TestHelper f("var x = 0; while (x) ;"); |
70 | 70 |
71 f.CheckLoopAssignedCount(0, "x"); | 71 f.CheckLoopAssignedCount(0, "x"); |
72 } | 72 } |
73 | 73 |
74 | 74 TEST(ForIn1) { |
75 TEST(SimpleLoop2) { | 75 const char* loops[] = {"for(x in 0) { }"}; |
76 const char* loops[] = { | |
77 "while (x) { var x = 0; }", "for(;;) { var x = 0; }", | |
78 "for(;x;) { var x = 0; }", "for(;x;x) { var x = 0; }", | |
79 "for(var i = x; x; x) { var x = 0; }", "for(y in 0) { var x = 0; }", | |
80 "for(y of 0) { var x = 0; }", "for(var x = 0; x; x++) { }", | |
81 "for(var x = 0; x++;) { }", "var x; for(;x;x++) { }", | |
82 "var x; do { x = 1; } while (0);", "do { var x = 1; } while (0);"}; | |
83 | 76 |
84 for (size_t i = 0; i < arraysize(loops); i++) { | 77 for (size_t i = 0; i < arraysize(loops); i++) { |
85 TestHelper f(loops[i]); | 78 TestHelper f(loops[i]); |
86 f.CheckLoopAssignedCount(1, "x"); | |
87 } | |
88 } | |
89 | |
90 | |
91 TEST(ForInOf1) { | |
92 const char* loops[] = { | |
93 "for(x in 0) { }", "for(x of 0) { }", | |
94 }; | |
95 | |
96 for (size_t i = 0; i < arraysize(loops); i++) { | |
97 TestHelper f(loops[i]); | |
98 f.CheckLoopAssignedCount(0, "x"); | 79 f.CheckLoopAssignedCount(0, "x"); |
99 } | 80 } |
100 } | 81 } |
101 | 82 |
102 | 83 |
103 TEST(Param1) { | 84 TEST(Param1) { |
104 TestHelper f("while (1) a = 0;"); | 85 TestHelper f("while (1) a = 0;"); |
105 | 86 |
106 f.CheckLoopAssignedCount(1, "a"); | 87 f.CheckLoopAssignedCount(1, "a"); |
107 f.CheckLoopAssignedCount(0, "b"); | 88 f.CheckLoopAssignedCount(0, "b"); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 274 |
294 f.CheckLoopAssignedCount(1, "x"); | 275 f.CheckLoopAssignedCount(1, "x"); |
295 f.CheckLoopAssignedCount(3, "y"); | 276 f.CheckLoopAssignedCount(3, "y"); |
296 f.CheckLoopAssignedCount(5, "z"); | 277 f.CheckLoopAssignedCount(5, "z"); |
297 f.CheckLoopAssignedCount(0, "w"); | 278 f.CheckLoopAssignedCount(0, "w"); |
298 } | 279 } |
299 | 280 |
300 } // namespace compiler | 281 } // namespace compiler |
301 } // namespace internal | 282 } // namespace internal |
302 } // namespace v8 | 283 } // namespace v8 |
OLD | NEW |