Skip to content

Commit

Permalink
debugger: add debugger alias for exec(expr)
Browse files Browse the repository at this point in the history
#41794

PR-URL: #41907
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
  • Loading branch information
meixg authored and bengl committed Feb 22, 2022
1 parent f51b55d commit 67f1ebf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doc/api/debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ debug>
* `watchers`: List all watchers and their values (automatically listed on each
breakpoint)
* `repl`: Open debugger's repl for evaluation in debugging script's context
* `exec expr`: Execute an expression in debugging script's context
* `exec expr`, `p expr`: Execute an expression in debugging script's context and
print its value

### Execution control

Expand Down
6 changes: 4 additions & 2 deletions lib/internal/debugger/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const SHORTCUTS = {
setBreakpoint: 'sb',
clearBreakpoint: 'cb',
run: 'r',
exec: 'p'
};

const HELP = StringPrototypeTrim(`
Expand All @@ -93,7 +94,8 @@ watch(expr) Start watching the given expression
unwatch(expr) Stop watching an expression
watchers Print all watched expressions and their current values
exec(expr) Evaluate the expression and print the value
exec(expr), p(expr), exec expr, p expr
Evaluate the expression and print the value
repl Enter a debug repl that works like exec
scripts List application scripts that are currently loaded
Expand Down Expand Up @@ -530,7 +532,7 @@ function createRepl(inspector) {
function prepareControlCode(input) {
if (input === '\n') return lastCommand;
// Add parentheses: exec process.title => exec("process.title");
const match = RegExpPrototypeSymbolMatch(/^\s*exec\s+([^\n]*)/, input);
const match = RegExpPrototypeSymbolMatch(/^\s*(?:exec|p)\s+([^\n]*)/, input);
if (match) {
lastCommand = `exec(${JSONStringify(match[1])})`;
} else {
Expand Down
16 changes: 16 additions & 0 deletions test/sequential/test-debugger-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const assert = require('assert');
'works w/o paren'
);
})
.then(() => cli.command('p [typeof heartbeat, typeof process.exit]'))
.then(() => {
assert.match(
cli.output,
/\[ 'function', 'function' \]/,
'works w/o paren, short'
);
})
.then(() => cli.command('repl'))
.then(() => {
assert.match(
Expand Down Expand Up @@ -54,6 +62,14 @@ const assert = require('assert');
'works w/ paren'
);
})
.then(() => cli.command('p("[typeof heartbeat, typeof process.exit]")'))
.then(() => {
assert.match(
cli.output,
/\[ 'function', 'function' \]/,
'works w/ paren, short'
);
})
.then(() => cli.command('cont'))
.then(() => cli.command('exec [typeof heartbeat, typeof process.exit]'))
.then(() => {
Expand Down

0 comments on commit 67f1ebf

Please sign in to comment.