Reduce using of eval()

This commit is contained in:
YUKI Hiroshi 2015-11-05 19:12:21 +09:00
parent a029d82f18
commit 59fa80adf1

View File

@ -27,12 +27,20 @@ var TreeStyleTabWindowHelper = {
}; };
}, 'TreeStyleTab'); }, 'TreeStyleTab');
TreeStyleTabUtils.doPatching(nsBrowserAccess.prototype.openURI, 'nsBrowserAccess.prototype.openURI', function(aName, aSource) { nsBrowserAccess.prototype.__treesytletab__openURI = nsBrowserAccess.prototype.openURI;
return eval(aName+' = '+aSource.replace( nsBrowserAccess.prototype.openURI = function(aURI, aOpener, aWhere, aContext) {
/(switch\s*\(aWhere\))/, var where = aWhere;
'TreeStyleTabService.onBeforeBrowserAccessOpenURI(aOpener, aWhere, aContext); $1' if (where === Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW) {
)); let isExternal = aContext === Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL;
}, 'TreeStyleTab'); let overridePref = TreeStyleTabService.utils.getPref('browser.link.open_newwindow.override.external');
if (isExternal && overridePref !== null)
where = overridePref;
else
where = TreeStyleTabService.utils.getPref('browser.link.open_newwindow');
}
TreeStyleTabService.onBeforeBrowserAccessOpenURI(aOpener, where, aContext);
return this.__treesytletab__openURI.call(this, aURI, aOpener, aWhere, aContext);
};
nsBrowserAccess.prototype.__treesytletab__openURIInFrame = nsBrowserAccess.prototype.openURIInFrame; nsBrowserAccess.prototype.__treesytletab__openURIInFrame = nsBrowserAccess.prototype.openURIInFrame;
nsBrowserAccess.prototype.openURIInFrame = function(aURI, aParams, aWhere, aContext) { nsBrowserAccess.prototype.openURIInFrame = function(aURI, aParams, aWhere, aContext) {
@ -50,12 +58,11 @@ var TreeStyleTabWindowHelper = {
}, 'treeStyleTab'); }, 'treeStyleTab');
} }
TreeStyleTabUtils.doPatching(window.BrowserOpenTab, 'window.BrowserOpenTab', function(aName, aSource) { window.__treesytletab__BrowserOpenTab = window.BrowserOpenTab;
return eval(aName+' = '+aSource.replace( window.BrowserOpenTab = function(...aArgs) {
'openUILinkIn(', gBrowser.treeStyleTab.onBeforeNewTabCommand();
'gBrowser.treeStyleTab.onBeforeNewTabCommand(); $&' return this.__treesytletab__BrowserOpenTab.apply(this, aArgs);
)); };
}, 'treeStyleTab');
TreeStyleTabUtils.doPatching(window.undoCloseTab, 'window.undoCloseTab', function(aName, aSource) { TreeStyleTabUtils.doPatching(window.undoCloseTab, 'window.undoCloseTab', function(aName, aSource) {
return eval(aName+' = '+aSource.replace( return eval(aName+' = '+aSource.replace(
@ -189,19 +196,19 @@ var TreeStyleTabWindowHelper = {
return this.__treestyletab__viewBGImage.call(this, aEvent); return this.__treestyletab__viewBGImage.call(this, aEvent);
}; };
TreeStyleTabUtils.doPatching(nsContextMenu.prototype.addDictionaries, 'nsContextMenu.prototype.addDictionaries', function(aName, aSource) { nsContextMenu.prototype.__treestyletab__addDictionaries = nsContextMenu.prototype.addDictionaries;
return eval(aName+' = '+aSource.replace( nsContextMenu.prototype.addDictionaries = function() {
'openUILinkIn(', var newWindowPref = TreeStyleTabService.utils.getPref('browser.link.open_newwindow');
'TreeStyleTabService.onBeforeOpenLink(where, this.target.ownerDocument.defaultView); $&' var where = newWindowPref === 3 ? 'tab' : 'window' ;
)); TreeStyleTabService.onBeforeOpenLink(where, this.target.ownerDocument.defaultView);
}, 'TreeStyleTab'); return this.__treestyletab__addDictionaries.call(this, aEvent);
};
TreeStyleTabUtils.doPatching(BrowserSearch._loadSearch, 'BrowserSearch._loadSearch', function(aName, aSource) { BrowserSearch.__treestyletab__loadSearch = BrowserSearch._loadSearch;
return eval(aName+' = '+aSource.replace( BrowserSearch._loadSearch = function(aSearchText, aUseNewTab, aPurpose) {
'openLinkIn(', TreeStyleTabService.onBeforeBrowserSearch(aSearchText, aUseNewTab);
'TreeStyleTabService.onBeforeBrowserSearch(arguments[0], useNewTab); $&' return this.__treestyletab__loadSearch.call(this, aEvent);
)); };
}, 'TreeStyleTab');
TreeStyleTabUtils.doPatching(window.openLinkIn, 'window.openLinkIn', function(aName, aSource) { TreeStyleTabUtils.doPatching(window.openLinkIn, 'window.openLinkIn', function(aName, aSource) {
// Bug 1050447 changed this line in Fx 34 to // Bug 1050447 changed this line in Fx 34 to