OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 print('Checks possible break locations.'); | |
6 | |
7 InspectorTest.addScript(` | |
8 | |
9 function testEval() { | |
10 eval('// comment only'); | |
11 eval('// comment only\\n'); | |
12 } | |
13 | |
14 // function without return | |
15 function procedure() { | |
16 var a = 1; | |
17 var b = 2; | |
18 } | |
19 | |
20 function testProcedure() { | |
21 procedure(); | |
22 } | |
23 | |
24 function returnTrue() { | |
25 return true; | |
26 } | |
27 | |
28 function testIf() { | |
29 var a; | |
30 if (true) a = true; | |
31 if (!a) { | |
32 a = true; | |
33 } else { | |
34 a = false; | |
35 } | |
36 if (returnTrue()) { | |
37 a = false; | |
38 } else { | |
39 a = true; | |
40 } | |
41 } | |
42 | |
43 function emptyFunction() {} | |
44 | |
45 function testEmptyFunction() { | |
46 emptyFunction(); | |
47 } | |
48 | |
49 function twoArguments(a1, a2) { | |
50 } | |
51 | |
52 function testCallArguments() { | |
53 twoArguments(emptyFunction(), emptyFunction()); | |
54 } | |
55 | |
56 function testNested() { | |
57 function nested1() { | |
58 function nested2() { | |
59 function nested3() { | |
60 } | |
61 nested3(); | |
62 return; | |
63 } | |
64 return nested2(); | |
65 } | |
66 nested1(); | |
67 } | |
68 | |
69 function return42() { | |
70 return 42; | |
71 } | |
72 | |
73 function returnCall() { | |
74 return return42(); | |
75 } | |
76 | |
77 function testCallAtReturn() { | |
78 return returnCall(); | |
79 } | |
80 | |
81 function returnObject() { | |
82 return ({ foo: () => 42 }); | |
83 } | |
84 | |
85 function testWith() { | |
86 with (returnObject()) { | |
87 foo(); | |
88 } | |
89 with({}) { | |
90 return; | |
91 } | |
92 } | |
93 | |
94 function testForLoop() { | |
95 for (var i = 0; i < 1; ++i) {} | |
96 for (var i = 0; i < 1; ++i) i; | |
97 for (var i = 0; i < 0; ++i) {} | |
98 } | |
99 | |
100 function testForOfLoop() { | |
101 for (var k of []) {} | |
102 for (var k of [1]) k; | |
103 var a = []; | |
104 for (var k of a) {} | |
105 } | |
106 | |
107 function testForInLoop() { | |
108 var o = {}; | |
109 for (var k in o) {} | |
110 for (var k in o) k; | |
111 for (var k in { a:1 }) {} | |
112 for (var k in { a:1 }) k; | |
113 } | |
114 | |
115 function testSimpleExpressions() { | |
116 1 + 2 + 3; | |
117 var a = 1; | |
118 ++a; | |
119 a--; | |
120 } | |
121 | |
122 Object.defineProperty(this, 'getterFoo', { | |
123 get: () => return42 | |
124 }); | |
125 | |
126 function testGetter() { | |
127 getterFoo(); | |
128 } | |
129 | |
130 var obj = { | |
131 foo: () => ({ | |
132 boo: () => return42 | |
133 }) | |
134 }; | |
135 | |
136 function testChainedCalls() { | |
137 obj.foo().boo()(); | |
138 } | |
139 | |
140 function testChainedWithNative() { | |
141 Array.from([1]).concat([2]).map(v => v * 2); | |
142 } | |
143 | |
144 function testPromiseThen() { | |
145 return Promise.resolve().then(v => v * 2).then(v => v * 2); | |
146 } | |
147 | |
148 function testSwitch() { | |
149 for (var i = 0; i < 3; ++i) { | |
150 switch(i) { | |
151 case 0: continue; | |
152 case 1: return42(); break; | |
153 default: return; | |
154 } | |
155 } | |
156 } | |
157 | |
158 function* idMaker() { | |
159 yield 1; | |
160 yield 2; | |
161 yield 3; | |
162 } | |
163 | |
164 function testGenerator() { | |
165 var gen = idMaker(); | |
166 return42(); | |
167 gen.next().value; | |
168 debugger; | |
169 gen.next().value; | |
170 return42(); | |
171 gen.next().value; | |
172 return42(); | |
173 gen.next().value; | |
174 } | |
175 | |
176 function throwException() { | |
177 throw new Error(); | |
178 } | |
179 | |
180 function testCaughtException() { | |
181 try { | |
182 throwException() | |
183 } catch (e) { | |
184 return; | |
185 } | |
186 } | |
187 | |
188 function testClasses() { | |
189 class Cat { | |
190 constructor(name) { | |
191 this.name = name; | |
192 } | |
193 | |
194 speak() { | |
195 } | |
196 } | |
197 class Lion extends Cat { | |
198 constructor(name) { | |
199 super(name); | |
200 } | |
201 | |
202 speak() { | |
203 super.speak(); | |
204 } | |
205 } | |
206 new Lion().speak(); | |
207 } | |
208 | |
209 async function asyncFoo() { | |
210 await Promise.resolve().then(v => v * 2); | |
211 return42(); | |
212 await asyncBoo(); | |
213 } | |
214 | |
215 async function asyncBoo() { | |
216 await Promise.resolve(); | |
217 | |
218 } | |
219 | |
220 async function testAsyncAwait() { | |
221 await asyncFoo(); | |
222 await awaitBoo(); | |
dgozman
2017/02/27 17:56:48
Let's add that example where we skip something wit
kozy
2017/02/27 18:35:08
I added a test for some code in the middle and beh
| |
223 } | |
224 | |
225 //# sourceURL=test.js`); | |
226 | |
227 InspectorTest.setupScriptMap(); | |
228 Protocol.Debugger.onPaused(message => { | |
229 var frames = message.params.callFrames; | |
230 if (frames.length === 1) { | |
231 Protocol.Debugger.stepInto(); | |
232 return; | |
233 } | |
234 var scriptId = frames[0].location.scriptId; | |
235 InspectorTest.log('break at:'); | |
236 InspectorTest.logCallFrameSourceLocation(frames[0]) | |
237 .then(() => Protocol.Debugger.stepInto()); | |
238 }); | |
239 | |
240 Protocol.Debugger.enable(); | |
241 Protocol.Runtime.evaluate({ expression: 'Object.keys(this).filter(name => name.i ndexOf(\'test\') === 0)', returnByValue: true }) | |
242 .then(runTests); | |
243 | |
244 function runTests(message) { | |
245 var tests = message.result.result.value; | |
246 InspectorTest.runTestSuite(tests.map(test => eval(`(function ${test}(next) { | |
247 Protocol.Runtime.evaluate({ expression: 'debugger; ${test}()', awaitPromise: ${test.indexOf('testPromise') === 0}}).then(next); | |
248 })`))); | |
249 } | |
OLD | NEW |