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

Side by Side Diff: test/mjsunit/harmony/object-rest-basic.js

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: fix nits Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | test/mjsunit/harmony/object-spread-basic.js » ('j') | 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 2016 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-object-rest-spread
6 var { ...x } = { a: 1 };
7 assertEquals({ a: 1 }, x);
8
9 var { ...x } = { a: 1, b: 1 };
10 assertEquals({ a: 1, b: 1 }, x);
11
12 var { x, ...x } = { a: 1, b: 1 };
13 assertEquals({ a: 1, b: 1 }, x);
14
15 var { x = {}, ...x } = { a: 1, b: 1 };
16 assertEquals({ a: 1, b: 1 }, x);
17
18 var { y, ...x } = { y: 1, a: 1 };
19 assertEquals({ a: 1 }, x);
20 assertEquals(1, y);
21
22 var { z, y, ...x } = { z:1, y: 1, a: 1, b: 1 };
23 assertEquals({ a: 1, b:1 }, x);
24 assertEquals(1, y);
25 assertEquals(1, z);
26
27 ({ a, ...b } = { a: 1, b: 2 });
28 assertEquals(1, a);
29 assertEquals({ b: 2 }, b);
30
31 var { ...x } = {};
32 assertEquals({}, x);
33
34 var key = "b";
35 var { [key]: y, ...x } = { b: 1, a: 1 };
36 assertEquals({ a: 1 }, x);
37 assertEquals(1, y);
38
39 var key = 1;
40 var { [key++]: y, ...x } = { 1: 1, a: 1 };
41 assertEquals({ a: 1 }, x);
42 assertEquals(key, 2);
43 assertEquals(1, y);
44
45 function example({a, ...rest}, { b = rest }) {
46 assertEquals(1, a);
47 assertEquals({ b: 2, c: 3}, rest);
48 assertEquals({ b: 2, c: 3}, b);
49 };
50 example({ a: 1, b: 2, c: 3}, { b: undefined });
51
52 var x = { a: 3 };
53 var y = {
54 set a(val) { assertUnreachable(); },
55 ...x,
56 };
57 assertEquals(y.a, 3);
58
59 var x = {
60 get a() { throw new Error(); },
61 };
62 assertThrows(() => { var { ...y } = x });
63
64 var p = new Proxy({}, {
65 ownKeys() { throw new Error(); }
66 });
67 assertThrows(() => { var { ...y } = p });
68
69 var p = new Proxy({}, {
70 ownKeys() { [1]; },
71 get() { throw new Error(); }
72 });
73 assertThrows(() => { var { ...y } = p });
74
75 var p = new Proxy({}, {
76 ownKeys() { [1]; },
77 getOwnPropertyDescriptor() { throw new Error(); }
78 });
79 assertThrows(() => { var { ...y } = p });
80
81 var z = { b: 1}
82 var p = new Proxy(z, {
83 ownKeys() { return Object.keys(z); },
84 get(_, prop) { return z[prop]; },
85 getOwnPropertyDescriptor(_, prop) {
86 return Object.getOwnPropertyDescriptor(z, prop);
87 },
88 });
89 var { ...y } = p ;
90 assertEquals(z, y);
91
92 var z = { b: 1}
93 var { ...y } = { ...z} ;
94 assertEquals(z, y);
95
96 var count = 0;
97 class Foo {
98 constructor(x) { this.x = x; }
99 toString() { count++; return this.x.toString(); }
100 }
101 var f = new Foo(1);
102 var { [f] : x, ...y } = { 1: 1, 2: 2}
103 assertEquals(1, count);
104 assertEquals({2: 2}, y);
105
106 var { 1: x, 2: y, ...z } = { 1: 1, 2: 2, 3:3 };
107 assertEquals(1, x);
108 assertEquals(2, y);
109 assertEquals({ 3: 3 }, z);
110
111 var { 1.5: x, 2: y, ...z } = { 1.5: 1, 2: 2, 3:3 };
112 assertEquals(1, x);
113 assertEquals(2, y);
114 assertEquals({ 3: 3 }, z);
115
116 (({x, ...z}) => { assertEquals({y: 1}, z); })({ x: 1, y: 1});
117
118 var [...{...z}] = [{ x: 1}];
119 assertEquals({ 0: { x: 1} }, z);
120
121 var {...{x}} = { x: 1};
122 assertEquals(1, x);
OLDNEW
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | test/mjsunit/harmony/object-spread-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698