Skip to content

Commit

Permalink
debugger: refactor _debugger.js
Browse files Browse the repository at this point in the history
* `==` -> `===`
* use white space in array to improve readability

PR-URL: #9860
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Trott authored and Fishrock123 committed Dec 5, 2016
1 parent 346204d commit ac8d212
Showing 1 changed file with 32 additions and 22 deletions.
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

0 comments on commit ac8d212

Please sign in to comment.