From d4ac887fd112c3fde3a167223c42ecbac76c1f14 Mon Sep 17 00:00:00 2001 From: MinHyeong Kim Date: Fri, 8 Jun 2018 22:00:45 +0900 Subject: [PATCH] fix(core): fix #1078 tring to use `then` if patched `then` is not avail Pull request number #1041 break app in some mobile browser that Promise.then is not writeable. (We tested on Samsung Galaxy A5) I agree #1041 code change because it is not writable. But i think just break some application without any warning message is not right. So i add fallback code and display some wraning message for that. --- lib/zone.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/zone.ts b/lib/zone.ts index 9cbd04fdc..e9ca9ef21 100644 --- a/lib/zone.ts +++ b/lib/zone.ts @@ -1272,7 +1272,17 @@ const Zone: ZoneType = (function(global: any) { } } if (nativeMicroTaskQueuePromise) { - nativeMicroTaskQueuePromise[symbolThen](drainMicroTaskQueue); + if (typeof nativeMicroTaskQueuePromise[symbolThen] === FUNCTION) { + nativeMicroTaskQueuePromise[symbolThen](drainMicroTaskQueue); + } else if (typeof nativeMicroTaskQueuePromise.then === FUNCTION) { + nativeMicroTaskQueuePromise.then(drainMicroTaskQueue); + } else { + console.error(`Cannot found Promise#then method. Please add polyfill to using \`Promise\`. If you already did that. Perhaps Promise#then is not writeable. If you want to use it. add following codes to your \`polyfill.ts\` after \`import 'zone.js/dist/zone'\` + +if (!(Promise.prototype as any)['__zone_symbol__then']) { + (Promise.prototype as any)['__zone_symbol__then'] = Promise.prototype.then; +}`); + } } else { global[symbolSetTimeout](drainMicroTaskQueue, 0); }