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

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

Issue 1309813007: [es6] implement destructuring assignment (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: An implementation Created 5 years, 1 month 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/preparser.h ('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-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);
+})();
+
« src/preparser.h ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698