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: --expose-debug-as debug --harmony-destructuring-assignment
6// Flags: --harmony-destructuring-bind
7
8var exception = null;
9var Debug = debug.Debug;
10var break_count = 0;
11
12function listener(event, exec_state, event_data, data) {
13  if (event != Debug.DebugEvent.Break) return;
14  try {
15    var source = exec_state.frame(0).sourceLineText();
16    print(source);
17    assertTrue(source.indexOf(`// B${break_count++}`) > 0);
18    if (source.indexOf("assertEquals") > 0) {
19      exec_state.prepareStep(Debug.StepAction.StepNext);
20    } else {
21      exec_state.prepareStep(Debug.StepAction.StepIn);
22    }
23  } catch (e) {
24    exception = e;
25    print(e);
26  }
27};
28
29Debug.setListener(listener);
30
31function f() {
32  var a, b, c, d;
33  debugger;                                       // B0
34  [                                               // B1
35    a,                                            // B3
36    b,                                            // B4
37    c = 3                                         // B5
38  ] = [1, 2];                                     // B2
39  assertEquals({a:1,b:2,c:3}, {a, b, c});         // B6
40
41  [                                               // B7
42    a,                                            // B9
43    [
44      b,                                          // B10
45      c                                           // B11
46    ],
47    d                                             // B12
48  ] = [5, [6, 7], 8];                             // B8
49  assertEquals({a:5,b:6,c:7,d:8}, {a, b, c, d});  // B13
50
51  [                                               // B14
52    a,                                            // B16
53    b,                                            // B17
54    ...c                                          // B18
55  ] = [1, 2, 3, 4];                               // B15
56  assertEquals({a:1,b:2,c:[3,4]}, {a, b, c});     // B19
57
58  ({                                              // B20
59    a,                                            // B22
60    b,                                            // B23
61    c = 7                                         // B24
62  } = {a: 5, b: 6});                              // B21
63  assertEquals({a:5,b:6,c:7}, {a, b, c});         // B25
64
65  ({                                              // B26
66    a,                                            // B28
67    b = return1(),                                // B29
68    c = return1()                                 // B30
69  } = {a: 5, b: 6});                              // B27
70  assertEquals({a:5,b:6,c:1}, {a, b, c});         // B33
71
72  ({                                              // B34
73    x : a,                                        // B36
74    y : b,                                        // B37
75    z : c = 3                                     // B38
76  } = {x: 1, y: 2});                              // B35
77  assertEquals({a:1,b:2,c:3}, {a, b, c});         // B39
78}                                                 // B40
79
80function return1() {
81  return 1;                                       // B31
82}                                                 // B32
83
84f();
85Debug.setListener(null);                          // B41
86assertNull(exception);
87