| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 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 | 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 print('Checks possible break locations.'); | 5 print('Checks possible break locations.'); |
| 6 | 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 async function testAsyncAwait() { | |
| 220 await asyncFoo(); | |
| 221 await awaitBoo(); | |
| 222 } | |
| 223 | |
| 224 // TODO(kozyatinskiy): fix this. | |
| 225 async function testPromiseAsyncWithCode() { | |
| 226 var nextTest; | |
| 227 var testPromise = new Promise(resolve => nextTest = resolve); | |
| 228 async function main() { | |
| 229 async function foo() { | |
| 230 var resolveNested; | |
| 231 var p = new Promise(resolve => resolveNested = resolve); | |
| 232 setTimeout(resolveNested, 0); | |
| 233 await p; | |
| 234 } | |
| 235 setTimeout(returnCall, 0); | |
| 236 await foo(); | |
| 237 await foo(); | |
| 238 nextTest(); | |
| 239 } | |
| 240 main(); | |
| 241 return testPromise; | |
| 242 } | |
| 243 | |
| 244 //# sourceURL=test.js`); | |
| 245 | |
| 246 InspectorTest.setupScriptMap(); | 7 InspectorTest.setupScriptMap(); |
| 247 Protocol.Debugger.onPaused(message => { | 8 Protocol.Debugger.onPaused(message => { |
| 248 var frames = message.params.callFrames; | 9 var frames = message.params.callFrames; |
| 249 if (frames.length === 1) { | 10 if (frames.length === 1) { |
| 250 Protocol.Debugger.stepInto(); | 11 Protocol.Debugger.stepInto(); |
| 251 return; | 12 return; |
| 252 } | 13 } |
| 253 var scriptId = frames[0].location.scriptId; | 14 var scriptId = frames[0].location.scriptId; |
| 254 InspectorTest.log('break at:'); | 15 InspectorTest.log('break at:'); |
| 255 InspectorTest.logCallFrameSourceLocation(frames[0]) | 16 InspectorTest.logCallFrameSourceLocation(frames[0]) |
| 256 .then(() => Protocol.Debugger.stepInto()); | 17 .then(() => Protocol.Debugger.stepInto()); |
| 257 }); | 18 }); |
| 258 | 19 |
| 20 InspectorTest.loadScript('test/inspector/debugger/resources/break-locations.js')
; |
| 21 |
| 259 Protocol.Debugger.enable(); | 22 Protocol.Debugger.enable(); |
| 260 Protocol.Runtime.evaluate({ expression: 'Object.keys(this).filter(name => name.i
ndexOf(\'test\') === 0)', returnByValue: true }) | 23 Protocol.Runtime.evaluate({ expression: 'Object.keys(this).filter(name => name.i
ndexOf(\'test\') === 0)', returnByValue: true }) |
| 261 .then(runTests); | 24 .then(runTests); |
| 262 | 25 |
| 263 function runTests(message) { | 26 function runTests(message) { |
| 264 var tests = message.result.result.value; | 27 var tests = message.result.result.value; |
| 265 InspectorTest.runTestSuite(tests.map(test => eval(`(function ${test}(next) { | 28 InspectorTest.runTestSuite(tests.map(test => eval(`(function ${test}(next) { |
| 266 Protocol.Runtime.evaluate({ expression: 'debugger; ${test}()', awaitPromise:
${test.indexOf('testPromise') === 0}}) | 29 Protocol.Runtime.evaluate({ expression: 'debugger; ${test}()', awaitPromise:
${test.indexOf('testPromise') === 0}}) |
| 267 .then(next); | 30 .then(next); |
| 268 })`))); | 31 })`))); |
| 269 } | 32 } |
| OLD | NEW |