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 // Flags: --no-legacy-const --harmony-sloppy |
8 | 8 |
9 function CheckException(e) { | 9 function CheckException(e) { |
10 var string = e.toString(); | 10 var string = e.toString(); |
11 assertTrue(string.indexOf("has already been declared") >= 0 || | 11 assertTrue(string.indexOf("has already been declared") >= 0 || |
12 string.indexOf("redeclaration") >= 0); | 12 string.indexOf("redeclaration") >= 0); |
13 return 'Conflict'; | 13 return 'Conflict'; |
14 } | 14 } |
15 | 15 |
16 | 16 |
17 function TestGlobal(s,e) { | 17 function TestGlobal(s,e) { |
(...skipping 19 matching lines...) Expand all Loading... | |
37 return eval("(function(){ {" + s + "} return " + e + "})")(); | 37 return eval("(function(){ {" + s + "} return " + e + "})")(); |
38 } catch (x) { | 38 } catch (x) { |
39 return CheckException(x); | 39 return CheckException(x); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 function TestAll(expected,s,opt_e) { | 43 function TestAll(expected,s,opt_e) { |
44 var e = ""; | 44 var e = ""; |
45 var msg = s; | 45 var msg = s; |
46 if (opt_e) { e = opt_e; msg += opt_e; } | 46 if (opt_e) { e = opt_e; msg += opt_e; } |
47 assertEquals(expected === 'LocalConflict' ? 'NoConflict' : expected, | 47 // TODO(littledan): https://code.google.com/p/v8/issues/detail?id=4288 |
48 TestGlobal(s,e), "global:'" + msg + "'"); | 48 // It is also not clear whether these tests makes sense in sloppy mode. |
49 // assertEquals(expected === 'LocalConflict' ? 'NoConflict' : expected, | |
50 // TestGlobal(s,e), "global:'" + msg + "'"); | |
49 assertEquals(expected === 'LocalConflict' ? 'NoConflict' : expected, | 51 assertEquals(expected === 'LocalConflict' ? 'NoConflict' : expected, |
50 TestFunction(s,e), "function:'" + msg + "'"); | 52 TestFunction(s,e), "function:'" + msg + "'"); |
51 assertEquals(expected === 'LocalConflict' ? 'Conflict' : expected, | 53 assertEquals(expected === 'LocalConflict' ? 'Conflict' : expected, |
52 TestBlock(s,e), "block:'" + msg + "'"); | 54 TestBlock(s,e), "block:'" + msg + "'"); |
53 } | 55 } |
54 | 56 |
55 | 57 |
56 function TestConflict(s) { | 58 function TestConflict(s) { |
57 TestAll('Conflict', s); | 59 TestAll('Conflict', s); |
58 TestAll('Conflict', 'eval("' + s + '");'); | 60 // TODO(littledan): https://code.google.com/p/v8/issues/detail?id=4288 |
61 // It is also not clear whether these tests makes sense in sloppy mode. | |
62 // TestAll('Conflict', 'eval("' + s + '");'); | |
Dan Ehrenberg
2015/07/08 23:42:13
I don't see why these tests wouldn't make sense. W
arv (Not doing code reviews)
2015/07/09 14:30:53
See the bug.
eval('let x; var x;')
is more sim
rossberg
2015/07/10 12:13:17
I suppose
let x; eval('var x');
is an error in s
arv (Not doing code reviews)
2015/07/10 13:00:48
The other tests wrap the string in a function or a
| |
59 } | 63 } |
60 | 64 |
61 function TestNoConflict(s) { | 65 function TestNoConflict(s) { |
62 TestAll('NoConflict', s, "'NoConflict'"); | 66 TestAll('NoConflict', s, "'NoConflict'"); |
63 TestAll('NoConflict', 'eval("' + s + '");', "'NoConflict'"); | 67 // TODO(littledan): https://code.google.com/p/v8/issues/detail?id=4288 |
68 // TestAll('NoConflict', 'eval("' + s + '");', "'NoConflict'"); | |
64 } | 69 } |
65 | 70 |
66 function TestLocalConflict(s) { | 71 function TestLocalConflict(s) { |
67 TestAll('LocalConflict', s, "'NoConflict'"); | 72 TestAll('LocalConflict', s, "'NoConflict'"); |
68 TestAll('NoConflict', 'eval("' + s + '");', "'NoConflict'"); | 73 // TODO(littledan): https://code.google.com/p/v8/issues/detail?id=4288 |
74 // It is also not clear whether these tests makes sense in sloppy mode. | |
75 // TestAll('NoConflict', 'eval("' + s + '");', "'NoConflict'"); | |
69 } | 76 } |
70 | 77 |
71 var letbinds = [ "let x;", | 78 var letbinds = [ "let x;", |
72 "let x = 0;", | 79 "let x = 0;", |
73 "let x = undefined;", | 80 "let x = undefined;", |
74 "let x = function() {};", | 81 "let x = function() {};", |
75 "let x, y;", | 82 "let x, y;", |
76 "let y, x;", | 83 "let y, x;", |
77 "const x = 0;", | 84 "const x = 0;", |
78 "const x = undefined;", | 85 "const x = undefined;", |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 // Test conflicting parameter/var bindings. | 163 // Test conflicting parameter/var bindings. |
157 for (var v = 0; v < varbinds.length; ++v) { | 164 for (var v = 0; v < varbinds.length; ++v) { |
158 TestNoConflict('(function (x) {' + varbinds[v] + '})();'); | 165 TestNoConflict('(function (x) {' + varbinds[v] + '})();'); |
159 } | 166 } |
160 | 167 |
161 // Test conflicting catch/function bindings. | 168 // Test conflicting catch/function bindings. |
162 TestNoConflict('try {} catch(x) {' + funbind + '}'); | 169 TestNoConflict('try {} catch(x) {' + funbind + '}'); |
163 | 170 |
164 // Test conflicting parameter/function bindings. | 171 // Test conflicting parameter/function bindings. |
165 TestNoConflict('(function (x) {' + funbind + '})();'); | 172 TestNoConflict('(function (x) {' + funbind + '})();'); |
OLD | NEW |