Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit aca4728

Browse files
jwKimovikerman
authored andcommitted
fix: ensure that EventTarget is patched prior to legacy property descriptor patch (#1214)
If the event that EventTarget is defined on a device that also does not support patch via property descriptor, the result is that the XMLHttpRequest class would be patched prior to the event target being patched (due to returning in event-target-legacy if EventTarget is defined). This results in the wrapper that replaces XMLHttpRequest missing the patched listener fields. E.g. __zone_symbol__addEventListener and __zone_symbol__removeEventListener event-target-legacy. The result is that for any attempted http requests, a type error occurs in scheduleTask in browse.ts -> patchXhr, due to attempting call to non-existent __zone_symbol__addEventListener and __zone_symbol__removeEventListener, causing the requests to fail. Ensuring that patching of event target for legacy path takes place before legacy property descriptor patch eliminates this problem.
1 parent 775a752 commit aca4728

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: lib/browser/event-target-legacy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function eventTargetLegacyPatch(_global: any, api: _ZonePrivate) {
2424
// Workaround for: https://github.com/google/tracing-framework/issues/555
2525
apis = WTF_ISSUE_555_ARRAY.map((v) => 'HTML' + v + 'Element').concat(NO_EVENT_TARGET);
2626
} else if (_global[EVENT_TARGET]) {
27-
// EventTarget is already patched in browser.ts
27+
apis.push(EVENT_TARGET);
2828
} else {
2929
// Note: EventTarget is not available in all browsers,
3030
// if it's not available, we instead patch the APIs in the IDL that inherit from EventTarget
@@ -101,7 +101,7 @@ export function eventTargetLegacyPatch(_global: any, api: _ZonePrivate) {
101101
// vh is validateHandler to check event handler
102102
// is valid or not(for security check)
103103
api.patchEventTarget(_global, apiTypes, {vh: checkIEAndCrossContext});
104-
104+
(Zone as any)[api.symbol('patchEventTarget')] = !!_global[EVENT_TARGET];
105105
return true;
106106
}
107107

Diff for: lib/browser/event-target.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
*/
88

99
export function eventTargetPatch(_global: any, api: _ZonePrivate) {
10+
if ((Zone as any)[api.symbol('patchEventTarget')]) {
11+
// EventTarget is already patched.
12+
return;
13+
}
1014
const {eventNames, zoneSymbolEventNames, TRUE_STR, FALSE_STR, ZONE_SYMBOL_PREFIX} =
1115
api.getGlobalObjects()!;
1216
// predefine all __zone_symbol__ + eventName + true/false string

0 commit comments

Comments
 (0)