From 7c9d845d9b8009fd00a3b2bc628ac8978ab6a202 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 12 Jul 2019 10:42:41 +0200 Subject: [PATCH] luci-base: luci.js: add Promise.finally polyfill Fixes: #2854 Signed-off-by: Jo-Philipp Wich --- .../luci-base/htdocs/luci-static/resources/luci.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 6659bc51b6..259679f137 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 */ -- 2.30.2