From 416c786774dccc20d824737207be4e55cb53c9cc Mon Sep 17 00:00:00 2001 From: JiaLiPassion Date: Mon, 30 Mar 2020 09:14:02 +0900 Subject: [PATCH] fix(zone.js): should not try to patch fetch if it is not writable (#36311) Close #36142 In Firefox extensions, the `window.fetch` is not configurable, that means ``` const desc = Object.getOwnPropertyDescriptor(window, 'fetch'); desc.writable === false; ``` So in this case, we should not try to patch `fetch`, otherwise, it will throw error ('fetch is ReadOnly`) PR Close #36311 --- packages/zone.js/lib/common/promise.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/zone.js/lib/common/promise.ts b/packages/zone.js/lib/common/promise.ts index d588e1d520..8f41b06478 100644 --- a/packages/zone.js/lib/common/promise.ts +++ b/packages/zone.js/lib/common/promise.ts @@ -1,3 +1,5 @@ +import {patchMethod} from './utils'; + /** * @license * Copyright Google Inc. All Rights Reserved. @@ -500,8 +502,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr api.patchThen = patchThen; function zoneify(fn: Function) { - return function(this: unknown) { - let resultPromise = fn.apply(this, arguments); + return function(self: any, args: any[]) { + let resultPromise = fn.apply(self, args); if (resultPromise instanceof ZoneAwarePromise) { return resultPromise; } @@ -515,11 +517,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr if (NativePromise) { patchThen(NativePromise); - const fetch = global['fetch']; - if (typeof fetch == 'function') { - global[api.symbol('fetch')] = fetch; - global['fetch'] = zoneify(fetch); - } + patchMethod(global, 'fetch', delegate => zoneify(delegate)); } // This is not part of public API, but it is useful for tests, so we expose it.