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

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: Comments addressed, landing 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
Index: test/mjsunit/harmony/destructuring.js
diff --git a/test/mjsunit/harmony/destructuring.js b/test/mjsunit/harmony/destructuring.js
index 3cfb6fc528ec6f981108d16b271251b6a3c6e3b7..83d0563b5ccd091d75a1106d6394fd3f6b0607fb 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);
}());
@@ -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);
+ assertThrows(function() { y++; }, TypeError);
+
const {z} = { z : 3 };
assertEquals(3, z);
@@ -54,3 +95,49 @@
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() {
+ for (var val of [null, undefined]) {
+ assertThrows(function() { var {} = val; }, TypeError);
+ assertThrows(function() { var {x} = val; }, TypeError);
+ assertThrows(function() { var { x : {} } = { x : val }; }, TypeError);
+ assertThrows(function() { 'use strict'; let {} = val; }, TypeError);
+ assertThrows(function() { 'use strict'; let {x} = val; }, TypeError);
+ assertThrows(function() { 'use strict'; let { x : {} } = { x : val }; },
+ TypeError);
+ }
+}());
« test/message/destructuring-modify-const.js ('K') | « test/message/destructuring-modify-const.out ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698