Browse Source

debugger: refactor _debugger.js

* `==` -> `===`
* use white space in array to improve readability

PR-URL: https://github.com/nodejs/node/pull/9860
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
v6
Rich Trott 8 years ago
parent
commit
34a6c858bd
  1. 54
      lib/_debugger.js

54
lib/_debugger.js

@ -187,7 +187,7 @@ Client.prototype._addScript = function(desc) {
this.scripts[desc.id] = desc; this.scripts[desc.id] = desc;
if (desc.name) { if (desc.name) {
desc.isNative = (desc.name.replace('.js', '') in natives) || desc.isNative = (desc.name.replace('.js', '') in natives) ||
desc.name == 'node.js'; desc.name === 'node.js';
} }
}; };
@ -202,7 +202,7 @@ Client.prototype._onResponse = function(res) {
var index = -1; var index = -1;
this._reqCallbacks.some(function(fn, i) { this._reqCallbacks.some(function(fn, i) {
if (fn.request_seq == res.body.request_seq) { if (fn.request_seq === res.body.request_seq) {
cb = fn; cb = fn;
index = i; index = i;
return true; return true;
@ -212,25 +212,25 @@ Client.prototype._onResponse = function(res) {
var self = this; var self = this;
var handled = false; var handled = false;
if (res.headers.Type == 'connect') { if (res.headers.Type === 'connect') {
// Request a list of scripts for our own storage. // Request a list of scripts for our own storage.
self.reqScripts(); self.reqScripts();
self.emit('ready'); self.emit('ready');
handled = true; handled = true;
} else if (res.body && res.body.event == 'break') { } else if (res.body && res.body.event === 'break') {
this.emit('break', res.body); this.emit('break', res.body);
handled = true; handled = true;
} else if (res.body && res.body.event == 'exception') { } else if (res.body && res.body.event === 'exception') {
this.emit('exception', res.body); this.emit('exception', res.body);
handled = true; handled = true;
} else if (res.body && res.body.event == 'afterCompile') { } else if (res.body && res.body.event === 'afterCompile') {
this._addHandle(res.body.body.script); this._addHandle(res.body.body.script);
handled = true; handled = true;
} else if (res.body && res.body.event == 'scriptCollected') { } else if (res.body && res.body.event === 'scriptCollected') {
// ??? // ???
this._removeScript(res.body.body.script); this._removeScript(res.body.body.script);
handled = true; handled = true;
@ -328,7 +328,7 @@ Client.prototype.reqScopes = function(cb) {
Client.prototype.reqEval = function(expression, cb) { Client.prototype.reqEval = function(expression, cb) {
var self = this; var self = this;
if (this.currentFrame == NO_FRAME) { if (this.currentFrame === NO_FRAME) {
// Only need to eval in global scope. // Only need to eval in global scope.
this.reqFrameEval(expression, NO_FRAME, cb); this.reqFrameEval(expression, NO_FRAME, cb);
return; return;
@ -358,7 +358,7 @@ Client.prototype.reqEval = function(expression, cb) {
// Finds the first scope in the array in which the expression evals. // Finds the first scope in the array in which the expression evals.
Client.prototype._reqFramesEval = function(expression, evalFrames, cb) { Client.prototype._reqFramesEval = function(expression, evalFrames, cb) {
if (evalFrames.length == 0) { if (evalFrames.length === 0) {
// Just eval in global scope. // Just eval in global scope.
this.reqFrameEval(expression, NO_FRAME, cb); this.reqFrameEval(expression, NO_FRAME, cb);
return; return;
@ -382,7 +382,7 @@ Client.prototype.reqFrameEval = function(expression, frame, cb) {
arguments: { expression: expression } arguments: { expression: expression }
}; };
if (frame == NO_FRAME) { if (frame === NO_FRAME) {
req.arguments.global = true; req.arguments.global = true;
} else { } else {
req.arguments.frame = frame; req.arguments.frame = frame;
@ -529,9 +529,9 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
var mirror; var mirror;
var waiting = 1; var waiting = 1;
if (handle.className == 'Array') { if (handle.className === 'Array') {
mirror = []; mirror = [];
} else if (handle.className == 'Date') { } else if (handle.className === 'Date') {
mirror = new Date(handle.value); mirror = new Date(handle.value);
} else { } else {
mirror = {}; mirror = {};
@ -774,10 +774,20 @@ function Interface(stdin, stdout, args) {
process.once('SIGHUP', process.exit.bind(process, 0)); process.once('SIGHUP', process.exit.bind(process, 0));
var proto = Interface.prototype; var proto = Interface.prototype;
const ignored = ['pause', 'resume', 'exitRepl', 'handleBreak', const ignored = [
'requireConnection', 'killChild', 'trySpawn', 'pause',
'controlEval', 'debugEval', 'print', 'childPrint', 'resume',
'clearline']; 'exitRepl',
'handleBreak',
'requireConnection',
'killChild',
'trySpawn',
'controlEval',
'debugEval',
'print',
'childPrint',
'clearline'
];
const shortcut = { const shortcut = {
'run': 'r', 'run': 'r',
'cont': 'c', 'cont': 'c',
@ -1097,14 +1107,14 @@ Interface.prototype.list = function(delta) {
var lineno = res.fromLine + i + 1; var lineno = res.fromLine + i + 1;
if (lineno < from || lineno > to) continue; 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) { const breakpoint = client.breakpoints.some(function(bp) {
return (bp.scriptReq === client.currentScript || return (bp.scriptReq === client.currentScript ||
bp.script === 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 // The first line needs to have the module wrapper filtered out of
// it. // it.
var wrapper = Module.wrapper[0]; var wrapper = Module.wrapper[0];
@ -1151,7 +1161,7 @@ Interface.prototype.backtrace = function() {
return; return;
} }
if (bt.totalFrames == 0) { if (bt.totalFrames === 0) {
self.print('(empty stack)'); self.print('(empty stack)');
} else { } else {
const trace = []; const trace = [];
@ -1193,10 +1203,10 @@ Interface.prototype.scripts = function() {
var script = client.scripts[id]; var script = client.scripts[id];
if (script !== null && typeof script === 'object' && script.name) { if (script !== null && typeof script === 'object' && script.name) {
if (displayNatives || if (displayNatives ||
script.name == client.currentScript || script.name === client.currentScript ||
!script.isNative) { !script.isNative) {
scripts.push( scripts.push(
(script.name == client.currentScript ? '* ' : ' ') + (script.name === client.currentScript ? '* ' : ' ') +
id + ': ' + id + ': ' +
path.basename(script.name) path.basename(script.name)
); );

Loading…
Cancel
Save