event-target.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. export function eventTargetPatch(_global: any, api: _ZonePrivate) {
  9. if ((Zone as any)[api.symbol('patchEventTarget')]) {
  10. // EventTarget is already patched.
  11. return;
  12. }
  13. const {eventNames, zoneSymbolEventNames, TRUE_STR, FALSE_STR, ZONE_SYMBOL_PREFIX} =
  14. api.getGlobalObjects()!;
  15. // predefine all __zone_symbol__ + eventName + true/false string
  16. for (let i = 0; i < eventNames.length; i++) {
  17. const eventName = eventNames[i];
  18. const falseEventName = eventName + FALSE_STR;
  19. const trueEventName = eventName + TRUE_STR;
  20. const symbol = ZONE_SYMBOL_PREFIX + falseEventName;
  21. const symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
  22. zoneSymbolEventNames[eventName] = {};
  23. zoneSymbolEventNames[eventName][FALSE_STR] = symbol;
  24. zoneSymbolEventNames[eventName][TRUE_STR] = symbolCapture;
  25. }
  26. const EVENT_TARGET = _global['EventTarget'];
  27. if (!EVENT_TARGET || !EVENT_TARGET.prototype) {
  28. return;
  29. }
  30. api.patchEventTarget(_global, [EVENT_TARGET && EVENT_TARGET.prototype]);
  31. return true;
  32. }
  33. export function patchEvent(global: any, api: _ZonePrivate) {
  34. api.patchEventPrototype(global, api);
  35. }