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

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

Issue 2606833002: [ESnext] Implement Object spread (Closed)
Patch Set: fix test 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') | 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 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-spread
6
7 var x = {a: 1};
8 var y = { ...x};
9 assertEquals(x, y);
10
11 assertEquals({}, y = { ...{} } );
12 assertEquals({}, y = { ...undefined });
13 assertEquals({}, y = { ...null });
14
15 assertEquals({}, y = { ...1 });
16 assertEquals({0: 'f', 1: 'o', 2: 'o'}, y = { ...'foo' });
17 assertEquals({0: 0, 1: 1}, y = { ...[0, 1] });
18 assertEquals({}, { ...new Proxy({}, {}) });
19
20 assertEquals({a: 2}, y = { ...x, a: 2 });
21 assertEquals({a: 1, b: 1}, y = { ...x, b: 1 });
22 assertEquals({a: 1}, y = { a: 2, ...x });
23 assertEquals({a: 1, b: 1}, y = { a:2, ...x, b: 1 });
24 assertEquals({a: 3}, y = { a: 2, ...x, a: 3 });
25
26 var z = { b: 1}
27 assertEquals({a: 1, b: 1}, y = { ...x, ...z });
28 assertEquals({a: 1, b: 1}, y = { a: 2, ...x, ...z });
29 assertEquals({a: 1, b: 1}, y = { b: 2, ...z, ...x });
30 assertEquals({a: 1, b: 1}, y = { a: 1, ...x, b: 2, ...z });
31 assertEquals({a: 1, b: 2}, y = { a: 1, ...x, ...z, b: 2 });
32 assertEquals({a: 2, b: 2}, y = { ...x, ...z, a:2, b: 2 });
33
34 var x = {}
35 Object.defineProperty(x, 'a', {
36 enumerable: false,
37 configurable: false,
38 writable: false,
39 value: 1
40 });
41 assertEquals({}, { ...x });
42
43 var x = {}
44 Object.defineProperty(x, 'a', {
45 enumerable: true,
46 configurable: false,
47 writable: false,
48 value: 1
49 });
50 var y = { ...x };
51 var prop = Object.getOwnPropertyDescriptor(y, 'a');
52 assertEquals(prop.value, 1);
53 assertTrue(prop.enumerable);
54 assertTrue(prop.configurable);
55 assertTrue(prop.writable);
56
57 var x = { __proto__: z }
58 assertEquals({}, { ...x });
59
60 var x = {
61 get a() { return 1; },
62 set a(_) { assertUnreachable("setter called"); },
63 };
64 assertEquals({ a: 1 }, y = { ...x });
65
66 var x = {
67 method() { return 1; },
68 };
69 assertEquals(x, y = { ...x });
70
71 var x = {
72 *gen() { return {value: 1, done: true} ; },
73 };
74 assertEquals(x, y = { ...x });
75
76 var x = {
77 get a() { throw new Error(); },
78 };
79 assertThrows(() => { y = { ...x } });
80
81 var p = new Proxy({}, {
82 ownKeys() { throw new Error(); }
83 });
84 assertThrows(() => { y = { ...p } });
85
86 var p = new Proxy({}, {
87 ownKeys() { [1]; },
88 get() { throw new Error(); }
89 });
90 assertThrows(() => { y = { ...p } });
91
92 var p = new Proxy({}, {
93 ownKeys() { [1]; },
94 getOwnPropertyDescriptor() { throw new Error(); }
95 });
96 assertThrows(() => { y = { ...p } });
97
98 var p = new Proxy(z, {
99 ownKeys() { return Object.keys(z); },
100 get(_, prop) { return z[prop]; },
101 getOwnPropertyDescriptor(_, prop) {
102 return Object.getOwnPropertyDescriptor(z, prop);
103 },
104 });
105 assertEquals(z, y = { ...p });
106
107 var x = { a:1 };
108 assertEquals(x, y = { set a(_) { throw new Error(); }, ...x });
109
110 var x = { a:1 };
111 assertEquals(x, y = { get a() { throw new Error(); }, ...x });
OLDNEW
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698