Style: added gjslint rules and fixed style issues

Created tools/gjslint.sh that can be used to automatically check for
conformance with Google coding style.

Added semicolons to the end of all statements where it was missing.

Fixed spacing inconsistencies.

Added missing type info to JsDoc comments in ScriptManager.js

Removed commas at end of object literals.

Wrapped extra long lines.
This commit is contained in:
Miroslav Bajtos 2013-05-29 09:00:59 +02:00
Родитель 9ccc2a6732
Коммит c05c203676
15 изменённых файлов: 134 добавлений и 112 удалений

Просмотреть файл

@ -1,6 +1,6 @@
// Wire up websocket to talk to backend
WebInspector.loaded = function() {
WebInspector.socket = io.connect("http://" + window.location.host + '/');
WebInspector.socket = io.connect('http://' + window.location.host + '/');
WebInspector.socket.on('message', onWebSocketMessage);
WebInspector.socket.on('error', function(error) { console.error(error); });
WebInspector.socket.on('connect', onWebSocketConnected);
@ -38,15 +38,15 @@ WebInspector._panelDescriptors = function() {
return panelDescriptors.filter(function(pd) {
return ['scripts', 'console'].indexOf(pd.name()) != -1;
});
}
};
// Patch the expression used as an initial value for a new watch.
// DevTools' value "\n" breaks the debugger protocol.
importScript("WatchExpressionsSidebarPane.js");
importScript('WatchExpressionsSidebarPane.js');
WebInspector.WatchExpressionsSection.NewWatchExpression = "''";
Preferences.localizeUI = false;
Preferences.applicationTitle = 'Node Inspector'
Preferences.applicationTitle = 'Node Inspector';
WebInspector._platformFlavor = WebInspector.PlatformFlavor.MacLeopard;
@ -57,22 +57,22 @@ WebInspector._platformFlavor = WebInspector.PlatformFlavor.MacLeopard;
// we can return arbitrary string as inspected URL.
WebInspector.WorkerManager._calculateWorkerInspectorTitle = function() {
InspectorFrontendHost.inspectedURLChanged('');
}
};
// Do not offer download of the edited file when saving changes to V8.
// DevTools' implementation changes window.location which closes
// web-socket connection to the server and thus breaks the inspector.
InspectorFrontendHost.close = function(url, content, forceSaveAs) {
delete this._fileBuffers[url];
}
};
// Front-end intercepts Cmd+R, Ctrl+R and F5 keys and reloads the debugged
// page instead of the front-end page. We want to disable this behaviour.
WebInspector._orig_documentKeyDown = WebInspector.documentKeyDown;
WebInspector.documentKeyDown = function(event) {
switch (event.keyIdentifier) {
case "U+0052": // R key
case "F5":
case 'U+0052': // R key
case 'F5':
return;
}
WebInspector._orig_documentKeyDown(event);

Просмотреть файл

@ -55,36 +55,41 @@ CallFramesProvider.prototype = {
location: {
scriptId: frame.func.scriptId.toString(),
lineNumber: frame.line,
columnNumber: frame.column,
columnNumber: frame.column
},
scopeChain: scopeChain,
this: convert.v8RefToInspectorObject(frame.receiver),
this: convert.v8RefToInspectorObject(frame.receiver)
});
});
},
_fetchScopes: function(frameIndex, done) {
this._debuggerClient.sendDebugRequest('scopes', { frameNumber: frameIndex }, function(error, responseBody, responseRefs) {
var scopeChain;
this._debuggerClient.sendDebugRequest(
'scopes',
{
frameNumber: frameIndex
},
function(error, responseBody, responseRefs) {
var scopeChain;
if (error) {
done(error);
return;
if (error) {
done(error);
return;
}
scopeChain = responseBody.scopes.map(function(scope) {
resolveReference(scope.object, responseRefs);
return {
object: convert.v8RefToInspectorObject(scope.object),
type: convert.v8ScopeTypeToString(scope.type)
};
});
done(null, scopeChain);
}
scopeChain = responseBody.scopes.map(function(scope) {
resolveReference(scope.object, responseRefs);
return {
object: convert.v8RefToInspectorObject(scope.object),
type: convert.v8ScopeTypeToString(scope.type),
};
});
done(null, scopeChain);
})
},
);
}
};
exports.CallFramesProvider = CallFramesProvider;
exports.CallFramesProvider = CallFramesProvider;

Просмотреть файл

