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