Home | History | Annotate | Download | only in harmony
      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-bind
      6 
      7 var exception = null;
      8 var Debug = debug.Debug;
      9 var break_count = 0;
     10 
     11 function 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, break_count);
     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 
     28 Debug.setListener(listener);
     29 
     30 var id = x => x;                                  // B9 B10 B36 B37
     31 
     32 function test() {
     33   debugger;                                       // B0
     34   function fx1([
     35                 a,                                // B2
     36                 b                                 // B3
     37               ]) {
     38     assertEquals([1, 2], [a, b]);                 // B4
     39   }                                               // B5
     40   fx1([1, 2, 3]);                                 // B1
     41 
     42   function f2([
     43                 a,                                // B7
     44                 b = id(3)                         // B8
     45               ]) {
     46     assertEquals([4, 3], [a, b]);                 // B11
     47   }                                               // B12
     48   f2([4]);                                        // B6
     49 
     50   function f3({
     51                 x: a,                             // B14
     52                 y: b                              // B15
     53               }) {
     54     assertEquals([5, 6], [a, b]);                 // B16
     55   }                                               // B17
     56   f3({y: 6, x: 5});                               // B13
     57 
     58   function f4([
     59                 a,                                // B19
     60                 {
     61                   b,                              // B20
     62                   c,                              // B21
     63                 }
     64               ]) {
     65     assertEquals([2, 4, 6], [a, b, c]);           // B22
     66   }                                               // B23
     67   f4([2, {c: 6, b: 4}]);                          // B18
     68 
     69   function f5([
     70                 {
     71                   a,                              // B25
     72                   b = 7                           // B26
     73                 },
     74                 c = 3                             // B27
     75               ] = [{a:1}]) {
     76     assertEquals([1, 7, 3], [a, b, c]);           // B28
     77   }                                               // B29
     78   f5();                                           // B24
     79 
     80   var name = "x";                                 // B30
     81   function f6({
     82                 [id(name)]: a,                    // B34 B35
     83                 b = a                             // B38
     84               }) {
     85     assertEquals([9, 9], [a, b]);                 // B39
     86   }                                               // B40
     87   var o6 = {};                                    // B31
     88   o6[name] = 9;                                   // B32
     89   f6(o6);                                         // B33
     90 
     91   try {
     92     throw [3, 4];                                 // B41
     93   } catch ([
     94              a,                                   // B42
     95              b,                                   // B43
     96              c = 6                                // B44
     97            ]) {
     98     assertEquals([3, 4, 6], [a, b, c]);           // B45
     99   }
    100 
    101   var {                                           // B46
    102     x: a,                                         // B47
    103     y: b = 9                                      // B48
    104   } = { x: 4 };
    105   assertEquals([4, 9], [a, b]);                   // B49
    106 }                                                 // B50
    107 
    108 test();
    109 Debug.setListener(null);                          // B51
    110 assertNull(exception);
    111