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

Side by Side Diff: test/mjsunit/harmony/destructuring.js

Issue 1129083009: [destructuring] Support computed property names in patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Patch for landing Created 5 years, 7 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
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Flags: --harmony-destructuring 5 // Flags: --harmony-destructuring --harmony-computed-property-names
6 6
7 (function TestObjectLiteralPattern() { 7 (function TestObjectLiteralPattern() {
8 var { x : x, y : y } = { x : 1, y : 2 }; 8 var { x : x, y : y } = { x : 1, y : 2 };
9 assertEquals(1, x); 9 assertEquals(1, x);
10 assertEquals(2, y); 10 assertEquals(2, y);
11 11
12 var {z} = { z : 3 }; 12 var {z} = { z : 3 };
13 assertEquals(3, z); 13 assertEquals(3, z);
14 14
15 15
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 }, ReferenceError); 276 }, ReferenceError);
277 277
278 (function() { 278 (function() {
279 'use strict'; 279 'use strict';
280 let {x = (function() { x = 2; }())} = {x:1}; 280 let {x = (function() { x = 2; }())} = {x:1};
281 assertSame(1, x); 281 assertSame(1, x);
282 }()); 282 }());
283 }()); 283 }());
284 284
285 285
286 (function TestComputedNames() {
287 var x = 1;
288 var {[x]:y} = {1:2};
289 assertSame(2, y);
290
291 (function(){
292 'use strict';
293 let {[x]:y} = {1:2};
294 assertSame(2, y);
295 }());
296
297 var callCount = 0;
298 function foo(v) { callCount++; return v; }
299
300 (function() {
301 callCount = 0;
302 var {[foo("abc")]:x} = {abc:42};
303 assertSame(42, x);
304 assertEquals(1, callCount);
305 }());
306
307 (function() {
308 'use strict';
309 callCount = 0;
310 let {[foo("abc")]:x} = {abc:42};
311 assertSame(42, x);
312 assertEquals(1, callCount);
313 }());
314
315 (function() {
316 callCount = 0;
317 var {[foo("abc")]:x} = {};
318 assertSame(undefined, x);
319 assertEquals(1, callCount);
320 }());
321
322 (function() {
323 'use strict';
324 callCount = 0;
325 let {[foo("abc")]:x} = {};
326 assertSame(undefined, x);
327 assertEquals(1, callCount);
328 }());
329
330 for (val of [null, undefined]) {
331 callCount = 0;
332 assertThrows(function() {
333 var {[foo()]:x} = val;
334 }, TypeError);
335 assertEquals(0, callCount);
336
337 callCount = 0;
338 assertThrows(function() {
339 'use strict';
340 let {[foo()]:x} = val;
341 }, TypeError);
342 assertEquals(0, callCount);
343 }
344
345 var log = [];
346 var o = {
347 get x() { log.push("get x"); return 1; },
348 get y() { log.push("get y"); return 2; }
349 }
350 function f(v) { log.push("f " + v); return v; }
351
352 (function() {
353 log = [];
354 var { [f('x')]:x, [f('y')]:y } = o;
355 assertSame(1, x);
356 assertSame(2, y);
357 assertArrayEquals(["f x", "get x", "f y", "get y"], log);
358 }());
359
360 (function() {
361 'use strict';
362 log = [];
363 let { [f('x')]:x, [f('y')]:y } = o;
364 assertSame(1, x);
365 assertSame(2, y);
366 assertArrayEquals(["f x", "get x", "f y", "get y"], log);
367 }());
368
369 (function() {
370 'use strict';
371 log = [];
372 const { [f('x')]:x, [f('y')]:y } = o;
373 assertSame(1, x);
374 assertSame(2, y);
375 assertArrayEquals(["f x", "get x", "f y", "get y"], log);
376 }());
377 }());
378
379
286 (function TestExceptions() { 380 (function TestExceptions() {
287 for (var val of [null, undefined]) { 381 for (var val of [null, undefined]) {
288 assertThrows(function() { var {} = val; }, TypeError); 382 assertThrows(function() { var {} = val; }, TypeError);
289 assertThrows(function() { var {x} = val; }, TypeError); 383 assertThrows(function() { var {x} = val; }, TypeError);
290 assertThrows(function() { var { x : {} } = { x : val }; }, TypeError); 384 assertThrows(function() { var { x : {} } = { x : val }; }, TypeError);
291 assertThrows(function() { 'use strict'; let {} = val; }, TypeError); 385 assertThrows(function() { 'use strict'; let {} = val; }, TypeError);
292 assertThrows(function() { 'use strict'; let {x} = val; }, TypeError); 386 assertThrows(function() { 'use strict'; let {x} = val; }, TypeError);
293 assertThrows(function() { 'use strict'; let { x : {} } = { x : val }; }, 387 assertThrows(function() { 'use strict'; let { x : {} } = { x : val }; },
294 TypeError); 388 TypeError);
295 } 389 }
296 }()); 390 }());
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