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

Unified 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: Updated tests. 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 side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/harmony/block-scoping.js
diff --git a/test/mjsunit/harmony/block-scoping.js b/test/mjsunit/harmony/block-scoping.js
index f974de82b5ce35b94dc58acb0ed651246014e1f9..46e3eb316f6636fd36c0357b0954e19d7b02e820 100644
--- a/test/mjsunit/harmony/block-scoping.js
+++ b/test/mjsunit/harmony/block-scoping.js
@@ -39,20 +39,145 @@ function f1() {
}
f1();
-// Dynamic lookup through block scopes.
+
+// Dynamic lookup in and through block contexts.
function f2(one) {
var x = one + 1;
- // TODO(keuchel): introduce let
- // let y = one + 2;
- if (one == 1) {
- // Parameter
+ let y = one + 2;
+ {
+ let z = one + 3;
assertEquals(1, eval('one'));
- // Function local var variable
assertEquals(2, eval('x'));
- // Function local let variable
- // TODO(keuchel): introduce let
- // assertEquals(3, eval('y'));
+ assertEquals(3, eval('y'));
+ assertEquals(4, eval('z'));
}
}
f2(1);
+
+// Lookup in and through block contexts.
+function f3(one) {
+ var x = one + 1;
+ let y = one + 2;
+ {
+ let z = one + 3;
+ assertEquals(1, one);
+ assertEquals(2, x);
+ assertEquals(3, y);
+ assertEquals(4, z);
+ }
+}
+f3(1);
+
+
+// Dynamic lookup from closure.
+function f4(one) {
+ var x = one + 1;
+ let y = one + 2;
+ {
+ let z = one + 3;
+ function f() {
+ assertEquals(1, eval('one'));
+ assertEquals(2, eval('x'));
+ assertEquals(3, eval('y'));
+ assertEquals(4, eval('z'));
+ };
+ }
+}
+f4(1);
+
+
+// Lookup from closure.
+function f5(one) {
+ var x = one + 1;
+ let y = one + 2;
+ {
+ let z = one + 3;
+ function f() {
+ assertEquals(1, one);
+ assertEquals(2, x);
+ assertEquals(3, y);
+ assertEquals(4, z);
+ };
+ }
+}
+f5(1);
+
+
+// Return from block.
+function f6() {
+ let x = 1;
+ {
+ let y = 2;
+ return x + y;
+ }
+}
+assertEquals(3, f6(6));
+
+
+// Variable shadowing.
+function f7(a) {
+ let b = 1;
+ { // let vars shadowing arg and let var
+ let a = 2;
+ let b = 2;
+ }
+ try {
+ throw 'stuff1';
+ } catch (a) {
+ // catch var shadowing arg
+ a = 2;
+ {
+ // let var shadowing catch var
+ let a = 3;
+ try {
+ throw 'stuff2';
+ } catch (a) {
+ // catch var shadowing let var
+ a = 4;
+ }
+ assertEquals(3,a);
+ }
+ assertEquals(2,a);
+ }
+ try {
+ throw 'stuff3';
+ } catch (c) {
+ try {
+ throw 'stuff4';
+ } catch(c) {
+ // catch var shadowing catch var
+ c = 3;
+ }
+ (function(c) {
+ // arg shadowing catch
+ })();
+ assertEquals('stuff3', c);
+ }
+ (function(a,b) {
+ // arg shadowing arg and let var
+ a = 2;
+ b = 2;
+ })(1,1);
+ assertEquals(1,a);
+ assertEquals(1,b);
+}
+f7(1);
+
+
+// Ensure let variables are block local and var variables function local.
+function f8() {
+ var let_accessors = [];
+ var var_accessors = [];
+ for (var i = 0; i < 10; i++) {
+ let x = i;
+ var y = i;
+ let_accessors[i] = function() { return x; }
+ var_accessors[i] = function() { return i; }
+ }
+ for (var i = 0; i < 10; i++) {
+ y = j + 10;
Lasse Reichstein 2011/08/16 11:00:46 Should y not just always be 10? And I can't see "j
Steven 2011/08/16 15:06:08 Done.
+ assertEquals(i, let_accessors[i]());
+ assertEquals(y, var_accessors[i]());
+ }
+}
Lasse Reichstein 2011/08/16 11:00:46 And you don't call f8 (which is why it could be bu
Steven 2011/08/16 15:06:08 Done.

Powered by Google App Engine
This is Rietveld 408576698