From: Jo-Philipp Wich Date: Fri, 12 Jul 2019 08:42:41 +0000 (+0200) Subject: luci-base: luci.js: add Promise.finally polyfill X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7c9d845d9b8009fd00a3b2bc628ac8978ab6a202;p=oweals%2Fluci.git luci-base: luci.js: add Promise.finally polyfill Fixes: #2854 Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 6659bc51b..259679f13 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -23,6 +23,20 @@ }); } + /* Promise.finally polyfill */ + if (typeof Promise.prototype.finally !== 'function') { + Promise.prototype.finally = function(fn) { + var onFinally = function(cb) { + return Promise.resolve(fn.call(this)).then(cb); + }; + + return this.then( + function(result) { return onFinally.call(this, function() { return result }) }, + function(reason) { return onFinally.call(this, function() { return Promise.reject(reason) }) } + ); + }; + } + /* * Class declaration and inheritance helper */