Index: test/mjsunit/harmony/block-scoping.js |
diff --git a/test/mjsunit/harmony/block-scoping.js b/test/mjsunit/harmony/block-scoping.js |
index 1181bd12329a101d4a8331f617de0c50b304bafc..0e09ddc50f607ffb2914d309cb1d3b127e1ee48a 100644 |
--- a/test/mjsunit/harmony/block-scoping.js |
+++ b/test/mjsunit/harmony/block-scoping.js |
@@ -1,4 +1,4 @@ |
-// Copyright 2008 the V8 project authors. All rights reserved. |
+// Copyright 2011 the V8 project authors. All rights reserved. |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
// met: |
@@ -39,20 +39,76 @@ 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. |
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.
|
+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); |
+ }; |
+ } |
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.
|
+} |
+f5(1); |
+ |
+// Return from block. |
+function f6() { |
+ let x = 1; |
+ { |
+ let y = 2; |
+ return x + y; |
+ } |
+} |
+assertEquals(3, f6(6)); |