Chromium Code Reviews| Index: test/mjsunit/harmony/destructuring.js |
| diff --git a/test/mjsunit/harmony/destructuring.js b/test/mjsunit/harmony/destructuring.js |
| index 3cfb6fc528ec6f981108d16b271251b6a3c6e3b7..d5848d544a5201a146e179c249dc088f816c420f 100644 |
| --- a/test/mjsunit/harmony/destructuring.js |
| +++ b/test/mjsunit/harmony/destructuring.js |
| @@ -18,6 +18,30 @@ |
| sum += z; |
| } |
| assertEquals(6, sum); |
| + |
| + |
| + var countX = 0; |
| + var countY = 0; |
| + var countZ = 0; |
| + var o = { |
| + get x() { |
| + countX++; |
| + return 0; |
| + }, |
| + get y() { |
| + countY++; |
| + return { |
| + get z() { countZ++; return 1; } |
| + } |
| + } |
| + }; |
| + var { 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); |
| }()); |
| @@ -30,6 +54,29 @@ |
| 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; |
|
arv (Not doing code reviews)
2015/05/18 14:00:27
This makes me wish we had a test that makes sure w
Dmitry Lomov (no reviews)
2015/05/18 14:25:56
Done.
|
| + 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 +93,9 @@ |
| assertEquals(1, x); |
| assertEquals(2, y); |
| + assertThrows(function() { x++; }, TypeError); |
| + assertThrows(function() { y++; }, TypeError); |
| + |
| const {z} = { z : 3 }; |
| assertEquals(3, z); |
| @@ -54,3 +104,45 @@ |
| 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); |
| + assertThrows(function() { var {x} = null; }, TypeError); |
| + assertThrows(function() { var { x : {} } = { x : null }; }, TypeError); |
| + assertThrows(function() { 'use strict'; let {} = null; }, TypeError); |
| + assertThrows(function() { 'use strict'; let {x} = null; }, TypeError); |
| + assertThrows(function() { 'use strict'; let { x : {} } = { x : null }; }, TypeError); |
| +}()); |