api-util.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. import {globalSources, patchEventPrototype, patchEventTarget, zoneSymbolEventNames} from '../common/events';
  9. import {ADD_EVENT_LISTENER_STR, ArraySlice, attachOriginToPatched, bindArguments, FALSE_STR, isBrowser, isIEOrEdge, isMix, isNode, ObjectCreate, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, patchClass, patchMacroTask, patchMethod, patchOnProperties, REMOVE_EVENT_LISTENER_STR, TRUE_STR, wrapWithCurrentZone, ZONE_SYMBOL_PREFIX} from '../common/utils';
  10. import {patchCallbacks} from './browser-util';
  11. import {_redefineProperty} from './define-property';
  12. import {eventNames, filterProperties} from './property-descriptor';
  13. Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
  14. api.patchOnProperties = patchOnProperties;
  15. api.patchMethod = patchMethod;
  16. api.bindArguments = bindArguments;
  17. api.patchMacroTask = patchMacroTask;
  18. // In earlier version of zone.js (<0.9.0), we use env name `__zone_symbol__BLACK_LISTED_EVENTS` to
  19. // define which events will not be patched by `Zone.js`.
  20. // In newer version (>=0.9.0), we change the env name to `__zone_symbol__UNPATCHED_EVENTS` to keep
  21. // the name consistent with angular repo.
  22. // The `__zone_symbol__BLACK_LISTED_EVENTS` is deprecated, but it is still be supported for
  23. // backwards compatibility.
  24. const SYMBOL_BLACK_LISTED_EVENTS = Zone.__symbol__('BLACK_LISTED_EVENTS');
  25. const SYMBOL_UNPATCHED_EVENTS = Zone.__symbol__('UNPATCHED_EVENTS');
  26. if (global[SYMBOL_UNPATCHED_EVENTS]) {
  27. global[SYMBOL_BLACK_LISTED_EVENTS] = global[SYMBOL_UNPATCHED_EVENTS];
  28. }
  29. if (global[SYMBOL_BLACK_LISTED_EVENTS]) {
  30. (Zone as any)[SYMBOL_BLACK_LISTED_EVENTS] = (Zone as any)[SYMBOL_UNPATCHED_EVENTS] =
  31. global[SYMBOL_BLACK_LISTED_EVENTS];
  32. }
  33. api.patchEventPrototype = patchEventPrototype;
  34. api.patchEventTarget = patchEventTarget;
  35. api.isIEOrEdge = isIEOrEdge;
  36. api.ObjectDefineProperty = ObjectDefineProperty;
  37. api.ObjectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor;
  38. api.ObjectCreate = ObjectCreate;
  39. api.ArraySlice = ArraySlice;
  40. api.patchClass = patchClass;
  41. api.wrapWithCurrentZone = wrapWithCurrentZone;
  42. api.filterProperties = filterProperties;
  43. api.attachOriginToPatched = attachOriginToPatched;
  44. api._redefineProperty = _redefineProperty;
  45. api.patchCallbacks = patchCallbacks;
  46. api.getGlobalObjects = () => ({
  47. globalSources,
  48. zoneSymbolEventNames,
  49. eventNames,
  50. isBrowser,
  51. isMix,
  52. isNode,
  53. TRUE_STR,
  54. FALSE_STR,
  55. ZONE_SYMBOL_PREFIX,
  56. ADD_EVENT_LISTENER_STR,
  57. REMOVE_EVENT_LISTENER_STR
  58. });
  59. });