test_stepping-01.js (2323B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Check scenarios where we're leaving function a and 8 * going to the function b's call-site. 9 */ 10 11 async function testFinish({ devToolsClient }) { 12 await close(devToolsClient); 13 14 do_test_finished(); 15 } 16 17 async function invokeAndPause({ global, threadFront }, expression) { 18 return executeOnNextTickAndWaitForPause( 19 () => global.eval(expression), 20 threadFront 21 ); 22 } 23 24 async function step(threadFront, cmd) { 25 return cmd(threadFront); 26 } 27 28 function getPauseLocation(packet) { 29 const { line, column } = packet.frame.where; 30 return { line, column }; 31 } 32 33 function getPauseReturn(packet) { 34 return packet.why.frameFinished.return; 35 } 36 37 async function steps(threadFront, sequence) { 38 const locations = []; 39 for (const cmd of sequence) { 40 const packet = await step(threadFront, cmd); 41 locations.push(getPauseLocation(packet)); 42 } 43 return locations; 44 } 45 46 async function stepOutOfA(dbg, func, expectedLocation) { 47 await invokeAndPause(dbg, `${func}()`); 48 const { threadFront } = dbg; 49 await steps(threadFront, [stepOver, stepIn]); 50 51 const packet = await stepOut(threadFront); 52 53 deepEqual( 54 getPauseLocation(packet), 55 expectedLocation, 56 `step out location in ${func}` 57 ); 58 59 await threadFront.resume(); 60 } 61 62 async function stepOverInA(dbg, func, expectedLocation) { 63 await invokeAndPause(dbg, `${func}()`); 64 const { threadFront } = dbg; 65 await steps(threadFront, [stepOver, stepIn]); 66 67 let packet = await stepOver(threadFront); 68 equal(getPauseReturn(packet).ownPropertyLength, 1, "a() is returning obj"); 69 70 packet = await stepOver(threadFront); 71 deepEqual( 72 getPauseLocation(packet), 73 expectedLocation, 74 `step out location in ${func}` 75 ); 76 await dbg.threadFront.resume(); 77 } 78 79 async function testStep(dbg, func, expectedValue) { 80 await stepOverInA(dbg, func, expectedValue); 81 await stepOutOfA(dbg, func, expectedValue); 82 } 83 84 function run_test() { 85 return (async function () { 86 const dbg = await setupTestFromUrl("stepping.js"); 87 88 await testStep(dbg, "arithmetic", { line: 16, column: 8 }); 89 await testStep(dbg, "composition", { line: 21, column: 3 }); 90 await testStep(dbg, "chaining", { line: 26, column: 6 }); 91 92 await testFinish(dbg); 93 })(); 94 }