| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --expose-debug-as debug | 5 // Flags: --expose-debug-as debug |
| 6 | 6 |
| 7 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 var Debug = debug.Debug | 9 var Debug = debug.Debug |
| 10 var done, stepCount; | 10 var done, stepCount; |
| 11 var exception = null; |
| 11 | 12 |
| 12 function listener(event, execState, eventData, data) { | 13 function listener(event, execState, eventData, data) { |
| 13 if (event == Debug.DebugEvent.Break) { | 14 if (event != Debug.DebugEvent.Break) return; |
| 15 try { |
| 14 if (!done) { | 16 if (!done) { |
| 15 execState.prepareStep(Debug.StepAction.StepIn); | 17 execState.prepareStep(Debug.StepAction.StepIn); |
| 16 var s = execState.frame().sourceLineText(); | 18 var s = execState.frame().sourceLineText(); |
| 17 assertTrue(s.indexOf('// ' + stepCount + '.') !== -1); | 19 assertTrue(s.indexOf('// ' + stepCount + '.') !== -1); |
| 18 stepCount++; | 20 stepCount++; |
| 19 } | 21 } |
| 22 } catch (e) { |
| 23 exception = e; |
| 20 } | 24 } |
| 21 }; | 25 }; |
| 22 | 26 |
| 23 Debug.setListener(listener); | 27 Debug.setListener(listener); |
| 24 | 28 |
| 25 | 29 |
| 26 class Base { | 30 class Base { |
| 27 constructor() { // 1. | 31 constructor() { |
| 28 var x = 1; // 2. | 32 var x = 1; // 1. |
| 29 var y = 2; // 3. | 33 var y = 2; // 2. |
| 30 done = true; // 4. | 34 done = true; // 3. |
| 31 } | 35 } |
| 32 } | 36 } |
| 33 | 37 |
| 34 class Derived extends Base {} | 38 class Derived extends Base {} // 0. |
| 35 | 39 |
| 36 | 40 |
| 37 (function TestBreakPointInConstructor() { | 41 (function TestBreakPointInConstructor() { |
| 38 done = false; | 42 done = false; |
| 39 stepCount = 1; | 43 stepCount = 1; |
| 40 var bp = Debug.setBreakPoint(Base, 0); | 44 var bp = Debug.setBreakPoint(Base, 0); |
| 41 | 45 |
| 42 new Base(); | 46 new Base(); |
| 43 assertEquals(1, stepCount); | 47 assertEquals(4, stepCount); |
| 44 | 48 |
| 45 Debug.clearBreakPoint(bp); | 49 Debug.clearBreakPoint(bp); |
| 46 })(); | 50 })(); |
| 47 | 51 |
| 48 | 52 |
| 49 (function TestDefaultConstructor() { | 53 (function TestDefaultConstructor() { |
| 50 done = false; | 54 done = false; |
| 51 stepCount = 1; | 55 stepCount = 1; |
| 52 | 56 |
| 53 var bp = Debug.setBreakPoint(Base, 0); | 57 var bp = Debug.setBreakPoint(Base, 0); |
| 54 new Derived(); | 58 new Derived(); |
| 55 assertEquals(1, stepCount); | 59 assertEquals(4, stepCount); |
| 56 | 60 |
| 57 Debug.clearBreakPoint(bp); | 61 Debug.clearBreakPoint(bp); |
| 58 })(); | 62 })(); |
| 59 | 63 |
| 60 | 64 |
| 61 (function TestStepInto() { | 65 (function TestStepInto() { |
| 62 done = false; | 66 done = false; |
| 63 stepCount = 0; | 67 stepCount = -1; |
| 64 | 68 |
| 65 function f() { | 69 function f() { |
| 66 new Derived(); // 0. | 70 new Derived(); // -1. |
| 67 } | 71 } |
| 68 | 72 |
| 69 var bp = Debug.setBreakPoint(f, 0); | 73 var bp = Debug.setBreakPoint(f, 0); |
| 70 f(); | 74 f(); |
| 71 assertEquals(1, stepCount); | 75 assertEquals(4, stepCount); |
| 72 | 76 |
| 73 Debug.clearBreakPoint(bp); | 77 Debug.clearBreakPoint(bp); |
| 74 })(); | 78 })(); |
| 75 | 79 |
| 76 | 80 |
| 77 (function TestExtraIndirection() { | 81 (function TestExtraIndirection() { |
| 78 done = false; | 82 done = false; |
| 79 stepCount = 0; | 83 stepCount = -2; |
| 80 | 84 |
| 81 class Derived2 extends Derived {} | 85 class Derived2 extends Derived {} // -1. |
| 82 | 86 |
| 83 function f() { | 87 function f() { |
| 84 new Derived2(); // 0. | 88 new Derived2(); // -2. |
| 85 } | 89 } |
| 86 | 90 |
| 87 var bp = Debug.setBreakPoint(f, 0); | 91 var bp = Debug.setBreakPoint(f, 0); |
| 88 f(); | 92 f(); |
| 89 assertEquals(1, stepCount); | 93 assertEquals(4, stepCount); |
| 90 | 94 |
| 91 Debug.clearBreakPoint(bp); | 95 Debug.clearBreakPoint(bp); |
| 92 })(); | 96 })(); |
| 93 | 97 |
| 94 | 98 |
| 95 (function TestBoundClass() { | 99 (function TestBoundClass() { |
| 96 done = false; | 100 done = false; |
| 97 stepCount = 0; | 101 stepCount = -1; |
| 98 | 102 |
| 99 var bound = Derived.bind(null); | 103 var bound = Derived.bind(null); |
| 100 | 104 |
| 101 function f() { | 105 function f() { |
| 102 new bound(); // 0. | 106 new bound(); // -1. |
| 103 } | 107 } |
| 104 | 108 |
| 105 var bp = Debug.setBreakPoint(f, 0); | 109 var bp = Debug.setBreakPoint(f, 0); |
| 106 f(); | 110 f(); |
| 107 assertEquals(1, stepCount); | 111 assertEquals(4, stepCount); |
| 108 | 112 |
| 109 Debug.clearBreakPoint(bp); | 113 Debug.clearBreakPoint(bp); |
| 110 })(); | 114 })(); |
| 111 | 115 |
| 112 | 116 |
| 113 Debug.setListener(null); | 117 Debug.setListener(null); |
| 118 assertNull(exception); |
| OLD | NEW |