From 91b3078099fe5b121fb1aa84c4688d6c84686200 Mon Sep 17 00:00:00 2001 From: cola119 Date: Sat, 30 Apr 2022 01:29:45 +0900 Subject: [PATCH] debugger: add string validation for watch(expr) --- lib/internal/debugger/inspect_repl.js | 1 + .../test-debugger-watch-validation.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/sequential/test-debugger-watch-validation.js 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());