Skip to content

Commit 416c786

Browse files
JiaLiPassionkara
authored andcommitted
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
1 parent 93302b7 commit 416c786

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

packages/zone.js/lib/common/promise.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {patchMethod} from './utils';
2+
13
/**
24
* @license
35
* Copyright Google Inc. All Rights Reserved.
@@ -500,8 +502,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
500502
api.patchThen = patchThen;
501503

502504
function zoneify(fn: Function) {
503-
return function(this: unknown) {
504-
let resultPromise = fn.apply(this, arguments);
505+
return function(self: any, args: any[]) {
506+
let resultPromise = fn.apply(self, args);
505507
if (resultPromise instanceof ZoneAwarePromise) {
506508
return resultPromise;
507509
}
@@ -515,11 +517,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
515517

516518
if (NativePromise) {
517519
patchThen(NativePromise);
518-
const fetch = global['fetch'];
519-
if (typeof fetch == 'function') {
520-
global[api.symbol('fetch')] = fetch;
521-
global['fetch'] = zoneify(fetch);
522-
}
520+
patchMethod(global, 'fetch', delegate => zoneify(delegate));
523521
}
524522

525523
// This is not part of public API, but it is useful for tests, so we expose it.

0 commit comments

Comments
 (0)