OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 // Test for conflicting variable bindings. | 5 // Test for conflicting variable bindings. |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 function CheckException(e) { | 9 function CheckException(e) { |
10 var string = e.toString(); | 10 var string = e.toString(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 "let x = 0;", | 72 "let x = 0;", |
73 "let x = undefined;", | 73 "let x = undefined;", |
74 "let x = function() {};", | 74 "let x = function() {};", |
75 "let x, y;", | 75 "let x, y;", |
76 "let y, x;", | 76 "let y, x;", |
77 "const x = 0;", | 77 "const x = 0;", |
78 "const x = undefined;", | 78 "const x = undefined;", |
79 "const x = function() {};", | 79 "const x = function() {};", |
80 "const x = 2, y = 3;", | 80 "const x = 2, y = 3;", |
81 "const y = 4, x = 5;", | 81 "const y = 4, x = 5;", |
| 82 "class x { }", |
82 ]; | 83 ]; |
| 84 function forCompatible(bind) { |
| 85 return !bind.startsWith('class'); |
| 86 } |
83 var varbinds = [ "var x;", | 87 var varbinds = [ "var x;", |
84 "var x = 0;", | 88 "var x = 0;", |
85 "var x = undefined;", | 89 "var x = undefined;", |
86 "var x = function() {};", | 90 "var x = function() {};", |
87 "var x, y;", | 91 "var x, y;", |
88 "var y, x;", | 92 "var y, x;", |
89 ]; | 93 ]; |
90 var funbind = "function x() {}"; | 94 var funbind = "function x() {}"; |
91 | 95 |
92 for (var l = 0; l < letbinds.length; ++l) { | 96 for (var l = 0; l < letbinds.length; ++l) { |
93 // Test conflicting let/var bindings. | 97 // Test conflicting let/var bindings. |
94 for (var v = 0; v < varbinds.length; ++v) { | 98 for (var v = 0; v < varbinds.length; ++v) { |
95 // Same level. | 99 // Same level. |
96 TestConflict(letbinds[l] + varbinds[v]); | 100 TestConflict(letbinds[l] + varbinds[v]); |
97 TestConflict(varbinds[v] + letbinds[l]); | 101 TestConflict(varbinds[v] + letbinds[l]); |
98 // Different level. | 102 // Different level. |
99 TestConflict(letbinds[l] + '{' + varbinds[v] + '}'); | 103 TestConflict(letbinds[l] + '{' + varbinds[v] + '}'); |
100 TestConflict('{' + varbinds[v] +'}' + letbinds[l]); | 104 TestConflict('{' + varbinds[v] +'}' + letbinds[l]); |
101 TestNoConflict(varbinds[v] + '{' + letbinds[l] + '}'); | 105 TestNoConflict(varbinds[v] + '{' + letbinds[l] + '}'); |
102 TestNoConflict('{' + letbinds[l] + '}' + varbinds[v]); | 106 TestNoConflict('{' + letbinds[l] + '}' + varbinds[v]); |
103 // For loop. | 107 // For loop. |
104 TestConflict('for (' + letbinds[l] + '0;) {' + varbinds[v] + '}'); | 108 if (forCompatible(letbinds[l])) { |
| 109 TestConflict('for (' + letbinds[l] + '0;) {' + varbinds[v] + '}'); |
| 110 } |
105 TestNoConflict('for (' + varbinds[v] + '0;) {' + letbinds[l] + '}'); | 111 TestNoConflict('for (' + varbinds[v] + '0;) {' + letbinds[l] + '}'); |
106 } | 112 } |
107 | 113 |
108 // Test conflicting let/let bindings. | 114 // Test conflicting let/let bindings. |
109 for (var k = 0; k < letbinds.length; ++k) { | 115 for (var k = 0; k < letbinds.length; ++k) { |
110 // Same level. | 116 // Same level. |
111 TestConflict(letbinds[l] + letbinds[k]); | 117 TestConflict(letbinds[l] + letbinds[k]); |
112 TestConflict(letbinds[k] + letbinds[l]); | 118 TestConflict(letbinds[k] + letbinds[l]); |
113 // Different level. | 119 // Different level. |
114 TestNoConflict(letbinds[l] + '{ ' + letbinds[k] + '}'); | 120 TestNoConflict(letbinds[l] + '{ ' + letbinds[k] + '}'); |
115 TestNoConflict('{' + letbinds[k] +'} ' + letbinds[l]); | 121 TestNoConflict('{' + letbinds[k] +'} ' + letbinds[l]); |
116 // For loop. | 122 // For loop. |
117 TestNoConflict('for (' + letbinds[l] + '0;) {' + letbinds[k] + '}'); | 123 if (forCompatible(letbinds[l])) { |
118 TestNoConflict('for (' + letbinds[k] + '0;) {' + letbinds[l] + '}'); | 124 TestNoConflict('for (' + letbinds[l] + '0;) {' + letbinds[k] + '}'); |
| 125 } |
| 126 if (forCompatible(letbinds[k])) { |
| 127 TestNoConflict('for (' + letbinds[k] + '0;) {' + letbinds[l] + '}'); |
| 128 } |
119 } | 129 } |
120 | 130 |
121 // Test conflicting function/let bindings. | 131 // Test conflicting function/let bindings. |
122 // Same level. | 132 // Same level. |
123 TestConflict(letbinds[l] + funbind); | 133 TestConflict(letbinds[l] + funbind); |
124 TestConflict(funbind + letbinds[l]); | 134 TestConflict(funbind + letbinds[l]); |
125 // Different level. | 135 // Different level. |
126 TestNoConflict(letbinds[l] + '{' + funbind + '}'); | 136 TestNoConflict(letbinds[l] + '{' + funbind + '}'); |
127 TestNoConflict('{' + funbind + '}' + letbinds[l]); | 137 TestNoConflict('{' + funbind + '}' + letbinds[l]); |
128 TestNoConflict(funbind + '{' + letbinds[l] + '}'); | 138 TestNoConflict(funbind + '{' + letbinds[l] + '}'); |
129 TestNoConflict('{' + letbinds[l] + '}' + funbind); | 139 TestNoConflict('{' + letbinds[l] + '}' + funbind); |
130 // For loop. | 140 // For loop. |
131 TestNoConflict('for (' + letbinds[l] + '0;) {' + funbind + '}'); | 141 if (forCompatible(letbinds[l])) { |
| 142 TestNoConflict('for (' + letbinds[l] + '0;) {' + funbind + '}'); |
| 143 } |
132 | 144 |
133 // Test conflicting parameter/let bindings. | 145 // Test conflicting parameter/let bindings. |
134 TestConflict('(function(x) {' + letbinds[l] + '})();'); | 146 TestConflict('(function(x) {' + letbinds[l] + '})();'); |
135 } | 147 } |
136 | 148 |
137 // Test conflicting function/var bindings. | 149 // Test conflicting function/var bindings. |
138 for (var v = 0; v < varbinds.length; ++v) { | 150 for (var v = 0; v < varbinds.length; ++v) { |
139 // Same level. | 151 // Same level. |
140 TestLocalConflict(varbinds[v] + funbind); | 152 TestLocalConflict(varbinds[v] + funbind); |
141 TestLocalConflict(funbind + varbinds[v]); | 153 TestLocalConflict(funbind + varbinds[v]); |
(...skipping 14 matching lines...) Expand all Loading... |
156 // Test conflicting parameter/var bindings. | 168 // Test conflicting parameter/var bindings. |
157 for (var v = 0; v < varbinds.length; ++v) { | 169 for (var v = 0; v < varbinds.length; ++v) { |
158 TestNoConflict('(function (x) {' + varbinds[v] + '})();'); | 170 TestNoConflict('(function (x) {' + varbinds[v] + '})();'); |
159 } | 171 } |
160 | 172 |
161 // Test conflicting catch/function bindings. | 173 // Test conflicting catch/function bindings. |
162 TestNoConflict('try {} catch(x) {' + funbind + '}'); | 174 TestNoConflict('try {} catch(x) {' + funbind + '}'); |
163 | 175 |
164 // Test conflicting parameter/function bindings. | 176 // Test conflicting parameter/function bindings. |
165 TestNoConflict('(function (x) {' + funbind + '})();'); | 177 TestNoConflict('(function (x) {' + funbind + '})();'); |
OLD | NEW |