Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b7eb56

Browse filesBrowse files
Dailyscattargos
authored andcommitted
debugger: improve validations and documents for watch and unwatch
- debugger: add string validation for watch(expr) - debugger: add help document for watch(index) - test: add test for watch(index) command - doc: add information on unwatch(index) option PR-URL: #46947 Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
1 parent 94882f5 commit 2b7eb56
Copy full SHA for 2b7eb56

File tree

Expand file treeCollapse file tree

4 files changed

+34
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+34
-4
lines changed
Open diff view settings
Collapse file

‎doc/api/debugger.md‎

Copy file name to clipboardExpand all lines: doc/api/debugger.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ debug>
197197
after)
198198
* `watch(expr)`: Add expression to watch list
199199
* `unwatch(expr)`: Remove expression from watch list
200+
* `unwatch(index)`: Remove expression at specific index from watch list
200201
* `watchers`: List all watchers and their values (automatically listed on each
201202
breakpoint)
202203
* `repl`: Open debugger's repl for evaluation in debugging script's context
Collapse file

‎lib/internal/debugger/inspect_repl.js‎

Copy file name to clipboardExpand all lines: lib/internal/debugger/inspect_repl.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ breakOnNone Don't pause on exceptions (this is the default)
9191
9292
watch(expr) Start watching the given expression
9393
unwatch(expr) Stop watching an expression
94+
unwatch(index) Stop watching an expression at specific index from watch list
9495
watchers Print all watched expressions and their current values
9596
9697
exec(expr), p(expr), exec expr, p expr
@@ -1078,6 +1079,7 @@ function createRepl(inspector) {
10781079
},
10791080

10801081
watch(expr) {
1082+
validateString(expr, 'expression');
10811083
ArrayPrototypePush(watchedExpressions, expr);
10821084
},
10831085

Collapse file
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
common.skipIfInspectorDisabled();
5+
6+
const fixtures = require('../common/fixtures');
7+
const startCLI = require('../common/debugger');
8+
9+
const assert = require('assert');
10+
11+
const cli = startCLI([fixtures.path('debugger/break.js')]);
12+
13+
(async () => {
14+
await cli.waitForInitialBreak();
15+
await cli.command('watch()');
16+
await cli.waitFor(/ERR_INVALID_ARG_TYPE/);
17+
assert.match(cli.output, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "expression" argument must be of type string\. Received undefined/);
18+
})()
19+
.finally(() => cli.quit())
20+
.then(common.mustCall());
Collapse file

‎test/sequential/test-debugger-watchers.mjs‎

Copy file name to clipboardExpand all lines: test/sequential/test-debugger-watchers.mjs
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,25 @@ try {
2828
await cli.command('watchers');
2929

3030
assert.match(cli.output, /x is not defined/);
31-
31+
assert.match(cli.output, /1: "Hello" = 'Hello'/);
32+
assert.match(cli.output, /2: 42 = 42/);
33+
assert.match(cli.output, /3: NaN = NaN/);
34+
assert.match(cli.output, /4: true = true/);
35+
assert.match(cli.output, /5: \[1, 2\] = \[ 1, 2 \]/);
36+
assert.match(cli.output, /6: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/,
37+
'shows "..." for process.env');
38+
39+
await cli.command('unwatch(4)');
3240
await cli.command('unwatch("42")');
3341
await cli.stepCommand('n');
3442

3543
assert.match(cli.output, /0: x = 10/);
3644
assert.match(cli.output, /1: "Hello" = 'Hello'/);
3745
assert.match(cli.output, /2: NaN = NaN/);
38-
assert.match(cli.output, /3: true = true/);
39-
assert.match(cli.output, /4: \[1, 2\] = \[ 1, 2 \]/);
46+
assert.match(cli.output, /3: \[1, 2\] = \[ 1, 2 \]/);
4047
assert.match(
4148
cli.output,
42-
/5: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/,
49+
/4: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/,
4350
'shows "..." for process.env'
4451
);
4552

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.