Reduce use of eval()

This commit is contained in:
Piro / YUKI Hiroshi 2016-09-05 22:27:22 +09:00
parent d2e7ea5eba
commit 9f3c964b11

View File

@ -413,6 +413,7 @@ var TreeStyleTabWindowHelper = {
initTabbrowserMethods : function TSTWH_initTabbrowserMethods(aTabBrowser) initTabbrowserMethods : function TSTWH_initTabbrowserMethods(aTabBrowser)
{ {
var b = aTabBrowser; var b = aTabBrowser;
var { ExtendedImmutable } = Components.utils.import('resource://treestyletab-modules/lib/extended-immutable.js', {});
TreeStyleTabUtils.doPatching(b.moveTabForward, 'b.moveTabForward', function(aName, aSource) { TreeStyleTabUtils.doPatching(b.moveTabForward, 'b.moveTabForward', function(aName, aSource) {
return eval(aName+' = '+aSource.replace( return eval(aName+' = '+aSource.replace(
@ -500,15 +501,30 @@ var TreeStyleTabWindowHelper = {
return result; return result;
}; };
TreeStyleTabUtils.doPatching(b._beginRemoveTab, 'b._beginRemoveTab', function(aName, aSource) { if (!b._treestyletab__beginRemoveTab) {
return eval(aName+' = '+aSource.replace( b._treestyletab__beginRemoveTab = b._beginRemoveTab;
'if (this.tabs.length - this._removingTabs.length == 1) {', b._beginRemoveTab = function(aTab, ...aArgs) {
'if (this.tabs.length - this._removingTabs.length == 1 || this.treeStyleTab.shouldCloseLastTabSubtreeOf(aTab)) {' var originalRemovingTabs = this._removingTabs;
).replace( var self = this;
'this._removingTabs.length == 0', if (this.treeStyleTab.shouldCloseLastTabSubtreeOf(aTab)) {
'(this.treeStyleTab.shouldCloseLastTabSubtreeOf(aTab) || $&)' this._removingTabs = new ExtendedImmutable(originalRemovingTabs, {
)); get length() {
}, 'treeStyleTab'); // hack for https://dxr.mozilla.org/mozilla-central/rev/dbe4b47941c7b3d6298a0ead5e40dd828096c808/browser/base/content/tabbrowser.xml#2371
if (aTab.closing) // do nothing after the removing process is started
return originalRemovingTabs.length;
if (window.skipNextCanClose) // the end section of the "close window with last tab" block
return 0;
else
return self.tabs.length - 1; // the beginning of the "close window with last tab" block
}
});
}
var result = this._treestyletab__beginRemoveTab(aTab, ...aArgs);
this._removingTabs = originalRemovingTabs;
return result;
};
}
b.__treestyletab__removeCurrentTab = b.removeCurrentTab; b.__treestyletab__removeCurrentTab = b.removeCurrentTab;
b.removeCurrentTab = function(...aArgs) { b.removeCurrentTab = function(...aArgs) {