test_restartFrame-01.js (3172B)
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 restarting a frame and stepping out of the 8 * restarted frame. 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 steps(threadFront, sequence) { 25 const locations = []; 26 for (const cmd of sequence) { 27 const packet = await step(threadFront, cmd); 28 locations.push(getPauseLocation(packet)); 29 } 30 return locations; 31 } 32 33 async function step(threadFront, cmd) { 34 return cmd(threadFront); 35 } 36 37 function getPauseLocation(packet) { 38 const { line, column } = packet.frame.where; 39 return { line, column }; 40 } 41 42 async function restartFrame0(dbg, func, expectedLocation) { 43 const { threadFront } = dbg; 44 45 info("pause and step into a()"); 46 await invokeAndPause(dbg, `${func}()`); 47 await steps(threadFront, [stepOver, stepIn]); 48 49 info("restart the youngest frame a()"); 50 const { frames } = await threadFront.frames(0, 5); 51 const frameActorID = frames[0].actorID; 52 const packet = await restartFrame(threadFront, frameActorID); 53 54 deepEqual( 55 getPauseLocation(packet), 56 expectedLocation, 57 "pause location in the restarted frame a()" 58 ); 59 } 60 61 async function restartFrame1(dbg, func, expectedLocation) { 62 const { threadFront } = dbg; 63 64 info("pause and step into b()"); 65 await invokeAndPause(dbg, `${func}()`); 66 await steps(threadFront, [stepOver, stepIn, stepIn]); 67 68 info("restart the frame with index 1"); 69 const { frames } = await threadFront.frames(0, 5); 70 const frameActorID = frames[1].actorID; 71 const packet = await restartFrame(threadFront, frameActorID); 72 73 deepEqual( 74 getPauseLocation(packet), 75 expectedLocation, 76 "pause location in the restarted frame c()" 77 ); 78 } 79 80 async function stepOutRestartedFrame( 81 dbg, 82 restartedFrameName, 83 expectedLocation, 84 expectedCallstackLength 85 ) { 86 const { threadFront } = dbg; 87 const { frames } = await threadFront.frames(0, 5); 88 89 Assert.equal( 90 frames.length, 91 expectedCallstackLength, 92 `the callstack length after restarting frame ${restartedFrameName}()` 93 ); 94 95 info(`step out of the restarted frame ${restartedFrameName}()`); 96 const frameActorID = frames[0].actorID; 97 const packet = await stepOut(threadFront, frameActorID); 98 99 deepEqual(getPauseLocation(packet), expectedLocation, `step out location`); 100 } 101 102 function run_test() { 103 return (async function () { 104 const dbg = await setupTestFromUrl("stepping.js"); 105 106 info(`Test restarting the youngest frame`); 107 await restartFrame0(dbg, "arithmetic", { line: 7, column: 2 }); 108 await stepOutRestartedFrame(dbg, "a", { line: 16, column: 8 }, 3); 109 await dbg.threadFront.resume(); 110 111 info(`Test restarting the frame with the index 1`); 112 await restartFrame1(dbg, "nested", { line: 30, column: 2 }); 113 await stepOutRestartedFrame(dbg, "c", { line: 36, column: 0 }, 3); 114 await dbg.threadFront.resume(); 115 116 await testFinish(dbg); 117 })(); 118 }