| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,7 @@ const { | |||
| 46 | 46 | ||
| 47 | 47 | const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes; | |
| 48 | 48 | ||
| 49 | - const { validateString } = require('internal/validators'); | ||
| 49 | + const { validateString, validateNumber } = require('internal/validators'); | ||
| 50 | 50 | ||
| 51 | 51 | const FS = require('fs'); | |
| 52 | 52 | const Path = require('path'); | |
@@ -81,7 +81,7 @@ out, o Step out, leaving the current function | |||
| 81 | 81 | backtrace, bt Print the current backtrace | |
| 82 | 82 | list Print the source around the current line where execution | |
| 83 | 83 | is currently paused | |
| 84 | - | ||
| 84 | + setContextLineNumber Set which lines to check for context | ||
| 85 | 85 | setBreakpoint, sb Set a breakpoint | |
| 86 | 86 | clearBreakpoint, cb Clear a breakpoint | |
| 87 | 87 | breakpoints List all known breakpoints | |
@@ -381,6 +381,7 @@ function createRepl(inspector) { | |||
| 381 | 381 | let currentBacktrace; | |
| 382 | 382 | let selectedFrame; | |
| 383 | 383 | let exitDebugRepl; | |
| 384 | + let contextLineNumber = 2; | ||
| 384 | 385 | ||
| 385 | 386 | function resetOnStart() { | |
| 386 | 387 | knownScripts = {}; | |
@@ -685,6 +686,15 @@ function createRepl(inspector) { | |||
| 685 | 686 | }); | |
| 686 | 687 | } | |
| 687 | 688 | ||
| 689 | + function setContextLineNumber(delta = 2) { | ||
| 690 | + if (!selectedFrame) { | ||
| 691 | + throw new ERR_DEBUGGER_ERROR('Requires execution to be paused'); | ||
| 692 | + } | ||
| 693 | + validateNumber(delta, 'delta', 1); | ||
| 694 | + contextLineNumber = delta; | ||
| 695 | + print(`The contextLine has been changed to ${delta}.`); | ||
| 696 | + } | ||
| 697 | + | ||
| 688 | 698 | function handleBreakpointResolved({ breakpointId, location }) { | |
| 689 | 699 | const script = knownScripts[location.scriptId]; | |
| 690 | 700 | const scriptUrl = script && script.url; | |
@@ -897,7 +907,7 @@ function createRepl(inspector) { | |||
| 897 | 907 | ||
| 898 | 908 | inspector.suspendReplWhile(() => | |
| 899 | 909 | PromisePrototypeThen( | |
| 900 | - SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(2)]), | ||
| 910 | + SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(contextLineNumber)]), | ||
| 901 | 911 | ({ 0: watcherList, 1: context }) => { | |
| 902 | 912 | const breakContext = watcherList ? | |
| 903 | 913 | `${watcherList}\n${inspect(context)}` : | |
@@ -1159,6 +1169,7 @@ function createRepl(inspector) { | |||
| 1159 | 1169 | }, | |
| 1160 | 1170 | ||
| 1161 | 1171 | list, | |
| 1172 | + setContextLineNumber, | ||
| 1162 | 1173 | }); | |
| 1163 | 1174 | aliasProperties(context, SHORTCUTS); | |
| 1164 | 1175 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,20 @@ | |||
| 1 | + let x = 0; | ||
| 2 | + x = 1; | ||
| 3 | + x = 2; | ||
| 4 | + x = 3; | ||
| 5 | + x = 4; | ||
| 6 | + x = 5; | ||
| 7 | + x = 6; | ||
| 8 | + x = 7; | ||
| 9 | + x = 8; | ||
| 10 | + x = 9; | ||
| 11 | + x = 10; | ||
| 12 | + x = 11; | ||
| 13 | + x = 12; | ||
| 14 | + x = 13; | ||
| 15 | + x = 14; | ||
| 16 | + x = 15; | ||
| 17 | + x = 16; | ||
| 18 | + x = 17; | ||
| 19 | + x = 18; | ||
| 20 | + module.exports = x; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,50 @@ | |||
| 1 | + import { skipIfInspectorDisabled } from '../common/index.mjs'; | ||
| 2 | + skipIfInspectorDisabled(); | ||
| 3 | + | ||
| 4 | + import { path } from '../common/fixtures.mjs'; | ||
| 5 | + import startCLI from '../common/debugger.js'; | ||
| 6 | + | ||
| 7 | + import assert from 'assert'; | ||
| 8 | + | ||
| 9 | + const script = path('debugger', 'twenty-lines.js'); | ||
| 10 | + const cli = startCLI([script]); | ||
| 11 | + | ||
| 12 | + function onFatal(error) { | ||
| 13 | + cli.quit(); | ||
| 14 | + throw error; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + function getLastLine(output) { | ||
| 18 | + const splittedByLine = output.split(';'); | ||
| 19 | + return splittedByLine[splittedByLine.length - 2]; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + // Stepping through breakpoints. | ||
| 23 | + try { | ||
| 24 | + await cli.waitForInitialBreak(); | ||
| 25 | + await cli.waitForPrompt(); | ||
| 26 | + | ||
| 27 | + await cli.command('setContextLineNumber("1")'); | ||
| 28 | + assert.ok(cli.output.includes('argument must be of type number. Received type string')); | ||
| 29 | + | ||
| 30 | + await cli.command('setContextLineNumber(0)'); | ||
| 31 | + assert.ok(cli.output.includes('It must be >= 1. Received 0')); | ||
| 32 | + | ||
| 33 | + // Make sure the initial value is 2. | ||
| 34 | + await cli.stepCommand('n'); | ||
| 35 | + assert.ok(getLastLine(cli.output).includes('4 x = 3')); | ||
| 36 | + | ||
| 37 | + await cli.command('setContextLineNumber(5)'); | ||
| 38 | + await cli.stepCommand('n'); | ||
| 39 | + assert.ok(getLastLine(cli.output).includes('8 x = 7')); | ||
| 40 | + | ||
| 41 | + await cli.command('setContextLineNumber(3)'); | ||
| 42 | + await cli.stepCommand('n'); | ||
| 43 | + assert.ok(getLastLine(cli.output).includes('7 x = 6')); | ||
| 44 | + await cli.command('list(3)'); | ||
| 45 | + assert.ok(getLastLine(cli.output).includes('7 x = 6')); | ||
| 46 | + | ||
| 47 | + await cli.quit(); | ||
| 48 | + } catch (error) { | ||
| 49 | + onFatal(error); | ||
| 50 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments