GeezerVison is showing github.com — debugger: improve validations and documents for watch and unwatch · nodejs/node@bce37c6
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -197,6 +197,7 @@ debug> | 197 | 197 | after) | 198 | 198 | * `watch(expr)`: Add expression to watch list | 199 | 199 | * `unwatch(expr)`: Remove expression from watch list | | 200 | +* `unwatch(index)`: Remove expression at specific index from watch list | 200 | 201 | * `watchers`: List all watchers and their values (automatically listed on each | 201 | 202 | breakpoint) | 202 | 203 | * `repl`: Open debugger's repl for evaluation in debugging script's context | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/debugger/inspect_repl.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -91,6 +91,7 @@ breakOnNone Don't pause on exceptions (this is the default) | 91 | 91 |
| 92 | 92 | watch(expr) Start watching the given expression | 93 | 93 | unwatch(expr) Stop watching an expression | | 94 | +unwatch(index) Stop watching an expression at specific index from watch list | 94 | 95 | watchers Print all watched expressions and their current values | 95 | 96 |
| 96 | 97 | exec(expr), p(expr), exec expr, p expr | @@ -1078,6 +1079,7 @@ function createRepl(inspector) { | 1078 | 1079 | }, | 1079 | 1080 |
| 1080 | 1081 | watch(expr) { | | 1082 | + validateString(expr, 'expression'); | 1081 | 1083 | ArrayPrototypePush(watchedExpressions, expr); | 1082 | 1084 | }, | 1083 | 1085 |
| |
Collapse file Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboardExpand all lines: test/sequential/test-debugger-watchers.mjs +11-4Lines changed: 11 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,18 +28,25 @@ try { | 28 | 28 | await cli.command('watchers'); | 29 | 29 |
| 30 | 30 | 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)'); | 32 | 40 | await cli.command('unwatch("42")'); | 33 | 41 | await cli.stepCommand('n'); | 34 | 42 |
| 35 | 43 | assert.match(cli.output, /0: x = 10/); | 36 | 44 | assert.match(cli.output, /1: "Hello" = 'Hello'/); | 37 | 45 | 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 \]/); | 40 | 47 | assert.match( | 41 | 48 | cli.output, | 42 | | - /5: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/, | | 49 | + /4: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/, | 43 | 50 | 'shows "..." for process.env' | 44 | 51 | ); | 45 | 52 |
| |
|