Skip to content

Commit

Permalink
Add eslint eqeqeq rule and expand the heaviest call stack on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstange committed May 14, 2016
1 parent 900d894 commit fec6cba
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ module.exports = {
"no-console": [
"error",
{ allow: ["log", "warn", "error"] }
],
"eqeqeq": [
"error"
]
},
"settings": {
Expand Down
16 changes: 15 additions & 1 deletion src/components/ProfileTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ class ProfileTreeView extends Component{
}

procureInterestingInitialSelection() {

// Expand the heaviest callstack up to a certain depth and select the frame
// at that depth.
const newExpandedFuncStacks = this.props.expandedFuncStacks.slice();
const maxInterestingDepth = 12; // scientifically determined
let currentFuncStack = this._tree.getRoots()[0];
newExpandedFuncStacks.push(currentFuncStack);
for (let i = 0; i < maxInterestingDepth; i++) {
const children = this._tree.getChildren(currentFuncStack);
if (children.length === 0)
break;
currentFuncStack = children[0];
newExpandedFuncStacks.push(currentFuncStack);
}
this.props.onExpandedFuncStacksChange(newExpandedFuncStacks);
this.props.onSelectedFuncStackChange(currentFuncStack);
}

render() {
Expand Down
16 changes: 8 additions & 8 deletions src/components/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ class TreeView extends Component {
return;

if (event.keyCode < 37 || event.keyCode > 40) {
if (event.keyCode != 0 ||
String.fromCharCode(event.charCode) != '*') {
if (event.keyCode !== 0 ||
String.fromCharCode(event.charCode) !== '*') {
return;
}
}
Expand All @@ -225,21 +225,21 @@ class TreeView extends Component {
return;
}

if (event.keyCode == 37) { // KEY_LEFT
if (event.keyCode === 37) { // KEY_LEFT
const isCollapsed = this._isCollapsed(selected);
if (!isCollapsed) {
this._toggle(selected);
} else {
const parent = this.props.tree.getParent(selected);
if (parent != -1) {
if (parent !== -1) {
this._select(parent);
}
}
} else if (event.keyCode == 38) { // KEY_UP
} else if (event.keyCode === 38) { // KEY_UP
if (selectedRowIndex > 0) {
this._select(visibleRows[selectedRowIndex - 1]);
}
} else if (event.keyCode == 39) { // KEY_RIGHT
} else if (event.keyCode === 39) { // KEY_RIGHT
const isCollapsed = this._isCollapsed(selected);
if (isCollapsed) {
this._toggle(selected);
Expand All @@ -249,11 +249,11 @@ class TreeView extends Component {
this._select(this.props.tree.getChildren(selected)[0]);
}
}
} else if (event.keyCode == 40) { // KEY_DOWN
} else if (event.keyCode === 40) { // KEY_DOWN
if (selectedRowIndex < visibleRows.length - 1) {
this._select(visibleRows[selectedRowIndex + 1]);
}
} else if (String.fromCharCode(event.charCode) == '*') {
} else if (String.fromCharCode(event.charCode) === '*') {
this._toggleAll(selected);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/function-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function cleanFunctionName(functionName) {

function addonWithID(addonID) {
return meta.addons.find(function addonHasID(addon) {
return addon.id.toLowerCase() == addonID.toLowerCase();
return addon.id.toLowerCase() === addonID.toLowerCase();
});
}

function findAddonForChromeURIHost(host) {
return meta.addons.find(function addonUsesChromeURIHost(addon) {
return addon.chromeURIHosts && addon.chromeURIHosts.indexOf(host) != -1;
return addon.chromeURIHosts && addon.chromeURIHosts.indexOf(host) !== -1;
});
}

Expand Down Expand Up @@ -47,14 +47,14 @@ function getAddonForScriptURI(url, host) {
return addonWithID(jetpackID);
}

if (url.startsWith('file:///') && url.indexOf('/extensions/') != -1) {
if (url.startsWith('file:///') && url.indexOf('/extensions/') !== -1) {
var unpackedAddonNameMatch = /\/extensions\/(.*?)\//.exec(url);
if (unpackedAddonNameMatch)
return addonWithID(decodeURIComponent(unpackedAddonNameMatch[1]));
return null;
}

if (url.startsWith('jar:file:///') && url.indexOf('/extensions/') != -1) {
if (url.startsWith('jar:file:///') && url.indexOf('/extensions/') !== -1) {
var packedAddonNameMatch = /\/extensions\/(.*?).xpi/.exec(url);
if (packedAddonNameMatch)
return addonWithID(decodeURIComponent(packedAddonNameMatch[1]));
Expand Down Expand Up @@ -194,7 +194,7 @@ export function getFunctionInfo(fullName) {
functionName: cleanFunctionName(fullName),
libraryName: '',
lineInformation: '',
isRoot: fullName == '(root)',
isRoot: fullName === '(root)',
isJSFrame: false,
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ function threadOrder(state = [], action) {

function selectedThread(state = 0, action) {
switch (action.type) {
case 'RECEIVE_PROFILE_FROM_ADDON':
return defaultThreadOrder(action.profile.threads)[0];
case 'RECEIVE_PROFILE_FROM_ADDON': {
const contentThreadId = action.profile.threads.findIndex(thread => thread.name === 'Content');
return contentThreadId !== -1 ? contentThreadId : defaultThreadOrder(action.profile.threads)[0];
}
case 'CHANGE_SELECTED_THREAD':
return action.selectedThread;
default:
Expand Down

0 comments on commit fec6cba

Please sign in to comment.