Skip to content

Commit e4f0d95

Browse files
meixgbengl
authored andcommitted
debugger: add debugger alias for exec(expr)
#41794 PR-URL: #41907 Reviewed-By: Jan Krems <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 224745c commit e4f0d95

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

doc/api/debugger.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ debug>
197197
* `watchers`: List all watchers and their values (automatically listed on each
198198
breakpoint)
199199
* `repl`: Open debugger's repl for evaluation in debugging script's context
200-
* `exec expr`: Execute an expression in debugging script's context
200+
* `exec expr`, `p expr`: Execute an expression in debugging script's context and
201+
print its value
201202

202203
### Execution control
203204

lib/internal/debugger/inspect_repl.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const SHORTCUTS = {
6868
setBreakpoint: 'sb',
6969
clearBreakpoint: 'cb',
7070
run: 'r',
71+
exec: 'p'
7172
};
7273

7374
const HELP = StringPrototypeTrim(`
@@ -93,7 +94,8 @@ watch(expr) Start watching the given expression
9394
unwatch(expr) Stop watching an expression
9495
watchers Print all watched expressions and their current values
9596
96-
exec(expr) Evaluate the expression and print the value
97+
exec(expr), p(expr), exec expr, p expr
98+
Evaluate the expression and print the value
9799
repl Enter a debug repl that works like exec
98100
99101
scripts List application scripts that are currently loaded
@@ -530,7 +532,7 @@ function createRepl(inspector) {
530532
function prepareControlCode(input) {
531533
if (input === '\n') return lastCommand;
532534
// Add parentheses: exec process.title => exec("process.title");
533-
const match = RegExpPrototypeSymbolMatch(/^\s*exec\s+([^\n]*)/, input);
535+
const match = RegExpPrototypeSymbolMatch(/^\s*(?:exec|p)\s+([^\n]*)/, input);
534536
if (match) {
535537
lastCommand = `exec(${JSONStringify(match[1])})`;
536538
} else {

test/sequential/test-debugger-exec.js

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ const assert = require('assert');
2727
'works w/o paren'
2828
);
2929
})
30+
.then(() => cli.command('p [typeof heartbeat, typeof process.exit]'))
31+
.then(() => {
32+
assert.match(
33+
cli.output,
34+
/\[ 'function', 'function' \]/,
35+
'works w/o paren, short'
36+
);
37+
})
3038
.then(() => cli.command('repl'))
3139
.then(() => {
3240
assert.match(
@@ -54,6 +62,14 @@ const assert = require('assert');
5462
'works w/ paren'
5563
);
5664
})
65+
.then(() => cli.command('p("[typeof heartbeat, typeof process.exit]")'))
66+
.then(() => {
67+
assert.match(
68+
cli.output,
69+
/\[ 'function', 'function' \]/,
70+
'works w/ paren, short'
71+
);
72+
})
5773
.then(() => cli.command('cont'))
5874
.then(() => cli.command('exec [typeof heartbeat, typeof process.exit]'))
5975
.then(() => {

0 commit comments

Comments
 (0)