From e45af10c66f4547edc38b5b1a79119c3404f86fa Mon Sep 17 00:00:00 2001 From: cola119 Date: Wed, 20 Apr 2022 12:15:43 +0900 Subject: [PATCH 1/5] debugger: throw debugger error when the frame is missing --- lib/internal/debugger/inspect_repl.js | 3 +++ test/sequential/test-debugger-list.js | 35 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/sequential/test-debugger-list.js diff --git a/lib/internal/debugger/inspect_repl.js b/lib/internal/debugger/inspect_repl.js index 4b11023554e268..20cc394e234078 100644 --- a/lib/internal/debugger/inspect_repl.js +++ b/lib/internal/debugger/inspect_repl.js @@ -635,6 +635,9 @@ function createRepl(inspector) { // List source code function list(delta = 5) { + if (!selectedFrame) { + throw new ERR_DEBUGGER_ERROR('Requires execution to be paused'); + } return selectedFrame.list(delta).then(null, (error) => { print("You can't list source code right now"); throw error; diff --git a/test/sequential/test-debugger-list.js b/test/sequential/test-debugger-list.js new file mode 100644 index 00000000000000..b5fe3143535ed7 --- /dev/null +++ b/test/sequential/test-debugger-list.js @@ -0,0 +1,35 @@ +'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/three-lines.js')]); + +cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.command('list(0)')) + .then(() => { + assert.match(cli.output, /> 1 let x = 1;/); + }) + .then(() => cli.command('list(1)')) + .then(() => { + assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;/); + }) + .then(() => cli.command('list(10)')) + .then(() => { + assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;\n {2}3 module\.exports = x;\n {2}4 /); + }) + .then(() => cli.command('c')) + .then(() => cli.waitFor(/disconnect/)) + .then(() => cli.waitForPrompt()) + .then(() => cli.command('list()')) + .then(() => { + assert.match(cli.output, /Uncaught Error \[ERR_DEBUGGER_ERROR\]: Requires execution to be paused/); + }) + .finally(() => cli.quit()) + .then(common.mustCall()); From 832435f81e5a9827fd225907e920240b46815330 Mon Sep 17 00:00:00 2001 From: cola119 Date: Thu, 21 Apr 2022 00:26:19 +0900 Subject: [PATCH 2/5] test: fix flaky test --- test/sequential/test-debugger-list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sequential/test-debugger-list.js b/test/sequential/test-debugger-list.js index b5fe3143535ed7..ba6fa1e801df3f 100644 --- a/test/sequential/test-debugger-list.js +++ b/test/sequential/test-debugger-list.js @@ -26,7 +26,7 @@ cli.waitForInitialBreak() }) .then(() => cli.command('c')) .then(() => cli.waitFor(/disconnect/)) - .then(() => cli.waitForPrompt()) + .then(() => cli.waitFor(/debug> $/)) .then(() => cli.command('list()')) .then(() => { assert.match(cli.output, /Uncaught Error \[ERR_DEBUGGER_ERROR\]: Requires execution to be paused/); From 88f48e0b569db8f6590c656e8bf97feee0fa4ea1 Mon Sep 17 00:00:00 2001 From: cola119 Date: Thu, 21 Apr 2022 08:23:01 +0900 Subject: [PATCH 3/5] test: refactor into async-await --- test/sequential/test-debugger-list.js | 40 ++++++++++++--------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/test/sequential/test-debugger-list.js b/test/sequential/test-debugger-list.js index ba6fa1e801df3f..2adc904c0c763a 100644 --- a/test/sequential/test-debugger-list.js +++ b/test/sequential/test-debugger-list.js @@ -10,26 +10,20 @@ const assert = require('assert'); const cli = startCLI([fixtures.path('debugger/three-lines.js')]); -cli.waitForInitialBreak() - .then(() => cli.waitForPrompt()) - .then(() => cli.command('list(0)')) - .then(() => { - assert.match(cli.output, /> 1 let x = 1;/); - }) - .then(() => cli.command('list(1)')) - .then(() => { - assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;/); - }) - .then(() => cli.command('list(10)')) - .then(() => { - assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;\n {2}3 module\.exports = x;\n {2}4 /); - }) - .then(() => cli.command('c')) - .then(() => cli.waitFor(/disconnect/)) - .then(() => cli.waitFor(/debug> $/)) - .then(() => cli.command('list()')) - .then(() => { - assert.match(cli.output, /Uncaught Error \[ERR_DEBUGGER_ERROR\]: Requires execution to be paused/); - }) - .finally(() => cli.quit()) - .then(common.mustCall()); +(async () => { + await cli.waitForInitialBreak(); + await cli.waitForPrompt(); + await cli.command('list(0)'); + assert.match(cli.output, /> 1 let x = 1;/); + await cli.command('list(1)'); + assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;/); + await cli.command('list(10)'); + assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;\n {2}3 module\.exports = x;\n {2}4 /); + await cli.command('c'); + await cli.waitFor(/disconnect/); + await cli.waitFor(/debug> $/); + await cli.command('list()'); + assert.match(cli.output, /Uncaught Error \[ERR_DEBUGGER_ERROR\]: Requires execution to be paused/); +})() +.finally(() => cli.quit()) +.then(common.mustCall()); From 4cbbd47de694a94cfa4dc53ef933211fe6065ee2 Mon Sep 17 00:00:00 2001 From: cola119 Date: Fri, 22 Apr 2022 17:55:47 +0900 Subject: [PATCH 4/5] test: fix flaky test --- test/sequential/test-debugger-list.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/sequential/test-debugger-list.js b/test/sequential/test-debugger-list.js index 2adc904c0c763a..5842e202d1034c 100644 --- a/test/sequential/test-debugger-list.js +++ b/test/sequential/test-debugger-list.js @@ -23,6 +23,7 @@ const cli = startCLI([fixtures.path('debugger/three-lines.js')]); await cli.waitFor(/disconnect/); await cli.waitFor(/debug> $/); await cli.command('list()'); + await cli.waitFor(/ERR_DEBUGGER_ERROR/); assert.match(cli.output, /Uncaught Error \[ERR_DEBUGGER_ERROR\]: Requires execution to be paused/); })() .finally(() => cli.quit()) From 2ac7da09395f1333efc63656394557c75f58de83 Mon Sep 17 00:00:00 2001 From: cola119 Date: Fri, 22 Apr 2022 23:04:48 +0900 Subject: [PATCH 5/5] test: fix newline characters --- test/sequential/test-debugger-list.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sequential/test-debugger-list.js b/test/sequential/test-debugger-list.js index 5842e202d1034c..594874e140b306 100644 --- a/test/sequential/test-debugger-list.js +++ b/test/sequential/test-debugger-list.js @@ -16,9 +16,9 @@ const cli = startCLI([fixtures.path('debugger/three-lines.js')]); await cli.command('list(0)'); assert.match(cli.output, /> 1 let x = 1;/); await cli.command('list(1)'); - assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;/); + assert.match(cli.output, /> 1 let x = 1;\r?\n {2}2 x = x \+ 1;/); await cli.command('list(10)'); - assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;\n {2}3 module\.exports = x;\n {2}4 /); + assert.match(cli.output, /> 1 let x = 1;\r?\n {2}2 x = x \+ 1;\r?\n {2}3 module\.exports = x;\r?\n {2}4 /); await cli.command('c'); await cli.waitFor(/disconnect/); await cli.waitFor(/debug> $/);