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

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

Issue 7616009: Parse harmony let declarations. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 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 2008 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
11 // with the distribution. 11 // with the distribution.
(...skipping 20 matching lines...) Expand all
32 function f1() { 32 function f1() {
33 { 33 {
34 var x = 1; 34 var x = 1;
35 var y; 35 var y;
36 } 36 }
37 assertEquals(1, x) 37 assertEquals(1, x)
38 assertEquals(undefined, y) 38 assertEquals(undefined, y)
39 } 39 }
40 f1(); 40 f1();
41 41
42 // Dynamic lookup through block scopes. 42
43 // Dynamic lookup in and through block contexts.
43 function f2(one) { 44 function f2(one) {
44 var x = one + 1; 45 var x = one + 1;
45 // TODO(keuchel): introduce let 46 let y = one + 2;
46 // let y = one + 2; 47 {
47 if (one == 1) { 48 let z = one + 3;
48 // Parameter
49 assertEquals(1, eval('one')); 49 assertEquals(1, eval('one'));
50 // Function local var variable
51 assertEquals(2, eval('x')); 50 assertEquals(2, eval('x'));
52 // Function local let variable 51 assertEquals(3, eval('y'));
53 // TODO(keuchel): introduce let 52 assertEquals(4, eval('z'));
54 // assertEquals(3, eval('y'));
55 } 53 }
56 } 54 }
57 f2(1); 55 f2(1);
58 56
57
58 // Lookup in and through block contexts.
rossberg 2011/08/11 14:34:59 It would be great if you could add tests for varia
Lasse Reichstein 2011/08/12 08:08:33 Agree. There is no test here that can distinguish
Steven 2011/08/16 09:05:32 Added your for-loop test that distinguishes those.
Steven 2011/08/16 09:05:32 Done.
59 function f3(one) {
60 var x = one + 1;
61 let y = one + 2;
62 {
63 let z = one + 3;
64 assertEquals(1, one);
65 assertEquals(2, x);
66 assertEquals(3, y);
67 assertEquals(4, z);
68 }
69 }
70 f3(1);
71
72
73 // Dynamic lookup from closure.
74 function f4(one) {
75 var x = one + 1;
76 let y = one + 2;
77 {
78 let z = one + 3;
79 function f() {
80 assertEquals(1, eval('one'));
81 assertEquals(2, eval('x'));
82 assertEquals(3, eval('y'));
83 assertEquals(4, eval('z'));
84 };
85 }
86 }
87 f4(1);
88
89
90 // Lookup from closure.
91 function f5(one) {
92 var x = one + 1;
93 let y = one + 2;
94 {
95 let z = one + 3;
96 function f() {
97 assertEquals(1, one);
98 assertEquals(2, x);
99 assertEquals(3, y);
100 assertEquals(4, z);
101 };
102 }
Lasse Reichstein 2011/08/12 08:08:33 Try creating let variables in a loop. E.g.: var a
Steven 2011/08/16 09:05:32 Done.
103 }
104 f5(1);
105
106 // Return from block.
107 function f6() {
108 let x = 1;
109 {
110 let y = 2;
111 return x + y;
112 }
113 }
114 assertEquals(3, f6(6));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698