Reduce use of eval()
This commit is contained in:
parent
d1e63100d9
commit
979b38480e
@ -405,60 +405,42 @@ var TreeStyleTabWindowHelper = {
|
|||||||
var b = aTabBrowser;
|
var b = aTabBrowser;
|
||||||
var { ExtendedImmutable } = Components.utils.import('resource://treestyletab-modules/lib/extended-immutable.js', {});
|
var { ExtendedImmutable } = Components.utils.import('resource://treestyletab-modules/lib/extended-immutable.js', {});
|
||||||
|
|
||||||
TreeStyleTabUtils.doPatching(b.moveTabForward, 'b.moveTabForward', function(aName, aSource) {
|
b.__treestyletab__moveTabForward = b.moveTabForward;
|
||||||
return eval(aName+' = '+aSource.replace(
|
b.moveTabForward = function(...aArgs) {
|
||||||
'if (nextTab)',
|
let originalNextTab = this.treeStyleTab.getNextTab(this.mCurrentTab);
|
||||||
'(function() {\n' +
|
let nextTab = originalNextTab;
|
||||||
' let descendants = this.treeStyleTab.getDescendantTabs(this.mCurrentTab);\n' +
|
|
||||||
' if (descendants.indexOf(nextTab) > -1) {\n' +
|
|
||||||
' let lastDescendant = this.treeStyleTab.getLastDescendantTab(this.mCurrentTab);\n' +
|
|
||||||
' nextTab = this.treeStyleTab.getNextVisibleTab(lastDescendant || this.mCurrentTab);\n' +
|
|
||||||
' }\n' +
|
|
||||||
' if (this.treeStyleTab.hasChildTabs(nextTab) && this.treeStyleTab.isSubtreeCollapsed(nextTab)) {\n' +
|
|
||||||
' nextTab = this.treeStyleTab.getLastDescendantTab(nextTab);\n' +
|
|
||||||
' }\n' +
|
|
||||||
'}).call(this);' +
|
|
||||||
'$&'
|
|
||||||
).replace(
|
|
||||||
'this.moveTabToStart();',
|
|
||||||
'(function() {\n' +
|
|
||||||
' this.treeStyleTab.internallyTabMovingCount++;\n' +
|
|
||||||
' let parentTab = this.treeStyleTab.getParentTab(this.mCurrentTab);\n' +
|
|
||||||
' if (parentTab) {\n' +
|
|
||||||
' this.moveTabTo(this.mCurrentTab, this.treeStyleTab.getFirstChildTab(parentTab)._tPos);\n' +
|
|
||||||
' this.mCurrentTab.focus();\n' +
|
|
||||||
' }\n' +
|
|
||||||
' else {\n' +
|
|
||||||
' $&\n' +
|
|
||||||
' }\n' +
|
|
||||||
' this.treeStyleTab.internallyTabMovingCount--;\n' +
|
|
||||||
'}).call(this);'
|
|
||||||
));
|
|
||||||
}, 'treeStyleTab');
|
|
||||||
|
|
||||||
TreeStyleTabUtils.doPatching(b.moveTabBackward, 'b.moveTabBackward', function(aName, aSource) {
|
let descendants = this.treeStyleTab.getDescendantTabs(this.mCurrentTab);
|
||||||
return eval(aName+' = '+aSource.replace(
|
if (descendants.indexOf(nextTab) > -1) {
|
||||||
'if (previousTab)',
|
let lastDescendant = this.treeStyleTab.getLastDescendantTab(this.mCurrentTab);
|
||||||
'(function() {\n' +
|
nextTab = this.treeStyleTab.getNextVisibleTab(lastDescendant || this.mCurrentTab);
|
||||||
' previousTab = this.treeStyleTab.getPreviousVisibleTab(this.mCurrentTab);\n' +
|
}
|
||||||
'}).call(this);' +
|
if (this.treeStyleTab.hasChildTabs(nextTab) && this.treeStyleTab.isSubtreeCollapsed(nextTab)) {
|
||||||
'$&'
|
nextTab = this.treeStyleTab.getLastDescendantTab(nextTab);
|
||||||
).replace(
|
}
|
||||||
'this.moveTabToEnd();',
|
|
||||||
'(function() {\n' +
|
if (nextTab == originalNextTab)
|
||||||
' this.treeStyleTab.internallyTabMovingCount++;\n' +
|
return this.__treestyletab__moveTabForward(...aArgs);
|
||||||
' let parentTab = this.treeStyleTab.getParentTab(this.mCurrentTab);\n' +
|
|
||||||
' if (parentTab) {\n' +
|
if (nextTab)
|
||||||
' this.moveTabTo(this.mCurrentTab, this.treeStyleTab.getLastChildTab(parentTab)._tPos);\n' +
|
this.moveTabTo(this.mCurrentTab, nextTab._tPos);
|
||||||
' this.mCurrentTab.focus();\n' +
|
else if (this.arrowKeysShouldWrap)
|
||||||
' }\n' +
|
this.moveTabToStart();
|
||||||
' else {\n' +
|
};
|
||||||
' $&\n' +
|
|
||||||
' }\n' +
|
b.__treestyletab__moveTabBackward = b.moveTabBackward;
|
||||||
' this.treeStyleTab.internallyTabMovingCount--;\n' +
|
b.moveTabBackward = function(...aArgs) {
|
||||||
'}).call(this);'
|
let originalPreviousTab = this.treeStyleTab.getPreviousTab(this.mCurrentTab);
|
||||||
));
|
let previousTab = this.treeStyleTab.getPreviousVisibleTab(this.mCurrentTab);
|
||||||
}, 'treeStyleTab');
|
|
||||||
|
if (previousTab == originalPreviousTab)
|
||||||
|
return this.__treestyletab__moveTabBackward(...aArgs);
|
||||||
|
|
||||||
|
if (previousTab)
|
||||||
|
this.moveTabTo(this.mCurrentTab, previousTab._tPos);
|
||||||
|
else if (this.arrowKeysShouldWrap)
|
||||||
|
this.moveTabToStart();
|
||||||
|
};
|
||||||
|
|
||||||
b.__treestyletab__loadTabs = b.loadTabs;
|
b.__treestyletab__loadTabs = b.loadTabs;
|
||||||
b.loadTabs = function(aURIs, aLoadInBackground, aReplace, ...aArgs) {
|
b.loadTabs = function(aURIs, aLoadInBackground, aReplace, ...aArgs) {
|
||||||
|
Loading…
Reference in New Issue
Block a user