Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger - Filter out the ending of the Module wrapper when using the list command #9773

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,9 @@ Interface.prototype.list = function(delta) {
var lines = res.source.split('\n');
for (var i = 0; i < lines.length; i++) {
var lineno = res.fromLine + i + 1;
if (lineno < from || lineno > to) continue;
// The very last line will be the end of the module wrapper,
// and we need to filter that out.
if (lineno < from || lineno > to || lineno === lines.length) continue;

const current = lineno === 1 + client.currentSourceLine;
const breakpoint = client.breakpoints.some(function(bp) {
Expand Down
62 changes: 62 additions & 0 deletions test/parallel/test-debugger-list-no-module-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';
const common = require('../common');
const path = require('path');
const spawn = require('child_process').spawn;
const assert = require('assert');
const fixture = path.join(
common.fixturesDir,
'debugger-repeat-last.js'
);

const args = [
'debug',
`--port=${common.PORT}`,
fixture
];

const proc = spawn(process.execPath, args, { stdio: 'pipe' });
proc.stdout.setEncoding('utf8');

let stdout = '';

let hasPrompt = false;
let sentList = false;
let sentExit = false;

proc.stdout.on('data', (data) => {
if (!hasPrompt && data.startsWith('> 1')) {
hasPrompt = true;
}

if (hasPrompt) {
stdout += data;
if (!sentList) {
setImmediate(() => { proc.stdin.write('list(10)\n'); });
sentList = true;
return;
}

if (!sentExit && sentList) {
setImmediate(() => { proc.stdin.write('\n\n\n.exit\n\n\n'); });
sentExit = true;
return;
}
}
});

proc.on('exit', common.mustCall((exitCode, signal) => {
assert.strictEqual(exitCode, 0);
assert.strictEqual(signal, null);
// No module wrapping at the first line
assert.strictEqual(
stdout.includes('> 1 var a = 1;'),
true,
'debugger should not have the module wrapper'
);
// No module wrapping at the end
assert.strictEqual(
stdout.includes('9 });'),
false,
'the last line of the debugger should not have the module wrapping ending'
);
}));