Index: test/mjsunit/harmony/destructuring-assignment.js |
diff --git a/test/mjsunit/harmony/destructuring-assignment.js b/test/mjsunit/harmony/destructuring-assignment.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9391dd38005824cebcb5511369e7c43db2eaea8a |
--- /dev/null |
+++ b/test/mjsunit/harmony/destructuring-assignment.js |
@@ -0,0 +1,138 @@ |
+// Copyright 2015 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Flags: --harmony-destructuring-assignment --harmony-destructuring |
+ |
+// script-level tests |
+var ox, oy = {}, oz; |
+({ |
+ x: ox, |
+ y: oy.value, |
+ y2: oy["value2"], |
+ z: ({ set v(val) { oz = val; } }).v |
+} = { |
+ x: "value of x", |
+ y: "value of y1", |
+ y2: "value of y2", |
+ z: "value of z" |
+}); |
+assertEquals("value of x", ox); |
+assertEquals("value of y1", oy.value); |
+assertEquals("value of y2", oy.value2); |
+assertEquals("value of z", oz); |
+ |
+[ox, oy.value, oy["value2"], ...{ set v(val) { oz = val; } }.v] = [ |
+ 1007, |
+ 798432, |
+ 555, |
+ 1, 2, 3, 4, 5 |
+]; |
+assertEquals(ox, 1007); |
+assertEquals(oy.value, 798432); |
+assertEquals(oy.value2, 555); |
+assertEquals(oz, [1, 2, 3, 4, 5]); |
+ |
+ |
+(function testInFunction() { |
+ var x, y = {}, z; |
+ ({ |
+ x: x, |
+ y: y.value, |
+ y2: y["value2"], |
+ z: ({ set v(val) { z = val; } }).v |
+ } = { |
+ x: "value of x", |
+ y: "value of y1", |
+ y2: "value of y2", |
+ z: "value of z" |
+ }); |
+ assertEquals("value of x", x); |
+ assertEquals("value of y1", y.value); |
+ assertEquals("value of y2", y.value2); |
+ assertEquals("value of z", z); |
+ |
+ [x, y.value, y["value2"], ...{ set v(val) { z = val; } }.v] = [ |
+ 1007, |
+ 798432, |
+ 555, |
+ 1, 2, 3, 4, 5 |
+ ]; |
+ assertEquals(x, 1007); |
+ assertEquals(y.value, 798432); |
+ assertEquals(y.value2, 555); |
+ assertEquals(z, [1, 2, 3, 4, 5]); |
+})(); |
+ |
+ |
+(function testArrowFunctionInitializers() { |
+ var fn = (config = { value: defaults.value } = { value: "BLAH" }) => config; |
+ var defaults = {}; |
+ assertEquals({ value: "BLAH" }, fn()); |
+ assertEquals("BLAH", defaults.value); |
+})(); |
+ |
+ |
+(function testArrowFunctionInitializers2() { |
+ var fn = (config = [defaults.value] = ["BLAH"]) => config; |
+ var defaults = {}; |
+ assertEquals(["BLAH"], fn()); |
+ assertEquals("BLAH", defaults.value); |
+})(); |
+ |
+ |
+(function testFunctionInitializers() { |
+ function fn(config = { value: defaults.value } = { value: "BLAH" }) { |
+ return config; |
+ } |
+ var defaults = {}; |
+ assertEquals({ value: "BLAH" }, fn()); |
+ assertEquals("BLAH", defaults.value); |
+})(); |
+ |
+ |
+(function testFunctionInitializers2() { |
+ function fn(config = [defaults.value] = ["BLAH"]) { return config; } |
+ var defaults = {}; |
+ assertEquals(["BLAH"], fn()); |
+ assertEquals("BLAH", defaults.value); |
+})(); |
+ |
+ |
+(function testDeclarationInitializers() { |
+ var defaults = {}; |
+ var { value } = { value: defaults.value } = { value: "BLAH" }; |
+ assertEquals("BLAH", value); |
+ assertEquals("BLAH", defaults.value); |
+})(); |
+ |
+ |
+(function testDeclarationInitializers2() { |
+ var defaults = {}; |
+ var [value] = [defaults.value] = ["BLAH"]; |
+ assertEquals("BLAH", value); |
+ assertEquals("BLAH", defaults.value); |
+})(); |
+ |
+ |
+(function testObjectLiteralProperty() { |
+ var ext = {}; |
+ var obj = { |
+ a: { b: ext.b, c: ext["c"], d: { set v(val) { ext.d = val; } }.v } = { |
+ b: "b", c: "c", d: "d" } |
+ }; |
+ assertEquals({ b: "b", c: "c", d: "d" }, ext); |
+ assertEquals({ a: { b: "b", c: "c", d: "d" } }, obj); |
+})(); |
+ |
+ |
+(function testArrayLiteralProperty() { |
+ var ext = {}; |
+ var obj = [ |
+ ...[ ext.b, ext["c"], { set v(val) { ext.d = val; } }.v ] = [ |
+ "b", "c", "d" ] |
+ ]; |
+ assertEquals({ b: "b", c: "c", d: "d" }, ext); |
+ assertEquals([ "b", "c", "d" ], obj); |
+})(); |
+ |