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

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

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: Remove comment 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
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 { y, ...x } = { y: 1, a: 1 };
13 assertEquals({ a: 1 }, x);
14 assertEquals(1, y);
15
16 ({ a, ...b } = { a: 1, b: 2 });
17 assertEquals(1, a);
18 assertEquals({ b: 2 }, b);
19
20 var { ...x } = {};
21 assertEquals({}, x);
22
23 var key = "b";
24 var { [key]: y, ...x } = { b: 1, a: 1 };
25 assertEquals({ a: 1 }, x);
26 assertEquals(1, y);
27
28 var key = 1;
29 var { [key++]: y, ...x } = { 1: 1, a: 1 };
30 assertEquals({ a: 1 }, x);
31 assertEquals(key, 2);
32 assertEquals(1, y);
33
34 function example({a, ...rest}, { b = rest }) {
35 assertEquals(1, a);
36 assertEquals({ b: 2, c: 3}, rest);
37 assertEquals({ b: 2, c: 3}, b);
38 };
39 example({ a: 1, b: 2, c: 3}, { b: undefined });
40
41 var x = { a: 3 };
42 var y = {
43 set a(val) { assertUnreachable(); },
44 ...x,
45 };
46 assertEquals(y.a, 3);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698