@ -59,7 +59,7 @@ DebuggerAgent.prototype = {
type: 'scriptId',
target: convert.inspectorScriptIdToV8Id(params.location.scriptId),
line: params.location.lineNumber,
column: params.location.columnNumber,
column: params.location.columnNumber
};
this._session.sendDebugRequest('setbreakpoint', requestParams, function(error, response) {
@ -162,13 +162,13 @@ DebuggerAgent.prototype = {
else
sendResponse();
}.bind(this)
)
);
},
setPauseOnExceptions: function(params, done) {
var args = [
{ type: 'all', enabled: params.state == 'all' },
{ type: 'uncaught', enabled: params.state == 'uncaught' },
{ type: 'uncaught', enabled: params.state == 'uncaught' }
];
async.eachSeries(
@ -192,7 +192,7 @@ DebuggerAgent.prototype = {
target: convert.inspectorUrlToV8Name(params.url),
line: params.lineNumber,
column: params.columnNumber,
condition: params.condition,
condition: params.condition
};
this._session.sendDebugRequest('setbreakpoint', requestParams, function(error, response) {
@ -203,7 +203,7 @@ DebuggerAgent.prototype = {
done(null, {
breakpointId: response.breakpoint.toString(),
locations: response.actual_locations.map(convert.v8LocationToInspectorLocation),
locations: response.actual_locations.map(convert.v8LocationToInspectorLocation)
});
});
},
@ -238,7 +238,7 @@ DebuggerAgent.prototype = {
done();
},
evaluateOnCallFrame: function (params, done) {
evaluateOnCallFrame: function(params, done) {
var self = this;
var expression = params.expression;
var frame = Number(params.callFrameId);
@ -249,7 +249,7 @@ DebuggerAgent.prototype = {
expression: params.expression,
frame: frame
},
function (err, result) {
function(err, result) {
// Errors from V8 are actually just messages, so we need to fill them out a bit.
if (err) {
err = convert.v8ErrorToInspectorError(err);
@ -268,10 +268,10 @@ DebuggerAgent.prototype = {
this._session.sendDebugRequest(
'lookup',
{
handles: [ handle ],
includeSource: false,
handles: [handle],
includeSource: false
},
function (error, responseBody) {
function(error, responseBody) {
if (error) {
done(error);
} else {
@ -279,6 +279,6 @@ DebuggerAgent.prototype = {
}
}.bind(this));
}
}
};
exports.DebuggerAgent = DebuggerAgent;

Просмотреть файл

@ -10,7 +10,7 @@ function FrontendCommandHandler(sendResponseCb, session) {
}
FrontendCommandHandler.prototype = {
_initializeRegistry: function (session) {
_initializeRegistry: function(session) {
this._registerAgent('Debugger', new DebuggerAgent(session));
this._registerAgent('Runtime', new RuntimeAgent(session));
this._registerAgent('Page', new PageAgent(session));
@ -30,11 +30,11 @@ FrontendCommandHandler.prototype = {
this._registerQuery('Worker.canInspectWorkers', { result: false });
},
_registerAgent: function (name, agent) {
_registerAgent: function(name, agent) {
this._agents[name] = agent;
},
_registerNoopCommands: function () {
_registerNoopCommands: function() {
var i, fullMethodName;
for (i = 0; i < arguments.length; i++) {
fullMethodName = arguments[i];
@ -42,11 +42,11 @@ FrontendCommandHandler.prototype = {
}
},
_registerQuery: function (fullMethodName, result) {
_registerQuery: function(fullMethodName, result) {
this._specialCommands[fullMethodName] = { result: result };
},
handleCommand: function (messageObject) {
handleCommand: function(messageObject) {
var fullMethodName = messageObject.method,
domainAndMethod = fullMethodName.split('.'),
domainName = domainAndMethod[0],
@ -82,12 +82,12 @@ FrontendCommandHandler.prototype = {
}
method.call(agent, messageObject.params, function (error, result) {
method.call(agent, messageObject.params, function(error, result) {
this._handleMethodResult(messageObject.id, fullMethodName, error, result);
}.bind(this));
},
_handleMethodResult: function (requestId, fullMethodName, error, result) {
_handleMethodResult: function(requestId, fullMethodName, error, result) {
var response;
if (!requestId) {
@ -104,6 +104,6 @@ FrontendCommandHandler.prototype = {
this._sendResponse(response);
}
}
};
exports.FrontendCommandHandler = FrontendCommandHandler;

Просмотреть файл

@ -43,7 +43,7 @@ PageAgent.prototype = {
_isNodeInspectorScript: true
},
resources: [
],
]
}
});
},
@ -54,7 +54,7 @@ PageAgent.prototype = {
'scripts',
{
filter: scriptName,
includeSource: true,
includeSource: true
},
function convertScriptsToResourceContent(err, result) {
var script;
@ -68,7 +68,7 @@ PageAgent.prototype = {
content: script.source
});
}
)
);
},
reload: function(params, done) {

Просмотреть файл

@ -20,7 +20,7 @@ RuntimeAgent.prototype = {
expression: params.expression,
global: true
},
function (err, result) {
function(err, result) {
// Errors from V8 are actually just messages, so we need to fill them out a bit.
if (err) {
err = convert.v8ErrorToInspectorError(err);
@ -46,7 +46,7 @@ RuntimeAgent.prototype = {
{
expression: expression,
global: true,
additional_context: [
additional_context: [
{ name: SELF_CONTEXT_NAME, handle: Number(params.objectId) }
]
},
@ -74,7 +74,7 @@ RuntimeAgent.prototype = {
getProperties: function(params, done) {
var handle = parseInt(params.objectId, 10);
var request = { handles: [ handle ], includeSource: false };
var request = { handles: [handle], includeSource: false };
this._session.sendDebugRequest('lookup', request, function(error, responseBody, responseRefs) {
var obj,
proto,
@ -94,7 +94,7 @@ RuntimeAgent.prototype = {
var ref = responseRefs[p.ref];
return {
name: String(p.name),
value: convert.v8ResultToInspectorResult(ref),
value: convert.v8ResultToInspectorResult(ref)
};
});
}
@ -102,13 +102,13 @@ RuntimeAgent.prototype = {
if (proto)
props.push({
name: '__proto__',
value: convert.v8RefToInspectorObject(responseRefs[proto.ref]),
value: convert.v8RefToInspectorObject(responseRefs[proto.ref])
});
done(null, { result: props });
}
)
;
);
},
releaseObjectGroup: function(params, done) {

Просмотреть файл

@ -2,8 +2,8 @@ var events = require('events'),
convert = require('./convert.js');
/**
* @param hiddenScripts List of scripts that are not displayed to the user.
* @returns {ScriptManager}
* @param {Array.<string>} hiddenScripts List of scripts that are not displayed to the user.
* @return {ScriptManager}
* @constructor
*/
function ScriptManager(hiddenScripts) {
@ -34,8 +34,8 @@ ScriptManager.prototype = Object.create(events.EventEmitter.prototype, {
findScriptByID: {
/**
* @param id script id
* @returns {{hidden: boolean, path: string, url: string}}
* @param {string} id script id.
* @return {{hidden: boolean, path: string, url: string}}
*/
value: function(id) {
return this._sources[id];
@ -48,7 +48,7 @@ ScriptManager.prototype = Object.create(events.EventEmitter.prototype, {
scriptId: String(v8data.id),
url: convert.v8NameToInspectorUrl(v8data.name),
startLine: v8data.lineOffset,
startColumn: v8data.columnOffset,
startColumn: v8data.columnOffset
/* Properties not set:
endLine: undefined,
@ -63,7 +63,7 @@ ScriptManager.prototype = Object.create(events.EventEmitter.prototype, {
item = {
hidden: hidden,
v8name: v8data.name,
url: inspectorScriptData.url,
url: inspectorScriptData.url
};
this._sources[inspectorScriptData.scriptId] = item;
@ -77,7 +77,7 @@ ScriptManager.prototype = Object.create(events.EventEmitter.prototype, {
value: function() {
this._sources = {};
}
},
}
});
exports.ScriptManager = ScriptManager;

Просмотреть файл

@ -2,9 +2,9 @@ exports.v8LocationToInspectorLocation = function(v8loc) {
return {
scriptId: v8loc.script_id.toString(),
lineNumber: v8loc.line,
columnNumber: v8loc.column,
}
}
columnNumber: v8loc.column
};
};
// Conversions between v8 file paths and node-inspector urls
@ -29,7 +29,7 @@ exports.v8NameToInspectorUrl = function(v8name) {
}
return v8name;
}
};
exports.inspectorUrlToV8Name = function(url) {
var path = url.replace(/^file:\/\//, '');
@ -41,7 +41,7 @@ exports.inspectorUrlToV8Name = function(url) {
return '\\\\' + path.replace(/\//g, '\\'); // Windows UNC path
return url;
}
};
exports.v8ScopeTypeToString = function(v8ScopeType) {
switch (v8ScopeType) {
@ -58,7 +58,7 @@ exports.v8ScopeTypeToString = function(v8ScopeType) {
default:
return 'unknown';
}
}
};
exports.v8RefToInspectorObject = function(ref) {
var desc = '',
@ -93,9 +93,9 @@ exports.v8RefToInspectorObject = function(ref) {
type: ref.type,
objectId: ref.handle.toString(),
className: ref.className,
description: desc,
description: desc
};
}
};
exports.v8ErrorToInspectorError = function(message) {
var nameMatch = /^([^:]+):/.exec(message);
@ -106,7 +106,7 @@ exports.v8ErrorToInspectorError = function(message) {
className: nameMatch ? nameMatch[1] : 'Error',
description: message
};
}
};
exports.v8ResultToInspectorResult = function(result) {
if (result.type === 'object' || result.type === 'function') {
@ -118,7 +118,7 @@ exports.v8ResultToInspectorResult = function(result) {
value: result.value,
description: String(result.text)
};
}
};
exports.v8FunctionLookupToFunctionDetails = function(handleData) {
return {
@ -134,15 +134,15 @@ exports.v8FunctionLookupToFunctionDetails = function(handleData) {
// details :( // We need to issue `scopes` request to fetch scopes
// details, but we don't have frame number where the function was defined.
// Let's leave the scopeChain empty for now.
scopeChain: [],
scopeChain: []
}
};
}
};
exports.v8ScriptIdToInspectorId = function(scriptId) {
return String(scriptId);
}
};
exports.inspectorScriptIdToV8Id = function(scriptId) {
return Number(scriptId);
}
};

Просмотреть файл

@ -22,7 +22,7 @@ function getDebuggerPort(url, defaultPort) {
function createSession(debuggerPort) {
var session = Session.create(debuggerPort, config);
session.on('ws_closed', function () {
session.on('ws_closed', function() {
session.close();
});
return session;
@ -55,13 +55,13 @@ DebugServer.prototype.start = function(options) {
this.wsServer = ws;
httpServer.on('listening', handleServerListening);
httpServer.listen(config.webPort, config.webHost);
}
};
DebugServer.prototype.close = function() {
if (this.wsServer) {
this.wsServer.close();
this.emit('close');
}
}
};
exports.DebugServer = DebugServer;

Просмотреть файл

@ -88,7 +88,7 @@ exports.create = function(debuggerPort, config) {
debug.sendDebugRequest(
'clearbreakpoint',
{ breakpoint: sessionInstance.continueToLocationBreakpointId },
function(err, result){
function(err, result) {
if (err)
sendLogToConsole('warning', err);
else
@ -217,12 +217,12 @@ exports.create = function(debuggerPort, config) {
// disconnected from the debugged application
removeAllBreakpoints,
reloadScripts,
sendBacktraceIfPaused,
sendBacktraceIfPaused
]);
}
sessionInstance = Object.create(events.EventEmitter.prototype, {
continueToLocationBreakpointId: { writable:true, value: null },
continueToLocationBreakpointId: { writable: true, value: null },
callbackForNextBreak: {
get: function() { return callbackForNextBreak; },
set: function(value) {
@ -248,7 +248,7 @@ exports.create = function(debuggerPort, config) {
// code cleanup. We should probably extract CallFramesProvider
// as a dependency for Agents or move this method to debugger client
fetchCallFrames: {
value: function (done) {
value: function(done) {
new CallFramesProvider(debug).fetchCallFrames(done);
}
},
@ -271,7 +271,7 @@ exports.create = function(debuggerPort, config) {
var closeReason = 'Debugged process exited.';
debug = debugr.attachDebugger(debuggerPort);
debug.on('break', breakEvent);
debug.on('afterCompile', onAfterCompile)
debug.on('afterCompile', onAfterCompile);
debug.on('close', function() {
//TODO determine proper close behavior
debug = {
@ -538,7 +538,7 @@ exports.create = function(debuggerPort, config) {
conn = null;
});
}
},
}
});
frontendCommandHandler = new FrontendCommandHandler(

Просмотреть файл

@ -16,16 +16,25 @@ describe('CallFramesProvider', function() {
expect(callFrames).to.have.length.least(2);
function objectValueWithId(id, className) {
return {
type: 'object',
objectId: id,
className: className || 'Object',
description: 'Object'
};
}
assertFrame({
callFrameId: '0',
functionName: 'MyObj.myFunc',
location: {scriptId: '28', lineNumber: 7, columnNumber: 4},
scopeChain: [
{ object: { type: 'object', objectId: '-1', className: 'Object', description: 'Object'}, type: 'local' },
{ object: { type: 'object', objectId: '-2', className: 'Object', description: 'Object'}, type: 'closure' },
{ object: { type: 'object', objectId: '90', className: 'Object', description: 'Object'}, type: 'global' },
{ object: objectValueWithId('-1'), type: 'local' },
{ object: objectValueWithId('-2'), type: 'closure' },
{ object: objectValueWithId('90'), type: 'global' }
],
'this': {type: 'object', objectId: '1', className: 'Object', description: 'Object'},
'this': objectValueWithId('1')
},
callFrames[0],
'frame[0]');
@ -35,11 +44,11 @@ describe('CallFramesProvider', function() {
functionName: 'globalFunc',
location: {scriptId: '28', lineNumber: 12, columnNumber: 6},
scopeChain: [
{ object: { type: 'object', objectId: '-3', className: 'Object', description: 'Object'}, type: 'local' },
{ object: { type: 'object', objectId: '-4', className: 'Object', description: 'Object'}, type: 'closure' },
{ object: { type: 'object', objectId: '90', className: 'Object', description: 'Object'}, type: 'global' },
{ object: objectValueWithId('-3'), type: 'local' },
{ object: objectValueWithId('-4'), type: 'closure' },
{ object: objectValueWithId('90'), type: 'global' }
],
'this': {type: 'object', objectId: '10', className: 'global', description: 'Object'},
'this': objectValueWithId('10', 'global')
},
callFrames[1],
'frame[1]');
@ -51,8 +60,10 @@ describe('CallFramesProvider', function() {
});
function assertFrame(expected, actual, frameName) {
expect(actual.callFrameId, frameName + '.callFrameId').to.equal(expected.callFrameId);
expect(actual.functionName, frameName + '.functionName').to.equal(expected.functionName);
expect(actual.callFrameId, frameName + '.callFrameId')
.to.equal(expected.callFrameId);
expect(actual.functionName, frameName + '.functionName')
.to.equal(expected.functionName);
assertJSONEqual(expected.location, actual.location, frameName + '.location');
assertScopeChain(expected.scopeChain, actual.scopeChain, frameName + '.scopeChain');
assertJSONEqual(expected.this, actual.this, frameName + '.this');

Просмотреть файл

@ -29,7 +29,7 @@ describe('RuntimeAgent', function() {
{
objectId: MYFUNC_LOCAL_SCOPE_ID
},
function (error, result) {
function(error, result) {
if (error)
done(error);
@ -55,7 +55,7 @@ describe('RuntimeAgent', function() {
done();
});
})
});
});
});
@ -73,7 +73,7 @@ describe('RuntimeAgent', function() {
functionDeclaration: getCompletions.toString(),
returnByValue: true
},
function (err, response) {
function(err, response) {
if (err) {
done(err);
return;
@ -91,7 +91,7 @@ describe('RuntimeAgent', function() {
{
expression: 'console'
},
function (err, response) {
function(err, response) {
if (err) {
done(err);
return;
@ -102,18 +102,18 @@ describe('RuntimeAgent', function() {
);
}
});
})
});
});
// copied from front-end/RuntimeModel.js
// copied from front-end/RuntimeModel.js and replaced " with '
function getCompletions(primitiveType) {
var object;
if (primitiveType === "string")
object = new String("");
else if (primitiveType === "number")
if (primitiveType === 'string')
object = new String('');
else if (primitiveType === 'number')
object = new Number(0);
else if (primitiveType === "boolean")
else if (primitiveType === 'boolean')
object = new Boolean(false);
else
object = this;

Просмотреть файл

@ -26,5 +26,5 @@ describe('ScriptManager', function() {
manager.reset();
expect(manager.findScriptByID('id')).to.be.undefined;
});
})
});
});

Просмотреть файл

@ -100,7 +100,7 @@ describe('convert', function() {
handle: 0,
type: 'object',
className: 'Object',
text: '#<MyObject>',
text: '#<MyObject>'
};
expect(convert.v8RefToInspectorObject(ref).description).to.equal('MyObject');
@ -133,7 +133,7 @@ describe('convert', function() {
{ name: '1' },
{ name: '3' },
{ name: 'length' },
{ name: 'parent' },
{ name: 'parent' }
]
};

6
tools/gjslint.sh Executable file
Просмотреть файл

@ -0,0 +1,6 @@
#!/bin/bash
gjslint \
--nojsdoc --max_line_length=105 \
-r lib -r front-end/node -r test \
| grep -v "No docs found for member '" # fix --nojsdoc bug in v2.3.10