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

Side by Side Diff: test/mjsunit/harmony/computed-property-names.js

Issue 1273543002: Delete --harmony-computed-property-names flag (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 years, 4 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 2014 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-computed-property-names
6
7
8 function ID(x) {
9 return x;
10 }
11
12
13
14 (function TestBasicsString() {
15 var object = {
16 a: 'A',
17 ['b']: 'B',
18 c: 'C',
19 [ID('d')]: 'D',
20 };
21 assertEquals('A', object.a);
22 assertEquals('B', object.b);
23 assertEquals('C', object.c);
24 assertEquals('D', object.d);
25 assertArrayEquals(['a', 'b', 'c', 'd'], Object.keys(object));
26 })();
27
28
29 (function TestBasicsNumber() {
30 var object = {
31 a: 'A',
32 [1]: 'B',
33 c: 'C',
34 [ID(2)]: 'D',
35 };
36 assertEquals('A', object.a);
37 assertEquals('B', object[1]);
38 assertEquals('C', object.c);
39 assertEquals('D', object[2]);
40 // Array indexes first.
41 assertArrayEquals(['1', '2', 'a', 'c'], Object.keys(object));
42 })();
43
44
45 (function TestBasicsSymbol() {
46 var sym1 = Symbol();
47 var sym2 = Symbol();
48 var object = {
49 a: 'A',
50 [sym1]: 'B',
51 c: 'C',
52 [ID(sym2)]: 'D',
53 };
54 assertEquals('A', object.a);
55 assertEquals('B', object[sym1]);
56 assertEquals('C', object.c);
57 assertEquals('D', object[sym2]);
58 assertArrayEquals(['a', 'c'], Object.keys(object));
59 assertArrayEquals([sym1, sym2], Object.getOwnPropertySymbols(object));
60 })();
61
62
63 (function TestToNameSideEffects() {
64 var counter = 0;
65 var key1 = {
66 toString: function() {
67 assertEquals(0, counter++);
68 return 'b';
69 }
70 };
71 var key2 = {
72 toString: function() {
73 assertEquals(1, counter++);
74 return 'd';
75 }
76 };
77 var object = {
78 a: 'A',
79 [key1]: 'B',
80 c: 'C',
81 [key2]: 'D',
82 };
83 assertEquals(2, counter);
84 assertEquals('A', object.a);
85 assertEquals('B', object.b);
86 assertEquals('C', object.c);
87 assertEquals('D', object.d);
88 assertArrayEquals(['a', 'b', 'c', 'd'], Object.keys(object));
89 })();
90
91
92 (function TestToNameSideEffectsNumbers() {
93 var counter = 0;
94 var key1 = {
95 valueOf: function() {
96 assertEquals(0, counter++);
97 return 1;
98 },
99 toString: null
100 };
101 var key2 = {
102 valueOf: function() {
103 assertEquals(1, counter++);
104 return 2;
105 },
106 toString: null
107 };
108
109 var object = {
110 a: 'A',
111 [key1]: 'B',
112 c: 'C',
113 [key2]: 'D',
114 };
115 assertEquals(2, counter);
116 assertEquals('A', object.a);
117 assertEquals('B', object[1]);
118 assertEquals('C', object.c);
119 assertEquals('D', object[2]);
120 // Array indexes first.
121 assertArrayEquals(['1', '2', 'a', 'c'], Object.keys(object));
122 })();
123
124
125 (function TestDoubleName() {
126 var object = {
127 [1.2]: 'A',
128 [1e55]: 'B',
129 [0.000001]: 'C',
130 [-0]: 'D',
131 // TODO(arv): https://code.google.com/p/v8/issues/detail?id=3815
132 // [Infinity]: 'E',
133 // [-Infinity]: 'F',
134 [NaN]: 'G',
135 };
136 assertEquals('A', object['1.2']);
137 assertEquals('B', object['1e+55']);
138 assertEquals('C', object['0.000001']);
139 assertEquals('D', object[0]);
140 // TODO(arv): https://code.google.com/p/v8/issues/detail?id=3815
141 // assertEquals('E', object[Infinity]);
142 // assertEquals('F', object[-Infinity]);
143 assertEquals('G', object[NaN]);
144 })();
145
146
147 (function TestGetter() {
148 var object = {
149 get ['a']() {
150 return 'A';
151 }
152 };
153 assertEquals('A', object.a);
154
155 object = {
156 get b() {
157 assertUnreachable();
158 },
159 get ['b']() {
160 return 'B';
161 }
162 };
163 assertEquals('B', object.b);
164
165 object = {
166 get c() {
167 assertUnreachable();
168 },
169 get ['c']() {
170 assertUnreachable();
171 },
172 get ['c']() {
173 return 'C';
174 }
175 };
176 assertEquals('C', object.c);
177
178 object = {
179 get ['d']() {
180 assertUnreachable();
181 },
182 get d() {
183 return 'D';
184 }
185 };
186 assertEquals('D', object.d);
187 })();
188
189
190 (function TestSetter() {
191 var calls = 0;
192 var object = {
193 set ['a'](_) {
194 calls++;
195 }
196 };
197 object.a = 'A';
198 assertEquals(1, calls);
199
200 calls = 0;
201 object = {
202 set b(_) {
203 assertUnreachable();
204 },
205 set ['b'](_) {
206 calls++;
207 }
208 };
209 object.b = 'B';
210 assertEquals(1, calls);
211
212 calls = 0;
213 object = {
214 set c(_) {
215 assertUnreachable()
216 },
217 set ['c'](_) {
218 assertUnreachable()
219 },
220 set ['c'](_) {
221 calls++
222 }
223 };
224 object.c = 'C';
225 assertEquals(1, calls);
226
227 calls = 0;
228 object = {
229 set ['d'](_) {
230 assertUnreachable()
231 },
232 set d(_) {
233 calls++
234 }
235 };
236 object.d = 'D';
237 assertEquals(1, calls);
238 })();
239
240
241 (function TestDuplicateKeys() {
242 'use strict';
243 // ES5 does not allow duplicate keys.
244 // ES6 does but we haven't changed our code yet.
245
246 var object = {
247 a: 1,
248 ['a']: 2,
249 };
250 assertEquals(2, object.a);
251 })();
252
253
254 (function TestProto() {
255 var proto = {};
256 var object = {
257 __proto__: proto
258 };
259 assertEquals(proto, Object.getPrototypeOf(object));
260
261 object = {
262 '__proto__': proto
263 };
264 assertEquals(proto, Object.getPrototypeOf(object));
265
266 object = {
267 ['__proto__']: proto
268 };
269 assertEquals(Object.prototype, Object.getPrototypeOf(object));
270 assertEquals(proto, object.__proto__);
271 assertTrue(object.hasOwnProperty('__proto__'));
272
273 object = {
274 [ID('x')]: 'X',
275 __proto__: proto
276 };
277 assertEquals('X', object.x);
278 assertEquals(proto, Object.getPrototypeOf(object));
279 })();
280
281
282 (function TestExceptionInName() {
283 function MyError() {};
284 function throwMyError() {
285 throw new MyError();
286 }
287 assertThrows(function() {
288 var o = {
289 [throwMyError()]: 42
290 };
291 }, MyError);
292 assertThrows(function() {
293 var o = {
294 get [throwMyError()]() { return 42; }
295 };
296 }, MyError);
297 assertThrows(function() {
298 var o = {
299 set [throwMyError()](_) { }
300 };
301 }, MyError);
302 })();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/class-computed-property-names-super.js ('k') | test/mjsunit/harmony/computed-property-names-classes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698