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

Commit

Permalink
feat: Add setBreakpoint(line)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Sep 8, 2016
1 parent 82362ac commit 7064cce
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/node-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ function toCallback(promise, callback) {
.then(callback.bind(null, null), callback);
}

function unpackError({ code, message, data }) {
const err = new Error(`${message} - ${data}`);
err.code = code;
Error.captureStackTrace(err, unpackError);
return err;
}

class Client extends events.EventEmitter {
constructor() {
super();
Expand Down Expand Up @@ -374,7 +381,7 @@ class Client extends events.EventEmitter {
return new Promise((resolve, reject) => {
const data = { id: ++this._lastId, method, params };
this._pending[data.id] = (error, result) => {
if (error) reject(error);
if (error) reject(unpackError(error));
else resolve(isEmpty(result) ? undefined : result);
};
const json = JSON.stringify(data);
Expand Down Expand Up @@ -470,7 +477,7 @@ function createCommandContext(inspector) {
const scripts = {};
const watchedExpressions = [];

const breakPoints = new Map();
const knownBreakpoints = new Map();

// Clear current line
function clearline() {
Expand Down Expand Up @@ -529,7 +536,7 @@ function createCommandContext(inspector) {

setBreakpoint(script, line, condition, silent) {
const registerBreakpoint = ({ breakpointId, actualLocation }) => {
breakPoints.set(breakpointId, actualLocation);
knownBreakpoints.set(breakpointId, actualLocation);
};

// setBreakpoint()
Expand All @@ -538,6 +545,15 @@ function createCommandContext(inspector) {
return Debugger.setBreakpoint({ location: currentSourceLocation, condition })
.then(registerBreakpoint);
}

// setBreakpoint(line)
if (line === undefined && typeof script === 'number') {
const location = Object.assign({}, currentSourceLocation, {
lineNumber: script - 1,
});
return Debugger.setBreakpoint({ location, condition })
.then(registerBreakpoint);
}
throw new Error('Not implemented');
},

Expand Down Expand Up @@ -589,7 +605,7 @@ function createCommandContext(inspector) {
}

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

0 comments on commit 7064cce

Please sign in to comment.