This commit is contained in:
gorhill 2015-06-01 08:49:41 -04:00
parent 10740a28ff
commit d724fb23bd

View file

@ -609,13 +609,15 @@ vAPI.tabs._remove = function(tab, tabBrowser) {
/******************************************************************************/ /******************************************************************************/
vAPI.tabs.remove = function(tabId) { vAPI.tabs.remove = function(tabId) {
var tabs = tabWatcher.browserFromTabId(tabId); var browser = tabWatcher.browserFromTabId(tabId);
if ( tabs.length === 0 ) { if ( !browser ) {
return; return;
} }
for ( var tab of tabs ) { var tab = tabWatcher.tabFromBrowser(browser);
this._remove(tab, getTabBrowser(getOwnerWindow(tab))); if ( !tab ) {
return;
} }
this._remove(tab, getTabBrowser(getOwnerWindow(browser)));
}; };
/******************************************************************************/ /******************************************************************************/
@ -713,6 +715,25 @@ var tabWatcher = (function() {
return indexFromBrowser(browserFromTarget(target)); return indexFromBrowser(browserFromTarget(target));
}; };
var tabFromBrowser = function(browser) {
var i = indexFromBrowser(browser);
if ( i === -1 ) {
return null;
}
var win = getOwnerWindow(browser);
if ( !win ) {
return null;
}
var tabbrowser = getTabBrowser(win);
if ( !tabbrowser ) {
return null;
}
if ( !tabbrowser.tabs || i >= tabbrowser.tabs.length ) {
return null;
}
return tabbrowser.tabs[i];
};
var browserFromTarget = function(target) { var browserFromTarget = function(target) {
if ( !target ) { if ( !target ) {
return null; return null;
@ -921,7 +942,8 @@ var tabWatcher = (function() {
tabs: function() { return browserToTabIdMap.keys(); }, tabs: function() { return browserToTabIdMap.keys(); },
tabIdFromTarget: tabIdFromTarget, tabIdFromTarget: tabIdFromTarget,
browserFromTabId: browserFromTabId, browserFromTabId: browserFromTabId,
indexFromTarget: indexFromTarget indexFromTarget: indexFromTarget,
tabFromBrowser: tabFromBrowser
}; };
})(); })();