From fec6cbac9b0a5d435c4821a850b668ac930dfa2a Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Fri, 13 May 2016 22:34:06 -0400 Subject: [PATCH] Add eslint eqeqeq rule and expand the heaviest call stack on startup. --- .eslintrc.js | 3 +++ src/components/ProfileTreeView.js | 16 +++++++++++++++- src/components/TreeView.js | 16 ++++++++-------- src/function-info.js | 10 +++++----- src/reducers/index.js | 6 ++++-- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c728e7f3cd..5151fee80f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -43,6 +43,9 @@ module.exports = { "no-console": [ "error", { allow: ["log", "warn", "error"] } + ], + "eqeqeq": [ + "error" ] }, "settings": { diff --git a/src/components/ProfileTreeView.js b/src/components/ProfileTreeView.js index 901b418ae5..00f96f701c 100644 --- a/src/components/ProfileTreeView.js +++ b/src/components/ProfileTreeView.js @@ -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() { diff --git a/src/components/TreeView.js b/src/components/TreeView.js index d42b214b6b..7a7f65064d 100644 --- a/src/components/TreeView.js +++ b/src/components/TreeView.js @@ -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; } } @@ -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); @@ -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); } } diff --git a/src/function-info.js b/src/function-info.js index a1e70212f7..725bf53d54 100644 --- a/src/function-info.js +++ b/src/function-info.js @@ -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; }); } @@ -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])); @@ -194,7 +194,7 @@ export function getFunctionInfo(fullName) { functionName: cleanFunctionName(fullName), libraryName: '', lineInformation: '', - isRoot: fullName == '(root)', + isRoot: fullName === '(root)', isJSFrame: false, }; } diff --git a/src/reducers/index.js b/src/reducers/index.js index 92454e27c6..6828ea4363 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -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: