Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: test/mjsunit/harmony/block-conflicts.js

Issue 377513006: Fix several issues with ES6 redeclaration checks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 21 matching lines...) Expand all
32 "use strict"; 32 "use strict";
33 33
34 function CheckException(e) { 34 function CheckException(e) {
35 var string = e.toString(); 35 var string = e.toString();
36 assertTrue(string.indexOf("has already been declared") >= 0 || 36 assertTrue(string.indexOf("has already been declared") >= 0 ||
37 string.indexOf("redeclaration") >= 0); 37 string.indexOf("redeclaration") >= 0);
38 return 'Conflict'; 38 return 'Conflict';
39 } 39 }
40 40
41 41
42 function TestGlobal(s,e) {
43 try {
44 return eval(s + e);
45 } catch (x) {
46 return CheckException(x);
47 }
48 }
49
50
42 function TestFunction(s,e) { 51 function TestFunction(s,e) {
43 try { 52 try {
44 return eval("(function(){" + s + ";return " + e + "})")(); 53 return eval("(function(){" + s + " return " + e + "})")();
45 } catch (x) { 54 } catch (x) {
46 return CheckException(x); 55 return CheckException(x);
47 } 56 }
48 } 57 }
49 58
50 59
51 function TestBlock(s,e) { 60 function TestBlock(s,e) {
52 try { 61 try {
53 return eval("(function(){ if (true) { " + s + "; }; return " + e + "})")(); 62 return eval("(function(){ {" + s + "} return " + e + "})")();
54 } catch (x) { 63 } catch (x) {
55 return CheckException(x); 64 return CheckException(x);
56 } 65 }
57 } 66 }
58 67
59 function TestAll(expected,s,opt_e) { 68 function TestAll(expected,s,opt_e) {
69 print(s, opt_e)
ulan 2014/07/09 08:49:32 Debug output?
rossberg 2014/07/09 11:30:41 Done.
60 var e = ""; 70 var e = "";
61 var msg = s; 71 var msg = s;
62 if (opt_e) { e = opt_e; msg += "; " + opt_e; } 72 if (opt_e) { e = opt_e; msg += opt_e; }
63 assertEquals(expected, TestFunction(s,e), "function:'" + msg + "'"); 73 assertEquals(expected === 'LocalConflict' ? 'NoConflict' : expected,
64 assertEquals(expected, TestBlock(s,e), "block:'" + msg + "'"); 74 TestGlobal(s,e), "global:'" + msg + "'");
75 assertEquals(expected === 'LocalConflict' ? 'NoConflict' : expected,
76 TestFunction(s,e), "function:'" + msg + "'");
77 assertEquals(expected === 'LocalConflict' ? 'Conflict' : expected,
78 TestBlock(s,e), "block:'" + msg + "'");
65 } 79 }
66 80
67 81
68 function TestConflict(s) { 82 function TestConflict(s) {
69 TestAll('Conflict', s); 83 TestAll('Conflict', s);
70 TestAll('Conflict', 'eval("' + s + '")'); 84 TestAll('Conflict', 'eval("' + s + '");');
71 } 85 }
72 86
73
74 function TestNoConflict(s) { 87 function TestNoConflict(s) {
75 TestAll('NoConflict', s, "'NoConflict'"); 88 TestAll('NoConflict', s, "'NoConflict'");
76 TestAll('NoConflict', 'eval("' + s + '")', "'NoConflict'"); 89 TestAll('NoConflict', 'eval("' + s + '");', "'NoConflict'");
77 } 90 }
78 91
79 var letbinds = [ "let x", 92 function TestLocalConflict(s) {
80 "let x = 0", 93 TestAll('LocalConflict', s, "'NoConflict'");
81 "let x = undefined", 94 TestAll('NoConflict', 'eval("' + s + '");', "'NoConflict'");
82 "function x() { }", 95 }
83 "let x = function() {}", 96
84 "let x, y", 97 var letbinds = [ "let x;",
85 "let y, x", 98 "let x = 0;",
86 "const x = 0", 99 "let x = undefined;",
87 "const x = undefined", 100 "let x = function() {};",
88 "const x = function() {}", 101 "let x, y;",
89 "const x = 2, y = 3", 102 "let y, x;",
90 "const y = 4, x = 5", 103 // TODO(rossberg): reactivate when for-const is fixed.
104 /*
105 "const x = 0;",
106 "const x = undefined;",
107 "const x = function() {};",
108 "const x = 2, y = 3;",
109 "const y = 4, x = 5;",
110 */
91 ]; 111 ];
92 var varbinds = [ "var x", 112 var varbinds = [ "var x;",
93 "var x = 0", 113 "var x = 0;",
94 "var x = undefined", 114 "var x = undefined;",
95 "var x = function() {}", 115 "var x = function() {};",
96 "var x, y", 116 "var x, y;",
97 "var y, x", 117 "var y, x;",
98 ]; 118 ];
99 119 var funbind = "function x() {}";
100 120
101 for (var l = 0; l < letbinds.length; ++l) { 121 for (var l = 0; l < letbinds.length; ++l) {
102 // Test conflicting let/var bindings. 122 // Test conflicting let/var bindings.
103 for (var v = 0; v < varbinds.length; ++v) { 123 for (var v = 0; v < varbinds.length; ++v) {
104 // Same level. 124 // Same level.
105 TestConflict(letbinds[l] +'; ' + varbinds[v]); 125 TestConflict(letbinds[l] + varbinds[v]);
106 TestConflict(varbinds[v] +'; ' + letbinds[l]); 126 TestConflict(varbinds[v] + letbinds[l]);
107 // Different level. 127 // Different level.
108 TestConflict(letbinds[l] +'; {' + varbinds[v] + '; }'); 128 TestConflict(letbinds[l] + '{' + varbinds[v] + '}');
109 TestConflict('{ ' + varbinds[v] +'; }' + letbinds[l]); 129 TestConflict('{' + varbinds[v] +'}' + letbinds[l]);
130 TestNoConflict(varbinds[v] + '{' + letbinds[l] + '}');
131 TestNoConflict('{' + letbinds[l] + '}' + varbinds[v]);
132 // For loop.
133 TestConflict('for (' + letbinds[l] + '0;0) {' + varbinds[v] + '}');
134 TestNoConflict('for (' + varbinds[v] + '0;0) {' + letbinds[l] + '}');
110 } 135 }
111 136
112 // Test conflicting let/let bindings. 137 // Test conflicting let/let bindings.
113 for (var k = 0; k < letbinds.length; ++k) { 138 for (var k = 0; k < letbinds.length; ++k) {
114 // Same level. 139 // Same level.
115 TestConflict(letbinds[l] +'; ' + letbinds[k]); 140 TestConflict(letbinds[l] + letbinds[k]);
116 TestConflict(letbinds[k] +'; ' + letbinds[l]); 141 TestConflict(letbinds[k] + letbinds[l]);
117 // Different level. 142 // Different level.
118 TestNoConflict(letbinds[l] +'; { ' + letbinds[k] + '; }'); 143 TestNoConflict(letbinds[l] + '{ ' + letbinds[k] + '}');
119 TestNoConflict('{ ' + letbinds[k] +'; } ' + letbinds[l]); 144 TestNoConflict('{' + letbinds[k] +'} ' + letbinds[l]);
145 // For loop.
146 TestNoConflict('for (' + letbinds[l] + '0;0) {' + letbinds[k] + '}');
147 TestNoConflict('for (' + letbinds[k] + '0;0) {' + letbinds[l] + '}');
120 } 148 }
121 149
150 // Test conflicting function/let bindings.
151 // Same level.
152 TestConflict(letbinds[l] + funbind);
153 TestConflict(funbind + letbinds[l]);
154 // Different level.
155 TestNoConflict(letbinds[l] + '{' + funbind + '}');
156 TestNoConflict('{' + funbind + '}' + letbinds[l]);
157 TestNoConflict(funbind + '{' + letbinds[l] + '}');
158 TestNoConflict('{' + letbinds[l] + '}' + funbind);
159 // For loop.
160 TestNoConflict('for (' + letbinds[l] + '0;0) {' + funbind + '}');
161
122 // Test conflicting parameter/let bindings. 162 // Test conflicting parameter/let bindings.
123 TestConflict('(function (x) { ' + letbinds[l] + '; })()'); 163 TestConflict('(function(x) {' + letbinds[l] + '})();');
164 }
165
166 // Test conflicting function/var bindings.
167 for (var v = 0; v < varbinds.length; ++v) {
168 // Same level.
169 TestLocalConflict(varbinds[v] + funbind);
170 TestLocalConflict(funbind + varbinds[v]);
171 // Different level.
172 TestLocalConflict(funbind + '{' + varbinds[v] + '}');
173 TestLocalConflict('{' + varbinds[v] +'}' + funbind);
174 TestNoConflict(varbinds[v] + '{' + funbind + '}');
175 TestNoConflict('{' + funbind + '}' + varbinds[v]);
176 // For loop.
177 TestNoConflict('for (' + varbinds[v] + '0;0) {' + funbind + '}');
124 } 178 }
125 179
126 // Test conflicting catch/var bindings. 180 // Test conflicting catch/var bindings.
127 for (var v = 0; v < varbinds.length; ++v) { 181 for (var v = 0; v < varbinds.length; ++v) {
128 TestConflict('try {} catch (x) { ' + varbinds[v] + '; }'); 182 TestConflict('try {} catch(x) {' + varbinds[v] + '}');
129 } 183 }
130 184
131 // Test conflicting parameter/var bindings. 185 // Test conflicting parameter/var bindings.
132 for (var v = 0; v < varbinds.length; ++v) { 186 for (var v = 0; v < varbinds.length; ++v) {
133 TestNoConflict('(function (x) { ' + varbinds[v] + '; })()'); 187 TestNoConflict('(function (x) {' + varbinds[v] + '})();');
134 } 188 }
189
190 // Test conflicting catch/function bindings.
191 TestNoConflict('try {} catch(x) {' + funbind + '}');
192
193 // Test conflicting parameter/function bindings.
194 TestNoConflict('(function (x) {' + funbind + '})();');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698