Index: test/mjsunit/harmony/destructuring.js |
diff --git a/test/mjsunit/harmony/destructuring.js b/test/mjsunit/harmony/destructuring.js |
index 3cfb6fc528ec6f981108d16b271251b6a3c6e3b7..cbb2c2a2d81361ed960e9b237577ad599bc5c1d2 100644 |
--- a/test/mjsunit/harmony/destructuring.js |
+++ b/test/mjsunit/harmony/destructuring.js |
@@ -18,6 +18,29 @@ |
sum += z; |
} |
assertEquals(6, sum); |
+ |
+ |
+ var countX = 0; |
+ var countY = 0; |
+ var countZ = 0; |
+ var o = { get x() { |
arv (Not doing code reviews)
2015/05/18 13:12:53
var o = {
get x() {
...
}
};
Dmitry Lomov (no reviews)
2015/05/18 13:41:46
Done.
|
+ countX++; |
+ return 0; |
+ }, |
+ get y() { |
+ countY++; |
+ return { |
+ get z() { countZ++; return 1; } |
+ } |
+ } |
+ }; |
+ var { x : x0, y : { z : z1 }, x : x1 } = o; |
arv (Not doing code reviews)
2015/05/18 13:12:53
who would have ever thought :-)
|
+ assertSame(0, x0); |
+ assertSame(1, z1); |
+ assertSame(0, x1); |
+ assertEquals(2, countX); |
+ assertEquals(1, countY); |
+ assertEquals(1, countZ); |
}()); |
@@ -30,6 +53,28 @@ |
let {z} = { z : 3 }; |
assertEquals(3, z); |
+ let countX = 0; |
+ let countY = 0; |
+ let countZ = 0; |
+ let o = { get x() { |
+ countX++; |
+ return 0; |
+ }, |
+ get y() { |
+ countY++; |
+ return { |
+ get z() { countZ++; return 1; } |
+ } |
+ } |
+ }; |
+ let { x : x0, y : { z : z1 }, x : x1 } = o; |
+ assertSame(0, x0); |
+ assertSame(1, z1); |
+ assertSame(0, x1); |
+ assertEquals(2, countX); |
+ assertEquals(1, countY); |
+ assertEquals(1, countZ); |
+ |
let sum = 0; |
for(let {x, z} = { x : 0, z : 3 }; z != 0; z--) { |
@@ -46,6 +91,9 @@ |
assertEquals(1, x); |
assertEquals(2, y); |
+ assertThrows(function() { x++; }, TypeError); |
+ assertThrows(function() { y++; }, TypeError); |
+ |
const {z} = { z : 3 }; |
assertEquals(3, z); |
@@ -54,3 +102,41 @@ |
assertTrue(false); |
} |
}()); |
+ |
+(function TestFailingMatchesSloppy() { |
+ var {x, y} = {}; |
+ assertSame(undefined, x); |
+ assertSame(undefined, y); |
+ |
+ var { x : { z1 }, y2} = { x : {}, y2 : 42 } |
+ assertSame(undefined, z1); |
+ assertSame(42, y2); |
+}()); |
+ |
+ |
+(function TestFailingMatchesStrict() { |
+ 'use strict'; |
+ var {x, y} = {}; |
+ assertSame(undefined, x); |
+ assertSame(undefined, y); |
+ |
+ var { x : { z1 }, y2} = { x : {}, y2 : 42 } |
+ assertSame(undefined, z1); |
+ assertSame(42, y2); |
+ |
+ { |
+ let {x1,y1} = {}; |
+ assertSame(undefined, x1); |
+ assertSame(undefined, y1); |
+ |
+ let { x : { z1 }, y2} = { x : {}, y2 : 42 } |
+ assertSame(undefined, z1); |
+ assertSame(42, y2); |
+ } |
+}()); |
+ |
+ |
+(function TestExceptions() { |
+ assertThrows(function() { var {} = null; }, TypeError); |
caitp (gmail)
2015/05/18 13:11:06
do we want to test the other cases that would caus
Dmitry Lomov (no reviews)
2015/05/18 13:41:46
Done.
|
+ assertThrows(function() { 'use strict'; let {} = null; }, TypeError); |
+}()); |