OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 // | |
5 // Flags: --harmony-destructuring --harmony-default-parameters | |
6 | |
7 (function testExpressionTypes() { | |
8 "use strict"; | |
9 ((x, y = x) => assertEquals(42, y))(42); | |
10 | |
11 ((x, y = (x)) => assertEquals(42, y))(42); | |
12 ((x, y = `${x}`) => assertEquals("42", y))(42); | |
13 ((x, y = x = x + 1) => assertEquals(43, y))(42); | |
14 ((x, y = x()) => assertEquals(42, y))(() => 42); | |
15 ((x, y = new x()) => assertEquals(42, y.z))(function() { this.z = 42 }); | |
16 ((x, y = -x) => assertEquals(-42, y))(42); | |
17 ((x, y = ++x) => assertEquals(43, y))(42); | |
18 ((x, y = x === 42) => assertTrue(y))(42); | |
19 ((x, y = (x == 42 ? x : 0)) => assertEquals(42, y))(42); | |
20 | |
21 ((x, y = function() { return x }) => assertEquals(42, y()))(42); | |
22 ((x, y = () => x) => assertEquals(42, y()))(42); | |
23 | |
24 // Literals | |
25 ((x, y = {z: x}) => assertEquals(42, y.z))(42); | |
26 ((x, y = {[x]: x}) => assertEquals(42, y[42]))(42); | |
27 ((x, y = [x]) => assertEquals(42, y[0]))(42); | |
28 ((x, y = [...x]) => assertEquals(42, y[0]))([42]); | |
29 | |
30 ((x, y = class { | |
31 static [x]() { return x } | |
32 }) => assertEquals(42, y[42]()))(42); | |
33 ((x, y = (new class { | |
34 z() { return x } | |
35 })) => assertEquals(42, y.z()))(42); | |
36 | |
37 // Scope chain of named class literals is busted | |
38 //((x, y = (new class Y { | |
39 // static [x]() { return x } | |
40 // z() { return Y[42] } | |
41 //})) => assertEquals(42, y.z()))(42); | |
42 | |
43 // Defaults inside destructuring | |
44 ((x, {y = x}) => assertEquals(42, y))(42, {}); | |
45 ((x, [y = x]) => assertEquals(42, y))(42, []); | |
46 })(); | |
47 | |
48 (function testMultiScopeCapture() { | |
49 "use strict"; | |
50 var x = 1; | |
51 { | |
52 let y = 2; | |
53 ((x, y, a = x, b = y) => { | |
54 assertEquals(x, a); | |
55 assertEquals(y, b); | |
56 })(3, 4); | |
rossberg
2015/10/16 11:55:41
Perhaps also return x and y and verify on the outs
adamk
2015/10/16 13:38:28
Done (though I just put the test inside the functi
| |
57 } | |
58 })(); | |
OLD | NEW |