Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
feat: Add breakpoints command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Sep 8, 2016
1 parent 73272f9 commit 507a71d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions lib/node-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ function createCommandContext(inspector) {

setBreakpoint(script, line, condition, silent) {
function registerBreakpoint({ breakpointId, actualLocation }) {
if (actualLocation) {
handleBreakpointResolved({ breakpointId, location: actualLocation });
handleBreakpointResolved({ breakpointId, location: actualLocation });
if (actualLocation && actualLocation.scriptId) {
if (!silent) return ctx.list(5);
} else {
print(`Warning: script '${script}' was not loaded yet.`);
Expand Down Expand Up @@ -666,14 +666,32 @@ function createCommandContext(inspector) {
const urlRegex = `^(.*[\\/\\\\])?${escapedPath}$`;

return Debugger.setBreakpointByUrl({ urlRegex, lineNumber: line - 1, condition })
.then(registerBreakpoint);
.then(bp => {
// TODO: handle bp.locations in case the regex matches existing files
if (!bp.location) { // Fake it for now.
bp.actualLocation = { scriptUrl: `.*/${script}$`, lineNumber: line - 1 };
}
return registerBreakpoint(bp);
});
},

clearBreakpoint() {
// TODO: Use Debugger.removeBreakpoint({ breakpointId })
throw new Error('Not implemented');
},

get breakpoints() {
function formatLocation(location) {
if (!location) return '<unknown location>';
const script = scripts[location.scriptId];
const scriptUrl = script ? script.url : location.scriptUrl;
return `${getRelativePath(scriptUrl)}:${location.lineNumber}`;
}
knownBreakpoints.forEach((bp, idx) => {
print(`#${idx} ${formatLocation(bp.location)}`);
});
},

get cont() {
return Debugger.resume();
},
Expand Down Expand Up @@ -723,7 +741,7 @@ function createCommandContext(inspector) {

let isBreakpoint = false;
knownBreakpoints.forEach(({ location }) => {
if (location.scriptId === scriptId && (location.lineNumber + 1) === i) {
if (location && location.scriptId === scriptId && (location.lineNumber + 1) === i) {
isBreakpoint = true;
}
});
Expand Down

0 comments on commit 507a71d

Please sign in to comment.