Chromium Code Reviews| Index: test/mjsunit/harmony/destructuring.js |
| diff --git a/test/mjsunit/harmony/destructuring.js b/test/mjsunit/harmony/destructuring.js |
| index 015b6dee93e0cc399bd2151aa2c643f7984eb1d0..d15200804166709e42f45418949d19c35953b129 100644 |
| --- a/test/mjsunit/harmony/destructuring.js |
| +++ b/test/mjsunit/harmony/destructuring.js |
| @@ -23,12 +23,12 @@ |
| var countX = 0; |
| var countY = 0; |
| var countZ = 0; |
| - var o = { get x() { |
| - countX++; |
| + var o = { get x() { |
| + countX++; |
| return 0; |
| }, |
| - get y() { |
| - countY++; |
| + get y() { |
| + countY++; |
| return { |
| get z() { countZ++; return 1; } |
| } |
| @@ -41,8 +41,87 @@ |
| assertEquals(2, countX); |
| assertEquals(1, countY); |
| assertEquals(1, countZ); |
| +}()); |
| + |
| + |
| +(function TestObjectLiteralPatternInitializers() { |
| + var { x : x, y : y = 2 } = { x : 1 }; |
| + assertEquals(1, x); |
| + assertEquals(2, y); |
| + |
| + var {z = 3} = {}; |
| + assertEquals(3, z); |
| + |
|
arv (Not doing code reviews)
2015/05/18 14:36:20
-1 newline
Dmitry Lomov (no reviews)
2015/05/18 17:31:23
Done.
|
| + |
| + var sum = 0; |
| + for(var {z = 3} = {}; z != 0; z--) { |
|
arv (Not doing code reviews)
2015/05/18 14:36:20
ws
Dmitry Lomov (no reviews)
2015/05/18 17:31:23
Done.
|
| + sum += z; |
| + } |
| + assertEquals(6, sum); |
|
rossberg
2015/05/18 16:17:20
Nit: newline
Dmitry Lomov (no reviews)
2015/05/18 17:31:23
Done.
|
| + var countX = 0; |
| + var countY = 0; |
| + var countZ = 0; |
| + var o = { get x() { |
|
rossberg
2015/05/18 16:17:19
Can we modify this test (and below) such that it a
Dmitry Lomov (no reviews)
2015/05/18 17:31:23
Done.
|
| + countX++; |
| + return undefined; |
| + }, |
| + get y() { |
| + countY++; |
| + return { |
| + get z() { countZ++; return undefined; } |
| + } |
| + } |
| + }; |
| + var { x : x0 = 0, y : { z : z1 = 1}, x : x1 = 0} = o; |
| + assertSame(0, x0); |
| + assertSame(1, z1); |
| + assertSame(0, x1); |
| + assertEquals(2, countX); |
| + assertEquals(1, countY); |
| + assertEquals(1, countZ); |
| +}()); |
| + |
| + |
| +(function TestObjectLiteralPatternLexicalInitializers() { |
| + 'use strict'; |
| + let { x : x, y : y = 2 } = { x : 1 }; |
| + assertEquals(1, x); |
| + assertEquals(2, y); |
| + |
| + let {z = 3} = {}; |
| + assertEquals(3, z); |
| + |
| + let countX = 0; |
| + let countY = 0; |
| + let countZ = 0; |
| + let o = { get x() { |
| + countX++; |
| + return undefined; |
| + }, |
| + get y() { |
| + countY++; |
| + return { |
| + get z() { countZ++; return undefined; } |
| + } |
| + } |
| + }; |
| + let { x : x0 = 0, y : { z : z1 = 1 }, x : x1 = 5} = o; |
| + assertSame(0, x0); |
| + assertSame(1, z1); |
| + assertSame(5, x1); |
| + assertEquals(2, countX); |
| + assertEquals(1, countY); |
| + assertEquals(1, countZ); |
| + |
| + |
| + let sum = 0; |
| + for(let {x = 0, z = 3} = {}; z != 0; z--) { |
| + assertEquals(0, x); |
| + sum += z; |
| + } |
| + assertEquals(6, sum); |
| }()); |
| @@ -58,12 +137,12 @@ |
| let countX = 0; |
| let countY = 0; |
| let countZ = 0; |
| - let o = { get x() { |
| - countX++; |
| + let o = { get x() { |
| + countX++; |
| return 0; |
| }, |
| - get y() { |
| - countY++; |
| + get y() { |
| + countY++; |
| return { |
| get z() { countZ++; return 1; } |
| } |
| @@ -105,6 +184,73 @@ |
| } |
| }()); |
| +(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 TestTDZInIntializers() { |
|
rossberg
2015/05/18 16:17:19
Add tests like
let {x, y = eval("x")} = {x:42}
le
Dmitry Lomov (no reviews)
2015/05/18 17:31:23
Done.
|
| + 'use strict'; |
| + { |
| + let {x, y = x} = {x : 42, y : 27}; |
| + assertSame(42, x); |
| + assertSame(27, y); |
| + } |
| + |
| + { |
| + let {x, y = x + 1} = { x : 42 }; |
| + assertSame(42, x); |
| + assertSame(43, y); |
| + } |
| + assertThrows(function() { |
| + let {x = y, y} = { y : 42 }; |
| + }, ReferenceError); |
| +}()); |
| + |
| + |
| +(function TestSideEffectsInInitializers() { |
| + var callCount = 0; |
| + function f(v) { callCount++; return v; } |
| + |
| + callCount = 0; |
| + var { x = f(42) } = { x : 27 }; |
| + assertSame(27, x); |
| + assertEquals(0, callCount); |
| + |
| + callCount = 0; |
| + var { x = f(42) } = {}; |
| + assertSame(42, x); |
| + assertEquals(1, callCount); |
| +}()); |
| + |
|
arv (Not doing code reviews)
2015/05/18 14:36:20
Did you want to add tests for
let {x, x} = {x: 1
Dmitry Lomov (no reviews)
2015/05/18 17:31:23
Done.
|
| (function TestExceptions() { |
| assertThrows(function() { var {} = null; }, TypeError); |