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

Side by Side Diff: test/mjsunit/const-redecl.js

Issue 8139027: Version 3.6.5 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 2 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 | « test/mjsunit/compiler/regress-96989.js ('k') | test/mjsunit/element-kind.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 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return CheckException(x); 91 return CheckException(x);
92 } 92 }
93 } 93 }
94 94
95 95
96 function TestAll(expected,s,opt_e) { 96 function TestAll(expected,s,opt_e) {
97 var e = ""; 97 var e = "";
98 var msg = s; 98 var msg = s;
99 if (opt_e) { e = opt_e; msg += "; " + opt_e; } 99 if (opt_e) { e = opt_e; msg += "; " + opt_e; }
100 assertEquals(expected, TestLocal(s,e), "local:'" + msg + "'"); 100 assertEquals(expected, TestLocal(s,e), "local:'" + msg + "'");
101 assertEquals(expected, TestGlobal(s,e), "global:'" + msg + "'"); 101 // Redeclarations of global consts do not throw, they are silently ignored.
102 assertEquals(42, TestGlobal(s, 42), "global:'" + msg + "'");
102 assertEquals(expected, TestContext(s,e), "context:'" + msg + "'"); 103 assertEquals(expected, TestContext(s,e), "context:'" + msg + "'");
103 } 104 }
104 105
105 106
106 function TestConflict(def0, def1) { 107 function TestConflict(def0, def1) {
107 // No eval. 108 // No eval.
108 TestAll("TypeError", def0 +'; ' + def1); 109 TestAll("TypeError", def0 +'; ' + def1);
109 // Eval everything. 110 // Eval everything.
110 TestAll("TypeError", 'eval("' + def0 + '; ' + def1 + '")'); 111 TestAll("TypeError", 'eval("' + def0 + '; ' + def1 + '")');
111 // Eval first definition. 112 // Eval first definition.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 212
212 // Test that const inside loop behaves correctly. 213 // Test that const inside loop behaves correctly.
213 var loop = "for (var i = 0; i < 3; i++) { const x = i; }"; 214 var loop = "for (var i = 0; i < 3; i++) { const x = i; }";
214 TestAll(0, loop, "x"); 215 TestAll(0, loop, "x");
215 TestAll(0, "var a,b,c,d,e,f,g,h; " + loop, "x"); 216 TestAll(0, "var a,b,c,d,e,f,g,h; " + loop, "x");
216 217
217 218
218 // Test that const inside with behaves correctly. 219 // Test that const inside with behaves correctly.
219 TestAll(87, "with ({x:42}) { const x = 87; }", "x"); 220 TestAll(87, "with ({x:42}) { const x = 87; }", "x");
220 TestAll(undefined, "with ({x:42}) { const x; }", "x"); 221 TestAll(undefined, "with ({x:42}) { const x; }", "x");
222
223
224 // Additional tests for how various combinations of re-declarations affect
225 // the values of the var/const in question.
226 try {
227 eval("var undefined;");
228 } catch (ex) {
229 assertUnreachable("undefined (1) has thrown");
230 }
231
232 var original_undef = undefined;
233 var undefined = 1; // Should be silently ignored.
234 assertEquals(original_undef, undefined, "undefined got overwritten");
235 undefined = original_undef;
236
237 var a; const a; const a = 1;
238 assertEquals(1, a, "a has wrong value");
239 a = 2;
240 assertEquals(2, a, "a should be writable");
241
242 var b = 1; const b = 2;
243 assertEquals(2, b, "b has wrong value");
244
245 var c = 1; const c = 2; const c = 3;
246 assertEquals(3, c, "c has wrong value");
247
248 const d = 1; const d = 2;
249 assertEquals(1, d, "d has wrong value");
250
251 const e = 1; var e = 2;
252 assertEquals(1, e, "e has wrong value");
253
254 const f = 1; const f;
255 assertEquals(1, f, "f has wrong value");
256
257 var g; const g = 1;
258 assertEquals(1, g, "g has wrong value");
259 g = 2;
260 assertEquals(2, g, "g should be writable");
261
262 const h; var h = 1;
263 assertEquals(undefined,h, "h has wrong value");
264
265 eval("Object.defineProperty(this, 'i', { writable: true });"
266 + "const i = 7;"
267 + "assertEquals(7, i, \"i has wrong value\");");
268
269 var global = this;
270 assertThrows(function() {
271 Object.defineProperty(global, 'j', { writable: true })
272 }, TypeError);
273 const j = 2; // This is what makes the function above throw, because the
274 // const declaration gets hoisted and makes the property non-configurable.
275 assertEquals(2, j, "j has wrong value");
276
277 var k = 1; const k;
278 // You could argue about the expected result here. For now, the winning
279 // argument is that "const k;" is equivalent to "const k = undefined;".
280 assertEquals(undefined, k, "k has wrong value");
OLDNEW
« no previous file with comments | « test/mjsunit/compiler/regress-96989.js ('k') | test/mjsunit/element-kind.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698