From 9be3c3493dc0cec6732747e7929b710d17c764e5 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Wed, 22 Oct 2014 03:00:12 +0900 Subject: [PATCH] Flatten deeply nested "setTimeout()" --- modules/browser.js | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/modules/browser.js b/modules/browser.js index a0893bfd..e91ddae0 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -4981,27 +4981,20 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, { if (this.timers['onTabsOnTopSyncCommand']) clearTimeout(this.timers['onTabsOnTopSyncCommand']); this.timers['onTabsOnTopSyncCommand'] = setTimeout((function() { - var cleanup = (function() { - this.windowService.tabsOnTopChangingByUI = false; - delete this.timers['onTabsOnTopSyncCommand']; - }).bind(this); - try { - this.windowService.toggleFixed(this.mTabBrowser); - setTimeout((function() { - try { - if (this.window.TabsOnTop.enabled != aEnabled) - this.window.TabsOnTop.enabled = aEnabled; - } - catch(e) { - this.defaultErrorHandler(e); - } - cleanup(); - }).bind(this), 0); - } - catch(e) { - this.defaultErrorHandler(e); - cleanup(); - } + Deferred.resolve() + .then((function() { + this.windowService.toggleFixed(this.mTabBrowser); + return wait(0); + }).bind(this)) + .then((function() { + if (this.window.TabsOnTop.enabled != aEnabled) + this.window.TabsOnTop.enabled = aEnabled; + }).bind(this)) + .catch(this.defaultErrorHandler.bind(this)) + .then((function() { + this.windowService.tabsOnTopChangingByUI = false; + delete this.timers['onTabsOnTopSyncCommand']; + }).bind(this)); }).bind(this), 0); },