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: refactor _debugger.js #9860

Closed
wants to merge 1 commit into from
Closed
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
54 changes: 32 additions & 22 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Client.prototype._addScript = function(desc) {
this.scripts[desc.id] = desc;
if (desc.name) {
desc.isNative = (desc.name.replace('.js', '') in natives) ||
desc.name == 'node.js';
desc.name === 'node.js';
}
};

Expand All @@ -202,7 +202,7 @@ Client.prototype._onResponse = function(res) {
var index = -1;

this._reqCallbacks.some(function(fn, i) {
if (fn.request_seq == res.body.request_seq) {
if (fn.request_seq === res.body.request_seq) {
cb = fn;
index = i;
return true;
Expand All @@ -212,25 +212,25 @@ Client.prototype._onResponse = function(res) {
var self = this;
var handled = false;

if (res.headers.Type == 'connect') {
if (res.headers.Type === 'connect') {
// Request a list of scripts for our own storage.
self.reqScripts();
self.emit('ready');
handled = true;

} else if (res.body && res.body.event == 'break') {
} else if (res.body && res.body.event === 'break') {
this.emit('break', res.body);
handled = true;

} else if (res.body && res.body.event == 'exception') {
} else if (res.body && res.body.event === 'exception') {
this.emit('exception', res.body);
handled = true;

} else if (res.body && res.body.event == 'afterCompile') {
} else if (res.body && res.body.event === 'afterCompile') {
this._addHandle(res.body.body.script);
handled = true;

} else if (res.body && res.body.event == 'scriptCollected') {
} else if (res.body && res.body.event === 'scriptCollected') {
// ???
this._removeScript(res.body.body.script);
handled = true;
Expand Down Expand Up @@ -328,7 +328,7 @@ Client.prototype.reqScopes = function(cb) {
Client.prototype.reqEval = function(expression, cb) {
var self = this;

if (this.currentFrame == NO_FRAME) {
if (this.currentFrame === NO_FRAME) {
// Only need to eval in global scope.
this.reqFrameEval(expression, NO_FRAME, cb);
return;
Expand Down Expand Up @@ -358,7 +358,7 @@ Client.prototype.reqEval = function(expression, cb) {

// Finds the first scope in the array in which the expression evals.
Client.prototype._reqFramesEval = function(expression, evalFrames, cb) {
if (evalFrames.length == 0) {
if (evalFrames.length === 0) {
// Just eval in global scope.
this.reqFrameEval(expression, NO_FRAME, cb);
return;
Expand All @@ -382,7 +382,7 @@ Client.prototype.reqFrameEval = function(expression, frame, cb) {
arguments: { expression: expression }
};

if (frame == NO_FRAME) {
if (frame === NO_FRAME) {
req.arguments.global = true;
} else {
req.arguments.frame = frame;
Expand Down Expand Up @@ -529,9 +529,9 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
var mirror;
var waiting = 1;

if (handle.className == 'Array') {
if (handle.className === 'Array') {
mirror = [];
} else if (handle.className == 'Date') {
} else if (handle.className === 'Date') {
mirror = new Date(handle.value);
} else {
mirror = {};
Expand Down Expand Up @@ -774,10 +774,20 @@ function Interface(stdin, stdout, args) {
process.once('SIGHUP', process.exit.bind(process, 0));

var proto = Interface.prototype;
const ignored = ['pause', 'resume', 'exitRepl', 'handleBreak',
'requireConnection', 'killChild', 'trySpawn',
'controlEval', 'debugEval', 'print', 'childPrint',
'clearline'];
const ignored = [
'pause',
'resume',
'exitRepl',
'handleBreak',
'requireConnection',
'killChild',
'trySpawn',
'controlEval',
'debugEval',
'print',
'childPrint',
'clearline'
];
const shortcut = {
'run': 'r',
'cont': 'c',
Expand Down Expand Up @@ -1097,14 +1107,14 @@ Interface.prototype.list = function(delta) {
var lineno = res.fromLine + i + 1;
if (lineno < from || lineno > to) continue;

const current = lineno == 1 + client.currentSourceLine;
const current = lineno === 1 + client.currentSourceLine;
const breakpoint = client.breakpoints.some(function(bp) {
return (bp.scriptReq === client.currentScript ||
bp.script === client.currentScript) &&
bp.line == lineno;
bp.line === lineno;
});

if (lineno == 1) {
if (lineno === 1) {
// The first line needs to have the module wrapper filtered out of
// it.
var wrapper = Module.wrapper[0];
Expand Down Expand Up @@ -1151,7 +1161,7 @@ Interface.prototype.backtrace = function() {
return;
}

if (bt.totalFrames == 0) {
if (bt.totalFrames === 0) {
self.print('(empty stack)');
} else {
const trace = [];
Expand Down Expand Up @@ -1193,10 +1203,10 @@ Interface.prototype.scripts = function() {
var script = client.scripts[id];
if (script !== null && typeof script === 'object' && script.name) {
if (displayNatives ||
script.name == client.currentScript ||
script.name === client.currentScript ||
!script.isNative) {
scripts.push(
(script.name == client.currentScript ? '* ' : ' ') +
(script.name === client.currentScript ? '* ' : ' ') +
id + ': ' +
path.basename(script.name)
);
Expand Down