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

Side by Side 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 unified diff | Download patch
« src/preparser.h ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --harmony-destructuring-assignment --harmony-destructuring
6
7 // script-level tests
8 var ox, oy = {}, oz;
9 ({
10 x: ox,
11 y: oy.value,
12 y2: oy["value2"],
13 z: ({ set v(val) { oz = val; } }).v
14 } = {
15 x: "value of x",
16 y: "value of y1",
17 y2: "value of y2",
18 z: "value of z"
19 });
20 assertEquals("value of x", ox);
21 assertEquals("value of y1", oy.value);
22 assertEquals("value of y2", oy.value2);
23 assertEquals("value of z", oz);
24
25 [ox, oy.value, oy["value2"], ...{ set v(val) { oz = val; } }.v] = [
26 1007,
27 798432,
28 555,
29 1, 2, 3, 4, 5
30 ];
31 assertEquals(ox, 1007);
32 assertEquals(oy.value, 798432);
33 assertEquals(oy.value2, 555);
34 assertEquals(oz, [1, 2, 3, 4, 5]);
35
36
37 (function testInFunction() {
38 var x, y = {}, z;
39 ({
40 x: x,
41 y: y.value,
42 y2: y["value2"],
43 z: ({ set v(val) { z = val; } }).v
44 } = {
45 x: "value of x",
46 y: "value of y1",
47 y2: "value of y2",
48 z: "value of z"
49 });
50 assertEquals("value of x", x);
51 assertEquals("value of y1", y.value);
52 assertEquals("value of y2", y.value2);
53 assertEquals("value of z", z);
54
55 [x, y.value, y["value2"], ...{ set v(val) { z = val; } }.v] = [
56 1007,
57 798432,
58 555,
59 1, 2, 3, 4, 5
60 ];
61 assertEquals(x, 1007);
62 assertEquals(y.value, 798432);
63 assertEquals(y.value2, 555);
64 assertEquals(z, [1, 2, 3, 4, 5]);
65 })();
66
67
68 (function testArrowFunctionInitializers() {
69 var fn = (config = { value: defaults.value } = { value: "BLAH" }) => config;
70 var defaults = {};
71 assertEquals({ value: "BLAH" }, fn());
72 assertEquals("BLAH", defaults.value);
73 })();
74
75
76 (function testArrowFunctionInitializers2() {
77 var fn = (config = [defaults.value] = ["BLAH"]) => config;
78 var defaults = {};
79 assertEquals(["BLAH"], fn());
80 assertEquals("BLAH", defaults.value);
81 })();
82
83
84 (function testFunctionInitializers() {
85 function fn(config = { value: defaults.value } = { value: "BLAH" }) {
86 return config;
87 }
88 var defaults = {};
89 assertEquals({ value: "BLAH" }, fn());
90 assertEquals("BLAH", defaults.value);
91 })();
92
93
94 (function testFunctionInitializers2() {
95 function fn(config = [defaults.value] = ["BLAH"]) { return config; }
96 var defaults = {};
97 assertEquals(["BLAH"], fn());
98 assertEquals("BLAH", defaults.value);
99 })();
100
101
102 (function testDeclarationInitializers() {
103 var defaults = {};
104 var { value } = { value: defaults.value } = { value: "BLAH" };
105 assertEquals("BLAH", value);
106 assertEquals("BLAH", defaults.value);
107 })();
108
109
110 (function testDeclarationInitializers2() {
111 var defaults = {};
112 var [value] = [defaults.value] = ["BLAH"];
113 assertEquals("BLAH", value);
114 assertEquals("BLAH", defaults.value);
115 })();
116
117
118 (function testObjectLiteralProperty() {
119 var ext = {};
120 var obj = {
121 a: { b: ext.b, c: ext["c"], d: { set v(val) { ext.d = val; } }.v } = {
122 b: "b", c: "c", d: "d" }
123 };
124 assertEquals({ b: "b", c: "c", d: "d" }, ext);
125 assertEquals({ a: { b: "b", c: "c", d: "d" } }, obj);
126 })();
127
128
129 (function testArrayLiteralProperty() {
130 var ext = {};
131 var obj = [
132 ...[ ext.b, ext["c"], { set v(val) { ext.d = val; } }.v ] = [
133 "b", "c", "d" ]
134 ];
135 assertEquals({ b: "b", c: "c", d: "d" }, ext);
136 assertEquals([ "b", "c", "d" ], obj);
137 })();
138
OLDNEW
« 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