@@ -64,6 +64,7 @@ const SHORTCUTS = {
64
64
step : 's' ,
65
65
out : 'o' ,
66
66
backtrace : 'bt' ,
67
+ setContextLineNumber : 'scln' ,
67
68
setBreakpoint : 'sb' ,
68
69
clearBreakpoint : 'cb' ,
69
70
run : 'r' ,
@@ -81,7 +82,8 @@ out, o Step out, leaving the current function
81
82
backtrace, bt Print the current backtrace
82
83
list Print the source around the current line where execution
83
84
is currently paused
84
-
85
+ setContextLineNumber, scln
86
+ Set which lines to check for context
85
87
setBreakpoint, sb Set a breakpoint
86
88
clearBreakpoint, cb Clear a breakpoint
87
89
breakpoints List all known breakpoints
@@ -381,6 +383,7 @@ function createRepl(inspector) {
381
383
let currentBacktrace ;
382
384
let selectedFrame ;
383
385
let exitDebugRepl ;
386
+ let contextLineNumber = 2 ;
384
387
385
388
function resetOnStart ( ) {
386
389
knownScripts = { } ;
@@ -685,6 +688,19 @@ function createRepl(inspector) {
685
688
} ) ;
686
689
}
687
690
691
+ function setContextLineNumber ( delta = 2 ) {
692
+ if ( ! selectedFrame ) {
693
+ throw new ERR_DEBUGGER_ERROR ( 'Requires execution to be paused' ) ;
694
+ }
695
+ try {
696
+ contextLineNumber = delta ;
697
+ print ( `The contextLine has been changed to ${ delta } .` )
698
+ } catch ( error ) {
699
+ print ( "You can't setContextLineNumber source code right now" ) ;
700
+ throw error ;
701
+ }
702
+ }
703
+
688
704
function handleBreakpointResolved ( { breakpointId, location } ) {
689
705
const script = knownScripts [ location . scriptId ] ;
690
706
const scriptUrl = script && script . url ;
@@ -897,7 +913,7 @@ function createRepl(inspector) {
897
913
898
914
inspector . suspendReplWhile ( ( ) =>
899
915
PromisePrototypeThen (
900
- SafePromiseAllReturnArrayLike ( [ formatWatchers ( true ) , selectedFrame . list ( 2 ) ] ) ,
916
+ SafePromiseAllReturnArrayLike ( [ formatWatchers ( true ) , selectedFrame . list ( contextLineNumber ) ] ) ,
901
917
( { 0 : watcherList , 1 : context } ) => {
902
918
const breakContext = watcherList ?
903
919
`${ watcherList } \n${ inspect ( context ) } ` :
@@ -1159,6 +1175,7 @@ function createRepl(inspector) {
1159
1175
} ,
1160
1176
1161
1177
list,
1178
+ setContextLineNumber
1162
1179
} ) ;
1163
1180
aliasProperties ( context , SHORTCUTS ) ;
1164
1181
}
0 commit comments