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-bind --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  ((x, y = (new class Y {
38    static [x]() { return x }
39    z() { return Y[42]() }
40  })) => assertEquals(42, y.z()))(42);
41
42  ((x, y = (new class {
43    constructor() { this.z = x }
44  })) => assertEquals(42, y.z))(42);
45  ((x, y = (new class Y {
46    constructor() { this.z = x }
47  })) => assertEquals(42, y.z))(42);
48
49  ((x, y = (new class extends x {
50  })) => assertEquals(42, y.z()))(class { z() { return 42 } });
51
52  // Defaults inside destructuring
53  ((x, {y = x}) => assertEquals(42, y))(42, {});
54  ((x, [y = x]) => assertEquals(42, y))(42, []);
55})();
56
57
58(function testMultiScopeCapture() {
59  "use strict";
60  var x = 1;
61  {
62    let y = 2;
63    ((x, y, a = x, b = y) => {
64      assertEquals(3, x);
65      assertEquals(3, a);
66      assertEquals(4, y);
67      assertEquals(4, b);
68    })(3, 4);
69  }
70})();
71
72
73(function testSuper() {
74  "use strict";
75  class A {
76    x() { return 42; }
77  }
78
79  class B extends A {
80    y() {
81      ((q = super.x()) => assertEquals(42, q))();
82    }
83  }
84
85  new B().y();
86
87  class C {
88    constructor() { return { prop: 42 } }
89  }
90
91  class D extends C{
92    constructor() {
93      ((q = super()) => assertEquals(42, q.prop))();
94    }
95  }
96
97  new D();
98})();
99
100
101(function testScopeFlags() {
102  ((x, y = eval('x')) => assertEquals(42, y))(42);
103  ((x, {y = eval('x')}) => assertEquals(42, y))(42, {});
104})();
105