diff --git a/packages/uni-app-plus/dist/index.js b/packages/uni-app-plus/dist/index.js index 7aa090e0814b67627c7b3a8e56d1fc3cf341a8c2..2d04e0847d3e169823d11ef3ed217cbc6317fdd1 100644 --- a/packages/uni-app-plus/dist/index.js +++ b/packages/uni-app-plus/dist/index.js @@ -235,13 +235,15 @@ const SYNC_API_RE = const CONTEXT_API_RE = /^create|Manager$/; +const ASYNC_API = ['createBLEConnection']; + const CALLBACK_API_RE = /^on/; function isContextApi (name) { return CONTEXT_API_RE.test(name) } function isSyncApi (name) { - return SYNC_API_RE.test(name) + return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1 } function isCallbackApi (name) { @@ -266,6 +268,19 @@ function shouldPromise (name) { return true } +/* eslint-disable no-extend-native */ +if (!Promise.prototype.finally) { + Promise.prototype.finally = function (callback) { + const promise = this.constructor; + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + }; +} + function promisify (name, api) { if (!shouldPromise(name)) { return api @@ -279,18 +294,6 @@ function promisify (name, api) { success: resolve, fail: reject }), ...params); - /* eslint-disable no-extend-native */ - if (!Promise.prototype.finally) { - Promise.prototype.finally = function (callback) { - const promise = this.constructor; - return this.then( - value => promise.resolve(callback()).then(() => value), - reason => promise.resolve(callback()).then(() => { - throw reason - }) - ) - }; - } }))) } } diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index ede7974eaa96e95a876c13976399f24daebed991..2b64d7f501301c04ccdc54bf00e19a9748345bc4 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -235,13 +235,15 @@ const SYNC_API_RE = const CONTEXT_API_RE = /^create|Manager$/; +const ASYNC_API = ['createBLEConnection']; + const CALLBACK_API_RE = /^on/; function isContextApi (name) { return CONTEXT_API_RE.test(name) } function isSyncApi (name) { - return SYNC_API_RE.test(name) + return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1 } function isCallbackApi (name) { @@ -266,6 +268,19 @@ function shouldPromise (name) { return true } +/* eslint-disable no-extend-native */ +if (!Promise.prototype.finally) { + Promise.prototype.finally = function (callback) { + const promise = this.constructor; + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + }; +} + function promisify (name, api) { if (!shouldPromise(name)) { return api @@ -279,18 +294,6 @@ function promisify (name, api) { success: resolve, fail: reject }), ...params); - /* eslint-disable no-extend-native */ - if (!Promise.prototype.finally) { - Promise.prototype.finally = function (callback) { - const promise = this.constructor; - return this.then( - value => promise.resolve(callback()).then(() => value), - reason => promise.resolve(callback()).then(() => { - throw reason - }) - ) - }; - } }))) } } diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index ca718f756766dd8551b986337ce17f999499e9bb..7859d304051fc57c6e85ee0d5a2497fae870bd42 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -235,13 +235,15 @@ const SYNC_API_RE = const CONTEXT_API_RE = /^create|Manager$/; +const ASYNC_API = ['createBLEConnection']; + const CALLBACK_API_RE = /^on/; function isContextApi (name) { return CONTEXT_API_RE.test(name) } function isSyncApi (name) { - return SYNC_API_RE.test(name) + return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1 } function isCallbackApi (name) { @@ -266,6 +268,19 @@ function shouldPromise (name) { return true } +/* eslint-disable no-extend-native */ +if (!Promise.prototype.finally) { + Promise.prototype.finally = function (callback) { + const promise = this.constructor; + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + }; +} + function promisify (name, api) { if (!shouldPromise(name)) { return api @@ -279,18 +294,6 @@ function promisify (name, api) { success: resolve, fail: reject }), ...params); - /* eslint-disable no-extend-native */ - if (!Promise.prototype.finally) { - Promise.prototype.finally = function (callback) { - const promise = this.constructor; - return this.then( - value => promise.resolve(callback()).then(() => value), - reason => promise.resolve(callback()).then(() => { - throw reason - }) - ) - }; - } }))) } } diff --git a/packages/uni-mp-qq/dist/index.js b/packages/uni-mp-qq/dist/index.js index 9ed02a0ec4b6d1ab6e24a11d50a9a87746c1a275..6cac8aba264bb4f4692bdacda0ceb68fa8650aa9 100644 --- a/packages/uni-mp-qq/dist/index.js +++ b/packages/uni-mp-qq/dist/index.js @@ -235,13 +235,15 @@ const SYNC_API_RE = const CONTEXT_API_RE = /^create|Manager$/; +const ASYNC_API = ['createBLEConnection']; + const CALLBACK_API_RE = /^on/; function isContextApi (name) { return CONTEXT_API_RE.test(name) } function isSyncApi (name) { - return SYNC_API_RE.test(name) + return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1 } function isCallbackApi (name) { @@ -266,6 +268,19 @@ function shouldPromise (name) { return true } +/* eslint-disable no-extend-native */ +if (!Promise.prototype.finally) { + Promise.prototype.finally = function (callback) { + const promise = this.constructor; + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + }; +} + function promisify (name, api) { if (!shouldPromise(name)) { return api @@ -279,18 +294,6 @@ function promisify (name, api) { success: resolve, fail: reject }), ...params); - /* eslint-disable no-extend-native */ - if (!Promise.prototype.finally) { - Promise.prototype.finally = function (callback) { - const promise = this.constructor; - return this.then( - value => promise.resolve(callback()).then(() => value), - reason => promise.resolve(callback()).then(() => { - throw reason - }) - ) - }; - } }))) } } diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index f0458258bfa90a7a9b444abab192a120727874f5..666b02e8ac47c896b7d440333803ac24af2a3df7 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -235,13 +235,15 @@ const SYNC_API_RE = const CONTEXT_API_RE = /^create|Manager$/; +const ASYNC_API = ['createBLEConnection']; + const CALLBACK_API_RE = /^on/; function isContextApi (name) { return CONTEXT_API_RE.test(name) } function isSyncApi (name) { - return SYNC_API_RE.test(name) + return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1 } function isCallbackApi (name) { @@ -266,6 +268,19 @@ function shouldPromise (name) { return true } +/* eslint-disable no-extend-native */ +if (!Promise.prototype.finally) { + Promise.prototype.finally = function (callback) { + const promise = this.constructor; + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + }; +} + function promisify (name, api) { if (!shouldPromise(name)) { return api @@ -279,18 +294,6 @@ function promisify (name, api) { success: resolve, fail: reject }), ...params); - /* eslint-disable no-extend-native */ - if (!Promise.prototype.finally) { - Promise.prototype.finally = function (callback) { - const promise = this.constructor; - return this.then( - value => promise.resolve(callback()).then(() => value), - reason => promise.resolve(callback()).then(() => { - throw reason - }) - ) - }; - } }))) } } diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index d59bed55582cbcd073d5f94ff82b9fc26b4b308d..2192aa80d44c9d474ac7dc9189a09e7c0a120f83 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -235,13 +235,15 @@ const SYNC_API_RE = const CONTEXT_API_RE = /^create|Manager$/; +const ASYNC_API = ['createBLEConnection']; + const CALLBACK_API_RE = /^on/; function isContextApi (name) { return CONTEXT_API_RE.test(name) } function isSyncApi (name) { - return SYNC_API_RE.test(name) + return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1 } function isCallbackApi (name) { @@ -266,6 +268,19 @@ function shouldPromise (name) { return true } +/* eslint-disable no-extend-native */ +if (!Promise.prototype.finally) { + Promise.prototype.finally = function (callback) { + const promise = this.constructor; + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + }; +} + function promisify (name, api) { if (!shouldPromise(name)) { return api @@ -279,18 +294,6 @@ function promisify (name, api) { success: resolve, fail: reject }), ...params); - /* eslint-disable no-extend-native */ - if (!Promise.prototype.finally) { - Promise.prototype.finally = function (callback) { - const promise = this.constructor; - return this.then( - value => promise.resolve(callback()).then(() => value), - reason => promise.resolve(callback()).then(() => { - throw reason - }) - ) - }; - } }))) } } diff --git a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/define-pages.js b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/define-pages.js index 6816cb3451c2e8086edda9566a8478f23f61835a..44362c10b1efda883768bd896fdd0c4ce405969b 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/define-pages.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/define-pages.js @@ -10,7 +10,18 @@ function generatePageCode (pages, pageOptions) { module.exports = function definePages (appJson) { return { name: 'define-pages.js', - content: ` + content: ` +if (!Promise.prototype.finally) { + Promise.prototype.finally = function(callback) { + const promise = this.constructor + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + } +} if(uni.restoreGlobal){ uni.restoreGlobal(weex,plus,setTimeout,clearTimeout,setInterval,clearInterval) } diff --git a/src/core/helpers/promise.js b/src/core/helpers/promise.js index 181aaa42cde2f9764e7aa049681b3d2b15827680..dba09f0916c835bee0dc436aa50da5bdbc3a6a28 100644 --- a/src/core/helpers/promise.js +++ b/src/core/helpers/promise.js @@ -12,9 +12,9 @@ const SYNC_API_RE = const CONTEXT_API_RE = /^create|Manager$/ -const TASK_APIS = ['request', 'downloadFile', 'uploadFile', 'connectSocket'] +const TASK_APIS = ['request', 'downloadFile', 'uploadFile', 'connectSocket'] -const ASYNC_API = ['createBLEConnection'] +const ASYNC_API = ['createBLEConnection'] const CALLBACK_API_RE = /^on/ @@ -51,6 +51,19 @@ export function shouldPromise (name) { return true } +/* eslint-disable no-extend-native */ +if (!Promise.prototype.finally) { + Promise.prototype.finally = function (callback) { + const promise = this.constructor + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + } +} + export function promisify (name, api) { if (!shouldPromise(name)) { return api @@ -64,18 +77,6 @@ export function promisify (name, api) { success: resolve, fail: reject }), ...params) - /* eslint-disable no-extend-native */ - if (!Promise.prototype.finally) { - Promise.prototype.finally = function (callback) { - const promise = this.constructor - return this.then( - value => promise.resolve(callback()).then(() => value), - reason => promise.resolve(callback()).then(() => { - throw reason - }) - ) - } - } }))) } }