@@ -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
}
0 commit comments