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

Unified Diff: test/mjsunit/harmony/destructuring.js

Issue 1139773005: [destructuring] More tests for object literal pattern (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: More feedback Created 5 years, 7 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
« src/pattern-rewriter.cc ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/destructuring.js
diff --git a/test/mjsunit/harmony/destructuring.js b/test/mjsunit/harmony/destructuring.js
index 3cfb6fc528ec6f981108d16b271251b6a3c6e3b7..c07cb502b4d066876d6b8d1b68266f227ad15757 100644
--- a/test/mjsunit/harmony/destructuring.js
+++ b/test/mjsunit/harmony/destructuring.js
@@ -18,6 +18,26 @@
sum += z;
}
assertEquals(6, sum);
+
+
+ var log = [];
+ var o = {
+ get x() {
+ log.push("x");
+ return 0;
+ },
+ get y() {
+ log.push("y");
+ return {
+ get z() { log.push("z"); return 1; }
+ }
+ }
+ };
+ var { x : x0, y : { z : z1 }, x : x1 } = o;
+ assertSame(0, x0);
+ assertSame(1, z1);
+ assertSame(0, x1);
+ assertArrayEquals(["x", "y", "z", "x"], log);
arv (Not doing code reviews) 2015/05/18 14:43:42 thanks
Dmitry Lomov (no reviews) 2015/05/18 16:28:23 Acknowledged.
}());
@@ -30,6 +50,24 @@
let {z} = { z : 3 };
assertEquals(3, z);
+ let log = [];
+ let o = {
+ get x() {
+ log.push("x");
+ return 0;
+ },
+ get y() {
+ log.push("y");
+ return {
+ get z() { log.push("z"); return 1; }
+ }
+ }
+ };
+ let { x : x0, y : { z : z1 }, x : x1 } = o;
+ assertSame(0, x0);
+ assertSame(1, z1);
+ assertSame(0, x1);
+ assertArrayEquals(["x", "y", "z", "x"], log);
let sum = 0;
for(let {x, z} = { x : 0, z : 3 }; z != 0; z--) {
@@ -46,6 +84,9 @@
assertEquals(1, x);
assertEquals(2, y);
+ assertThrows(function() { x++; }, TypeError);
arv (Not doing code reviews) 2015/05/18 14:43:42 Can you add a test/message/ test too?
Dmitry Lomov (no reviews) 2015/05/18 16:28:23 Done.
+ assertThrows(function() { y++; }, TypeError);
+
const {z} = { z : 3 };
assertEquals(3, z);
@@ -54,3 +95,45 @@
assertTrue(false);
}
}());
+
arv (Not doing code reviews) 2015/05/18 14:43:42 +1 newline for consistency
Dmitry Lomov (no reviews) 2015/05/18 16:28:23 Done.
+(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() {
arv (Not doing code reviews) 2015/05/18 14:43:42 How about: (function TestExceptions() { for (va
Dmitry Lomov (no reviews) 2015/05/18 16:28:23 Done.
+ 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);
+}());
« src/pattern-rewriter.cc ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698