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

Fix debugger and profiler functionality #4298

Closed
wants to merge 2 commits into from
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
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ Module.prototype._compile = function(content, filename) {
var wrapper = Module.wrap(content);

var compiledWrapper = runInThisContext(wrapper,
{ filename: filename, lineOffset: -1 });
{ filename: filename, lineOffset: 0 });
if (global.v8debug) {
if (!resolvedArgv) {
// we enter the repl if we're not given a filename argument.
Expand Down
4 changes: 2 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@
};

NativeModule.wrapper = [
'(function (exports, require, module, __filename, __dirname) {\n',
'(function (exports, require, module, __filename, __dirname) { ',
'\n});'
];

Expand All @@ -968,7 +968,7 @@

var fn = runInThisContext(source, {
filename: this.filename,
lineOffset: -1
lineOffset: 0
});
fn(this.exports, NativeModule.require, this, this.filename);

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/exports-function-with-param.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = function foo(arg) { return arg; }
18 changes: 18 additions & 0 deletions test/parallel/test-vm-debug-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ assert.strictEqual(vm.runInDebugContext(undefined), undefined);
assert.equal(breaks, 1);
})();

// Can set listeners and breakpoints on a single line file
(function() {
const Debug = vm.runInDebugContext('Debug');
const fn = require(common.fixturesDir + '/exports-function-with-param');
let called = false;

Debug.setListener(function(event, state, data) {
if (data.constructor.name === 'BreakEvent') {
called = true;
}
});

Debug.setBreakPoint(fn);
fn('foo');
assert.strictEqual(Debug.showBreakPoints(fn), '(arg) { [B0]return arg; }');
assert.strictEqual(called, true);
})();

// See https://github.com/nodejs/node/issues/1190, fatal errors should not
// crash the process.
var script = common.fixturesDir + '/vm-run-in-debug-context.js';
Expand Down
4 changes: 2 additions & 2 deletions test/sequential/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ assert.equal(42, require('../fixtures/utf8-bom.js'));
assert.equal(42, require('../fixtures/utf8-bom.json'));

// Error on the first line of a module should
// have the correct line and column number
// have the correct line number
assert.throws(function() {
require('../fixtures/test-error-first-line-offset.js');
}, function(err) {
return /test-error-first-line-offset.js:1:1/.test(err.stack);
return /test-error-first-line-offset.js:1:/.test(err.stack);
}, 'Expected appearance of proper offset in Error stack');