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 | 11 |
12 function listener(event, execState, eventData, data) { | 12 function listener(event, execState, eventData, data) { |
13 if (event == Debug.DebugEvent.Break) { | 13 if (event == Debug.DebugEvent.Break) { |
14 if (!done) { | 14 if (!done) { |
15 execState.prepareStep(Debug.StepAction.StepInto); | 15 execState.prepareStep(Debug.StepAction.StepInto); |
16 var s = execState.frame().sourceLineText(); | 16 var s = execState.frame().sourceLineText(); |
17 print(s); | |
18 assertTrue(s.indexOf('// ' + stepCount + '.') !== -1); | 17 assertTrue(s.indexOf('// ' + stepCount + '.') !== -1); |
19 stepCount++; | 18 stepCount++; |
20 } | 19 } |
21 } | 20 } |
22 }; | 21 }; |
23 | 22 |
24 Debug.setListener(listener); | 23 Debug.setListener(listener); |
25 | 24 |
26 | 25 |
27 class Base { | 26 class Base { |
28 constructor() { // 1. | 27 constructor() { // 1. |
29 var x = 1; // 2. | 28 var x = 1; // 2. |
30 var y = 2; // 3. | 29 var y = 2; // 3. |
31 done = true; // 4. | 30 done = true; // 4. |
32 } | 31 } |
33 } | 32 } |
34 | 33 |
35 class Derived extends Base {} | 34 class Derived extends Base {} |
36 | 35 |
37 | 36 |
38 (function TestBreakPointInConstructor() { | 37 (function TestBreakPointInConstructor() { |
39 done = false; | 38 done = false; |
40 stepCount = 1; | 39 stepCount = 1; |
41 var bp = Debug.setBreakPoint(Base, 0); | 40 var bp = Debug.setBreakPoint(Base, 0); |
42 | 41 |
43 new Base(); | 42 new Base(); |
44 assertEquals(5, stepCount); | 43 assertEquals(1, stepCount); |
45 | 44 |
46 Debug.clearBreakPoint(bp); | 45 Debug.clearBreakPoint(bp); |
47 })(); | 46 })(); |
48 | 47 |
49 | 48 |
50 (function TestDefaultConstructor() { | 49 (function TestDefaultConstructor() { |
51 done = false; | 50 done = false; |
52 stepCount = 1; | 51 stepCount = 1; |
53 | 52 |
54 var bp = Debug.setBreakPoint(Base, 0); | 53 var bp = Debug.setBreakPoint(Base, 0); |
55 new Derived(); | 54 new Derived(); |
56 assertEquals(5, stepCount); | 55 assertEquals(1, stepCount); |
57 | 56 |
58 Debug.clearBreakPoint(bp); | 57 Debug.clearBreakPoint(bp); |
59 })(); | 58 })(); |
60 | 59 |
61 | 60 |
62 (function TestStepInto() { | 61 (function TestStepInto() { |
63 done = false; | 62 done = false; |
64 stepCount = 0; | 63 stepCount = 0; |
65 | 64 |
66 function f() { | 65 function f() { |
67 new Derived(); // 0. | 66 new Derived(); // 0. |
68 } | 67 } |
69 | 68 |
70 var bp = Debug.setBreakPoint(f, 0); | 69 var bp = Debug.setBreakPoint(f, 0); |
71 f(); | 70 f(); |
72 assertEquals(5, stepCount); | 71 assertEquals(1, stepCount); |
73 | 72 |
74 Debug.clearBreakPoint(bp); | 73 Debug.clearBreakPoint(bp); |
75 })(); | 74 })(); |
76 | 75 |
77 | 76 |
78 (function TestExtraIndirection() { | 77 (function TestExtraIndirection() { |
79 done = false; | 78 done = false; |
80 stepCount = 0; | 79 stepCount = 0; |
81 | 80 |
82 class Derived2 extends Derived {} | 81 class Derived2 extends Derived {} |
83 | 82 |
84 function f() { | 83 function f() { |
85 new Derived2(); // 0. | 84 new Derived2(); // 0. |
86 } | 85 } |
87 | 86 |
88 var bp = Debug.setBreakPoint(f, 0); | 87 var bp = Debug.setBreakPoint(f, 0); |
89 f(); | 88 f(); |
90 assertEquals(5, stepCount); | 89 assertEquals(1, stepCount); |
91 | 90 |
92 Debug.clearBreakPoint(bp); | 91 Debug.clearBreakPoint(bp); |
93 })(); | 92 })(); |
94 | 93 |
95 | 94 |
96 (function TestBoundClass() { | 95 (function TestBoundClass() { |
97 done = false; | 96 done = false; |
98 stepCount = 0; | 97 stepCount = 0; |
99 | 98 |
100 var bound = Derived.bind(null); | 99 var bound = Derived.bind(null); |
101 | 100 |
102 function f() { | 101 function f() { |
103 new bound(); // 0. | 102 new bound(); // 0. |
104 } | 103 } |
105 | 104 |
106 var bp = Debug.setBreakPoint(f, 0); | 105 var bp = Debug.setBreakPoint(f, 0); |
107 f(); | 106 f(); |
108 assertEquals(5, stepCount); | 107 assertEquals(1, stepCount); |
109 | 108 |
110 Debug.clearBreakPoint(bp); | 109 Debug.clearBreakPoint(bp); |
111 })(); | 110 })(); |
112 | 111 |
113 | 112 |
114 Debug.setListener(null); | 113 Debug.setListener(null); |
OLD | NEW |