diff --git a/lib/internal/debugger/inspect_repl.js b/lib/internal/debugger/inspect_repl.js index 4b11023554e268..01e9374e1ceac0 100644 --- a/lib/internal/debugger/inspect_repl.js +++ b/lib/internal/debugger/inspect_repl.js @@ -1024,6 +1024,7 @@ function createRepl(inspector) { }, watch(expr) { + validateString(expr, 'expression'); ArrayPrototypePush(watchedExpressions, expr); }, diff --git a/test/sequential/test-debugger-watch-validation.js b/test/sequential/test-debugger-watch-validation.js new file mode 100644 index 00000000000000..46307c18d55526 --- /dev/null +++ b/test/sequential/test-debugger-watch-validation.js @@ -0,0 +1,20 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +const cli = startCLI([fixtures.path('debugger/break.js')]); + +(async () => { + await cli.waitForInitialBreak(); + await cli.command('watch()'); + await cli.waitFor(/ERR_INVALID_ARG_TYPE/); + assert.match(cli.output, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "expression" argument must be of type string\. Received undefined/); +})() +.finally(() => cli.quit()) +.then(common.mustCall());