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

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: Comments 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
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/harmony/block-let-declaration.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
60 var e = ""; 69 var e = "";
61 var msg = s; 70 var msg = s;
62 if (opt_e) { e = opt_e; msg += "; " + opt_e; } 71 if (opt_e) { e = opt_e; msg += opt_e; }
63 assertEquals(expected, TestFunction(s,e), "function:'" + msg + "'"); 72 assertEquals(expected === 'LocalConflict' ? 'NoConflict' : expected,
64 assertEquals(expected, TestBlock(s,e), "block:'" + msg + "'"); 73 TestGlobal(s,e), "global:'" + msg + "'");
74 assertEquals(expected === 'LocalConflict' ? 'NoConflict' : expected,
75 TestFunction(s,e), "function:'" + msg + "'");
76 assertEquals(expected === 'LocalConflict' ? 'Conflict' : expected,
77 TestBlock(s,e), "block:'" + msg + "'");
65 } 78 }
66 79
67 80
68 function TestConflict(s) { 81 function TestConflict(s) {
69 TestAll('Conflict', s); 82 TestAll('Conflict', s);
70 TestAll('Conflict', 'eval("' + s + '")'); 83 TestAll('Conflict', 'eval("' + s + '");');
71 } 84 }
72 85
73
74 function TestNoConflict(s) { 86 function TestNoConflict(s) {
75 TestAll('NoConflict', s, "'NoConflict'"); 87 TestAll('NoConflict', s, "'NoConflict'");
76 TestAll('NoConflict', 'eval("' + s + '")', "'NoConflict'"); 88 TestAll('NoConflict', 'eval("' + s + '");', "'NoConflict'");
77 } 89 }
78 90
79 var letbinds = [ "let x", 91 function TestLocalConflict(s) {
80 "let x = 0", 92 TestAll('LocalConflict', s, "'NoConflict'");
81 "let x = undefined", 93 TestAll('NoConflict', 'eval("' + s + '");', "'NoConflict'");
82 "function x() { }", 94 }
83 "let x = function() {}", 95
84 "let x, y", 96 var letbinds = [ "let x;",
85 "let y, x", 97 "let x = 0;",
86 "const x = 0", 98 "let x = undefined;",
87 "const x = undefined", 99 "let x = function() {};",
88 "const x = function() {}", 100 "let x, y;",
89 "const x = 2, y = 3", 101 "let y, x;",
90 "const y = 4, x = 5", 102 "const x = 0;",
103 "const x = undefined;",
104 "const x = function() {};",
105 "const x = 2, y = 3;",
106 "const y = 4, x = 5;",
91 ]; 107 ];
92 var varbinds = [ "var x", 108 var varbinds = [ "var x;",
93 "var x = 0", 109 "var x = 0;",
94 "var x = undefined", 110 "var x = undefined;",
95 "var x = function() {}", 111 "var x = function() {};",
96 "var x, y", 112 "var x, y;",
97 "var y, x", 113 "var y, x;",
98 ]; 114 ];
99 115 var funbind = "function x() {}";
100 116
101 for (var l = 0; l < letbinds.length; ++l) { 117 for (var l = 0; l < letbinds.length; ++l) {
102 // Test conflicting let/var bindings. 118 // Test conflicting let/var bindings.
103 for (var v = 0; v < varbinds.length; ++v) { 119 for (var v = 0; v < varbinds.length; ++v) {
104 // Same level. 120 // Same level.
105 TestConflict(letbinds[l] +'; ' + varbinds[v]); 121 TestConflict(letbinds[l] + varbinds[v]);
106 TestConflict(varbinds[v] +'; ' + letbinds[l]); 122 TestConflict(varbinds[v] + letbinds[l]);
107 // Different level. 123 // Different level.
108 TestConflict(letbinds[l] +'; {' + varbinds[v] + '; }'); 124 TestConflict(letbinds[l] + '{' + varbinds[v] + '}');
109 TestConflict('{ ' + varbinds[v] +'; }' + letbinds[l]); 125 TestConflict('{' + varbinds[v] +'}' + letbinds[l]);
126 TestNoConflict(varbinds[v] + '{' + letbinds[l] + '}');
127 TestNoConflict('{' + letbinds[l] + '}' + varbinds[v]);
128 // For loop.
129 TestConflict('for (' + letbinds[l] + '0;) {' + varbinds[v] + '}');
130 TestNoConflict('for (' + varbinds[v] + '0;) {' + letbinds[l] + '}');
110 } 131 }
111 132
112 // Test conflicting let/let bindings. 133 // Test conflicting let/let bindings.
113 for (var k = 0; k < letbinds.length; ++k) { 134 for (var k = 0; k < letbinds.length; ++k) {
114 // Same level. 135 // Same level.
115 TestConflict(letbinds[l] +'; ' + letbinds[k]); 136 TestConflict(letbinds[l] + letbinds[k]);
116 TestConflict(letbinds[k] +'; ' + letbinds[l]); 137 TestConflict(letbinds[k] + letbinds[l]);
117 // Different level. 138 // Different level.
118 TestNoConflict(letbinds[l] +'; { ' + letbinds[k] + '; }'); 139 TestNoConflict(letbinds[l] + '{ ' + letbinds[k] + '}');
119 TestNoConflict('{ ' + letbinds[k] +'; } ' + letbinds[l]); 140 TestNoConflict('{' + letbinds[k] +'} ' + letbinds[l]);
141 // For loop.
142 TestNoConflict('for (' + letbinds[l] + '0;) {' + letbinds[k] + '}');
143 TestNoConflict('for (' + letbinds[k] + '0;) {' + letbinds[l] + '}');
120 } 144 }
121 145
146 // Test conflicting function/let bindings.
147 // Same level.
148 TestConflict(letbinds[l] + funbind);
149 TestConflict(funbind + letbinds[l]);
150 // Different level.
151 TestNoConflict(letbinds[l] + '{' + funbind + '}');
152 TestNoConflict('{' + funbind + '}' + letbinds[l]);
153 TestNoConflict(funbind + '{' + letbinds[l] + '}');
154 TestNoConflict('{' + letbinds[l] + '}' + funbind);
155 // For loop.
156 TestNoConflict('for (' + letbinds[l] + '0;) {' + funbind + '}');
157
122 // Test conflicting parameter/let bindings. 158 // Test conflicting parameter/let bindings.
123 TestConflict('(function (x) { ' + letbinds[l] + '; })()'); 159 TestConflict('(function(x) {' + letbinds[l] + '})();');
160 }
161
162 // Test conflicting function/var bindings.
163 for (var v = 0; v < varbinds.length; ++v) {
164 // Same level.
165 TestLocalConflict(varbinds[v] + funbind);
166 TestLocalConflict(funbind + varbinds[v]);
167 // Different level.
168 TestLocalConflict(funbind + '{' + varbinds[v] + '}');
169 TestLocalConflict('{' + varbinds[v] +'}' + funbind);
170 TestNoConflict(varbinds[v] + '{' + funbind + '}');
171 TestNoConflict('{' + funbind + '}' + varbinds[v]);
172 // For loop.
173 TestNoConflict('for (' + varbinds[v] + '0;) {' + funbind + '}');
124 } 174 }
125 175
126 // Test conflicting catch/var bindings. 176 // Test conflicting catch/var bindings.
127 for (var v = 0; v < varbinds.length; ++v) { 177 for (var v = 0; v < varbinds.length; ++v) {
128 TestConflict('try {} catch (x) { ' + varbinds[v] + '; }'); 178 TestConflict('try {} catch(x) {' + varbinds[v] + '}');
129 } 179 }
130 180
131 // Test conflicting parameter/var bindings. 181 // Test conflicting parameter/var bindings.
132 for (var v = 0; v < varbinds.length; ++v) { 182 for (var v = 0; v < varbinds.length; ++v) {
133 TestNoConflict('(function (x) { ' + varbinds[v] + '; })()'); 183 TestNoConflict('(function (x) {' + varbinds[v] + '})();');
134 } 184 }
185
186 // Test conflicting catch/function bindings.
187 TestNoConflict('try {} catch(x) {' + funbind + '}');
188
189 // Test conflicting parameter/function bindings.
190 TestNoConflict('(function (x) {' + funbind + '})();');
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/harmony/block-let-declaration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698