zone-legacy.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. 'use strict';
  2. /**
  3. * @license Angular v<unknown>
  4. * (c) 2010-2022 Google LLC. https://angular.io/
  5. * License: MIT
  6. */
  7. /*
  8. * This is necessary for Chrome and Chrome mobile, to enable
  9. * things like redefining `createdCallback` on an element.
  10. */
  11. let zoneSymbol;
  12. let _defineProperty;
  13. let _getOwnPropertyDescriptor;
  14. let _create;
  15. let unconfigurablesKey;
  16. function propertyPatch() {
  17. zoneSymbol = Zone.__symbol__;
  18. _defineProperty = Object[zoneSymbol('defineProperty')] = Object.defineProperty;
  19. _getOwnPropertyDescriptor = Object[zoneSymbol('getOwnPropertyDescriptor')] =
  20. Object.getOwnPropertyDescriptor;
  21. _create = Object.create;
  22. unconfigurablesKey = zoneSymbol('unconfigurables');
  23. Object.defineProperty = function (obj, prop, desc) {
  24. if (isUnconfigurable(obj, prop)) {
  25. throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj);
  26. }
  27. const originalConfigurableFlag = desc.configurable;
  28. if (prop !== 'prototype') {
  29. desc = rewriteDescriptor(obj, prop, desc);
  30. }
  31. return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag);
  32. };
  33. Object.defineProperties = function (obj, props) {
  34. Object.keys(props).forEach(function (prop) {
  35. Object.defineProperty(obj, prop, props[prop]);
  36. });
  37. for (const sym of Object.getOwnPropertySymbols(props)) {
  38. const desc = Object.getOwnPropertyDescriptor(props, sym);
  39. // Since `Object.getOwnPropertySymbols` returns *all* symbols,
  40. // including non-enumerable ones, retrieve property descriptor and check
  41. // enumerability there. Proceed with the rewrite only when a property is
  42. // enumerable to make the logic consistent with the way regular
  43. // properties are retrieved (via `Object.keys`, which respects
  44. // `enumerable: false` flag). More information:
  45. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties#retrieval
  46. if (desc?.enumerable) {
  47. Object.defineProperty(obj, sym, props[sym]);
  48. }
  49. }
  50. return obj;
  51. };
  52. Object.create = function (proto, propertiesObject) {
  53. if (typeof propertiesObject === 'object' && !Object.isFrozen(propertiesObject)) {
  54. Object.keys(propertiesObject).forEach(function (prop) {
  55. propertiesObject[prop] = rewriteDescriptor(proto, prop, propertiesObject[prop]);
  56. });
  57. }
  58. return _create(proto, propertiesObject);
  59. };
  60. Object.getOwnPropertyDescriptor = function (obj, prop) {
  61. const desc = _getOwnPropertyDescriptor(obj, prop);
  62. if (desc && isUnconfigurable(obj, prop)) {
  63. desc.configurable = false;
  64. }
  65. return desc;
  66. };
  67. }
  68. function _redefineProperty(obj, prop, desc) {
  69. const originalConfigurableFlag = desc.configurable;
  70. desc = rewriteDescriptor(obj, prop, desc);
  71. return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag);
  72. }
  73. function isUnconfigurable(obj, prop) {
  74. return obj && obj[unconfigurablesKey] && obj[unconfigurablesKey][prop];
  75. }
  76. function rewriteDescriptor(obj, prop, desc) {
  77. // issue-927, if the desc is frozen, don't try to change the desc
  78. if (!Object.isFrozen(desc)) {
  79. desc.configurable = true;
  80. }
  81. if (!desc.configurable) {
  82. // issue-927, if the obj is frozen, don't try to set the desc to obj
  83. if (!obj[unconfigurablesKey] && !Object.isFrozen(obj)) {
  84. _defineProperty(obj, unconfigurablesKey, { writable: true, value: {} });
  85. }
  86. if (obj[unconfigurablesKey]) {
  87. obj[unconfigurablesKey][prop] = true;
  88. }
  89. }
  90. return desc;
  91. }
  92. function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) {
  93. try {
  94. return _defineProperty(obj, prop, desc);
  95. }
  96. catch (error) {
  97. if (desc.configurable) {
  98. // In case of errors, when the configurable flag was likely set by rewriteDescriptor(),
  99. // let's retry with the original flag value
  100. if (typeof originalConfigurableFlag == 'undefined') {
  101. delete desc.configurable;
  102. }
  103. else {
  104. desc.configurable = originalConfigurableFlag;
  105. }
  106. try {
  107. return _defineProperty(obj, prop, desc);
  108. }
  109. catch (error) {
  110. let swallowError = false;
  111. if (prop === 'createdCallback' || prop === 'attachedCallback' ||
  112. prop === 'detachedCallback' || prop === 'attributeChangedCallback') {
  113. // We only swallow the error in registerElement patch
  114. // this is the work around since some applications
  115. // fail if we throw the error
  116. swallowError = true;
  117. }
  118. if (!swallowError) {
  119. throw error;
  120. }
  121. // TODO: @JiaLiPassion, Some application such as `registerElement` patch
  122. // still need to swallow the error, in the future after these applications
  123. // are updated, the following logic can be removed.
  124. let descJson = null;
  125. try {
  126. descJson = JSON.stringify(desc);
  127. }
  128. catch (error) {
  129. descJson = desc.toString();
  130. }
  131. console.log(`Attempting to configure '${prop}' with descriptor '${descJson}' on object '${obj}' and got error, giving up: ${error}`);
  132. }
  133. }
  134. else {
  135. throw error;
  136. }
  137. }
  138. }
  139. function eventTargetLegacyPatch(_global, api) {
  140. const { eventNames, globalSources, zoneSymbolEventNames, TRUE_STR, FALSE_STR, ZONE_SYMBOL_PREFIX } = api.getGlobalObjects();
  141. const WTF_ISSUE_555 = 'Anchor,Area,Audio,BR,Base,BaseFont,Body,Button,Canvas,Content,DList,Directory,Div,Embed,FieldSet,Font,Form,Frame,FrameSet,HR,Head,Heading,Html,IFrame,Image,Input,Keygen,LI,Label,Legend,Link,Map,Marquee,Media,Menu,Meta,Meter,Mod,OList,Object,OptGroup,Option,Output,Paragraph,Pre,Progress,Quote,Script,Select,Source,Span,Style,TableCaption,TableCell,TableCol,Table,TableRow,TableSection,TextArea,Title,Track,UList,Unknown,Video';
  142. const NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Window,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex,WebSocket'
  143. .split(',');
  144. const EVENT_TARGET = 'EventTarget';
  145. let apis = [];
  146. const isWtf = _global['wtf'];
  147. const WTF_ISSUE_555_ARRAY = WTF_ISSUE_555.split(',');
  148. if (isWtf) {
  149. // Workaround for: https://github.com/google/tracing-framework/issues/555
  150. apis = WTF_ISSUE_555_ARRAY.map((v) => 'HTML' + v + 'Element').concat(NO_EVENT_TARGET);
  151. }
  152. else if (_global[EVENT_TARGET]) {
  153. apis.push(EVENT_TARGET);
  154. }
  155. else {
  156. // Note: EventTarget is not available in all browsers,
  157. // if it's not available, we instead patch the APIs in the IDL that inherit from EventTarget
  158. apis = NO_EVENT_TARGET;
  159. }
  160. const isDisableIECheck = _global['__Zone_disable_IE_check'] || false;
  161. const isEnableCrossContextCheck = _global['__Zone_enable_cross_context_check'] || false;
  162. const ieOrEdge = api.isIEOrEdge();
  163. const ADD_EVENT_LISTENER_SOURCE = '.addEventListener:';
  164. const FUNCTION_WRAPPER = '[object FunctionWrapper]';
  165. const BROWSER_TOOLS = 'function __BROWSERTOOLS_CONSOLE_SAFEFUNC() { [native code] }';
  166. const pointerEventsMap = {
  167. 'MSPointerCancel': 'pointercancel',
  168. 'MSPointerDown': 'pointerdown',
  169. 'MSPointerEnter': 'pointerenter',
  170. 'MSPointerHover': 'pointerhover',
  171. 'MSPointerLeave': 'pointerleave',
  172. 'MSPointerMove': 'pointermove',
  173. 'MSPointerOut': 'pointerout',
  174. 'MSPointerOver': 'pointerover',
  175. 'MSPointerUp': 'pointerup'
  176. };
  177. // predefine all __zone_symbol__ + eventName + true/false string
  178. for (let i = 0; i < eventNames.length; i++) {
  179. const eventName = eventNames[i];
  180. const falseEventName = eventName + FALSE_STR;
  181. const trueEventName = eventName + TRUE_STR;
  182. const symbol = ZONE_SYMBOL_PREFIX + falseEventName;
  183. const symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
  184. zoneSymbolEventNames[eventName] = {};
  185. zoneSymbolEventNames[eventName][FALSE_STR] = symbol;
  186. zoneSymbolEventNames[eventName][TRUE_STR] = symbolCapture;
  187. }
  188. // predefine all task.source string
  189. for (let i = 0; i < WTF_ISSUE_555_ARRAY.length; i++) {
  190. const target = WTF_ISSUE_555_ARRAY[i];
  191. const targets = globalSources[target] = {};
  192. for (let j = 0; j < eventNames.length; j++) {
  193. const eventName = eventNames[j];
  194. targets[eventName] = target + ADD_EVENT_LISTENER_SOURCE + eventName;
  195. }
  196. }
  197. const checkIEAndCrossContext = function (nativeDelegate, delegate, target, args) {
  198. if (!isDisableIECheck && ieOrEdge) {
  199. if (isEnableCrossContextCheck) {
  200. try {
  201. const testString = delegate.toString();
  202. if ((testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS)) {
  203. nativeDelegate.apply(target, args);
  204. return false;
  205. }
  206. }
  207. catch (error) {
  208. nativeDelegate.apply(target, args);
  209. return false;
  210. }
  211. }
  212. else {
  213. const testString = delegate.toString();
  214. if ((testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS)) {
  215. nativeDelegate.apply(target, args);
  216. return false;
  217. }
  218. }
  219. }
  220. else if (isEnableCrossContextCheck) {
  221. try {
  222. delegate.toString();
  223. }
  224. catch (error) {
  225. nativeDelegate.apply(target, args);
  226. return false;
  227. }
  228. }
  229. return true;
  230. };
  231. const apiTypes = [];
  232. for (let i = 0; i < apis.length; i++) {
  233. const type = _global[apis[i]];
  234. apiTypes.push(type && type.prototype);
  235. }
  236. // vh is validateHandler to check event handler
  237. // is valid or not(for security check)
  238. api.patchEventTarget(_global, api, apiTypes, {
  239. vh: checkIEAndCrossContext,
  240. transferEventName: (eventName) => {
  241. const pointerEventName = pointerEventsMap[eventName];
  242. return pointerEventName || eventName;
  243. }
  244. });
  245. Zone[api.symbol('patchEventTarget')] = !!_global[EVENT_TARGET];
  246. return true;
  247. }
  248. // we have to patch the instance since the proto is non-configurable
  249. function apply(api, _global) {
  250. const { ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR } = api.getGlobalObjects();
  251. const WS = _global.WebSocket;
  252. // On Safari window.EventTarget doesn't exist so need to patch WS add/removeEventListener
  253. // On older Chrome, no need since EventTarget was already patched
  254. if (!_global.EventTarget) {
  255. api.patchEventTarget(_global, api, [WS.prototype]);
  256. }
  257. _global.WebSocket = function (x, y) {
  258. const socket = arguments.length > 1 ? new WS(x, y) : new WS(x);
  259. let proxySocket;
  260. let proxySocketProto;
  261. // Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
  262. const onmessageDesc = api.ObjectGetOwnPropertyDescriptor(socket, 'onmessage');
  263. if (onmessageDesc && onmessageDesc.configurable === false) {
  264. proxySocket = api.ObjectCreate(socket);
  265. // socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror'
  266. // but proxySocket not, so we will keep socket as prototype and pass it to
  267. // patchOnProperties method
  268. proxySocketProto = socket;
  269. [ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR, 'send', 'close'].forEach(function (propName) {
  270. proxySocket[propName] = function () {
  271. const args = api.ArraySlice.call(arguments);
  272. if (propName === ADD_EVENT_LISTENER_STR || propName === REMOVE_EVENT_LISTENER_STR) {
  273. const eventName = args.length > 0 ? args[0] : undefined;
  274. if (eventName) {
  275. const propertySymbol = Zone.__symbol__('ON_PROPERTY' + eventName);
  276. socket[propertySymbol] = proxySocket[propertySymbol];
  277. }
  278. }
  279. return socket[propName].apply(socket, args);
  280. };
  281. });
  282. }
  283. else {
  284. // we can patch the real socket
  285. proxySocket = socket;
  286. }
  287. api.patchOnProperties(proxySocket, ['close', 'error', 'message', 'open'], proxySocketProto);
  288. return proxySocket;
  289. };
  290. const globalWebSocket = _global['WebSocket'];
  291. for (const prop in WS) {
  292. globalWebSocket[prop] = WS[prop];
  293. }
  294. }
  295. /**
  296. * @fileoverview
  297. * @suppress {globalThis}
  298. */
  299. function propertyDescriptorLegacyPatch(api, _global) {
  300. const { isNode, isMix } = api.getGlobalObjects();
  301. if (isNode && !isMix) {
  302. return;
  303. }
  304. if (!canPatchViaPropertyDescriptor(api, _global)) {
  305. const supportsWebSocket = typeof WebSocket !== 'undefined';
  306. // Safari, Android browsers (Jelly Bean)
  307. patchViaCapturingAllTheEvents(api);
  308. api.patchClass('XMLHttpRequest');
  309. if (supportsWebSocket) {
  310. apply(api, _global);
  311. }
  312. Zone[api.symbol('patchEvents')] = true;
  313. }
  314. }
  315. function canPatchViaPropertyDescriptor(api, _global) {
  316. const { isBrowser, isMix } = api.getGlobalObjects();
  317. if ((isBrowser || isMix) &&
  318. !api.ObjectGetOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') &&
  319. typeof Element !== 'undefined') {
  320. // WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
  321. // IDL interface attributes are not configurable
  322. const desc = api.ObjectGetOwnPropertyDescriptor(Element.prototype, 'onclick');
  323. if (desc && !desc.configurable)
  324. return false;
  325. // try to use onclick to detect whether we can patch via propertyDescriptor
  326. // because XMLHttpRequest is not available in service worker
  327. if (desc) {
  328. api.ObjectDefineProperty(Element.prototype, 'onclick', {
  329. enumerable: true,
  330. configurable: true,
  331. get: function () {
  332. return true;
  333. }
  334. });
  335. const div = document.createElement('div');
  336. const result = !!div.onclick;
  337. api.ObjectDefineProperty(Element.prototype, 'onclick', desc);
  338. return result;
  339. }
  340. }
  341. const XMLHttpRequest = _global['XMLHttpRequest'];
  342. if (!XMLHttpRequest) {
  343. // XMLHttpRequest is not available in service worker
  344. return false;
  345. }
  346. const ON_READY_STATE_CHANGE = 'onreadystatechange';
  347. const XMLHttpRequestPrototype = XMLHttpRequest.prototype;
  348. const xhrDesc = api.ObjectGetOwnPropertyDescriptor(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE);
  349. // add enumerable and configurable here because in opera
  350. // by default XMLHttpRequest.prototype.onreadystatechange is undefined
  351. // without adding enumerable and configurable will cause onreadystatechange
  352. // non-configurable
  353. // and if XMLHttpRequest.prototype.onreadystatechange is undefined,
  354. // we should set a real desc instead a fake one
  355. if (xhrDesc) {
  356. api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
  357. enumerable: true,
  358. configurable: true,
  359. get: function () {
  360. return true;
  361. }
  362. });
  363. const req = new XMLHttpRequest();
  364. const result = !!req.onreadystatechange;
  365. // restore original desc
  366. api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, xhrDesc || {});
  367. return result;
  368. }
  369. else {
  370. const SYMBOL_FAKE_ONREADYSTATECHANGE = api.symbol('fake');
  371. api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
  372. enumerable: true,
  373. configurable: true,
  374. get: function () {
  375. return this[SYMBOL_FAKE_ONREADYSTATECHANGE];
  376. },
  377. set: function (value) {
  378. this[SYMBOL_FAKE_ONREADYSTATECHANGE] = value;
  379. }
  380. });
  381. const req = new XMLHttpRequest();
  382. const detectFunc = () => { };
  383. req.onreadystatechange = detectFunc;
  384. const result = req[SYMBOL_FAKE_ONREADYSTATECHANGE] === detectFunc;
  385. req.onreadystatechange = null;
  386. return result;
  387. }
  388. }
  389. const globalEventHandlersEventNames = [
  390. 'abort',
  391. 'animationcancel',
  392. 'animationend',
  393. 'animationiteration',
  394. 'auxclick',
  395. 'beforeinput',
  396. 'blur',
  397. 'cancel',
  398. 'canplay',
  399. 'canplaythrough',
  400. 'change',
  401. 'compositionstart',
  402. 'compositionupdate',
  403. 'compositionend',
  404. 'cuechange',
  405. 'click',
  406. 'close',
  407. 'contextmenu',
  408. 'curechange',
  409. 'dblclick',
  410. 'drag',
  411. 'dragend',
  412. 'dragenter',
  413. 'dragexit',
  414. 'dragleave',
  415. 'dragover',
  416. 'drop',
  417. 'durationchange',
  418. 'emptied',
  419. 'ended',
  420. 'error',
  421. 'focus',
  422. 'focusin',
  423. 'focusout',
  424. 'gotpointercapture',
  425. 'input',
  426. 'invalid',
  427. 'keydown',
  428. 'keypress',
  429. 'keyup',
  430. 'load',
  431. 'loadstart',
  432. 'loadeddata',
  433. 'loadedmetadata',
  434. 'lostpointercapture',
  435. 'mousedown',
  436. 'mouseenter',
  437. 'mouseleave',
  438. 'mousemove',
  439. 'mouseout',
  440. 'mouseover',
  441. 'mouseup',
  442. 'mousewheel',
  443. 'orientationchange',
  444. 'pause',
  445. 'play',
  446. 'playing',
  447. 'pointercancel',
  448. 'pointerdown',
  449. 'pointerenter',
  450. 'pointerleave',
  451. 'pointerlockchange',
  452. 'mozpointerlockchange',
  453. 'webkitpointerlockerchange',
  454. 'pointerlockerror',
  455. 'mozpointerlockerror',
  456. 'webkitpointerlockerror',
  457. 'pointermove',
  458. 'pointout',
  459. 'pointerover',
  460. 'pointerup',
  461. 'progress',
  462. 'ratechange',
  463. 'reset',
  464. 'resize',
  465. 'scroll',
  466. 'seeked',
  467. 'seeking',
  468. 'select',
  469. 'selectionchange',
  470. 'selectstart',
  471. 'show',
  472. 'sort',
  473. 'stalled',
  474. 'submit',
  475. 'suspend',
  476. 'timeupdate',
  477. 'volumechange',
  478. 'touchcancel',
  479. 'touchmove',
  480. 'touchstart',
  481. 'touchend',
  482. 'transitioncancel',
  483. 'transitionend',
  484. 'waiting',
  485. 'wheel'
  486. ];
  487. const documentEventNames = [
  488. 'afterscriptexecute', 'beforescriptexecute', 'DOMContentLoaded', 'freeze', 'fullscreenchange',
  489. 'mozfullscreenchange', 'webkitfullscreenchange', 'msfullscreenchange', 'fullscreenerror',
  490. 'mozfullscreenerror', 'webkitfullscreenerror', 'msfullscreenerror', 'readystatechange',
  491. 'visibilitychange', 'resume'
  492. ];
  493. const windowEventNames = [
  494. 'absolutedeviceorientation',
  495. 'afterinput',
  496. 'afterprint',
  497. 'appinstalled',
  498. 'beforeinstallprompt',
  499. 'beforeprint',
  500. 'beforeunload',
  501. 'devicelight',
  502. 'devicemotion',
  503. 'deviceorientation',
  504. 'deviceorientationabsolute',
  505. 'deviceproximity',
  506. 'hashchange',
  507. 'languagechange',
  508. 'message',
  509. 'mozbeforepaint',
  510. 'offline',
  511. 'online',
  512. 'paint',
  513. 'pageshow',
  514. 'pagehide',
  515. 'popstate',
  516. 'rejectionhandled',
  517. 'storage',
  518. 'unhandledrejection',
  519. 'unload',
  520. 'userproximity',
  521. 'vrdisplayconnected',
  522. 'vrdisplaydisconnected',
  523. 'vrdisplaypresentchange'
  524. ];
  525. const htmlElementEventNames = [
  526. 'beforecopy', 'beforecut', 'beforepaste', 'copy', 'cut', 'paste', 'dragstart', 'loadend',
  527. 'animationstart', 'search', 'transitionrun', 'transitionstart', 'webkitanimationend',
  528. 'webkitanimationiteration', 'webkitanimationstart', 'webkittransitionend'
  529. ];
  530. const ieElementEventNames = [
  531. 'activate',
  532. 'afterupdate',
  533. 'ariarequest',
  534. 'beforeactivate',
  535. 'beforedeactivate',
  536. 'beforeeditfocus',
  537. 'beforeupdate',
  538. 'cellchange',
  539. 'controlselect',
  540. 'dataavailable',
  541. 'datasetchanged',
  542. 'datasetcomplete',
  543. 'errorupdate',
  544. 'filterchange',
  545. 'layoutcomplete',
  546. 'losecapture',
  547. 'move',
  548. 'moveend',
  549. 'movestart',
  550. 'propertychange',
  551. 'resizeend',
  552. 'resizestart',
  553. 'rowenter',
  554. 'rowexit',
  555. 'rowsdelete',
  556. 'rowsinserted',
  557. 'command',
  558. 'compassneedscalibration',
  559. 'deactivate',
  560. 'help',
  561. 'mscontentzoom',
  562. 'msmanipulationstatechanged',
  563. 'msgesturechange',
  564. 'msgesturedoubletap',
  565. 'msgestureend',
  566. 'msgesturehold',
  567. 'msgesturestart',
  568. 'msgesturetap',
  569. 'msgotpointercapture',
  570. 'msinertiastart',
  571. 'mslostpointercapture',
  572. 'mspointercancel',
  573. 'mspointerdown',
  574. 'mspointerenter',
  575. 'mspointerhover',
  576. 'mspointerleave',
  577. 'mspointermove',
  578. 'mspointerout',
  579. 'mspointerover',
  580. 'mspointerup',
  581. 'pointerout',
  582. 'mssitemodejumplistitemremoved',
  583. 'msthumbnailclick',
  584. 'stop',
  585. 'storagecommit'
  586. ];
  587. const webglEventNames = ['webglcontextrestored', 'webglcontextlost', 'webglcontextcreationerror'];
  588. const formEventNames = ['autocomplete', 'autocompleteerror'];
  589. const detailEventNames = ['toggle'];
  590. const eventNames = [
  591. ...globalEventHandlersEventNames, ...webglEventNames, ...formEventNames, ...detailEventNames,
  592. ...documentEventNames, ...windowEventNames, ...htmlElementEventNames, ...ieElementEventNames
  593. ];
  594. // Whenever any eventListener fires, we check the eventListener target and all parents
  595. // for `onwhatever` properties and replace them with zone-bound functions
  596. // - Chrome (for now)
  597. function patchViaCapturingAllTheEvents(api) {
  598. const unboundKey = api.symbol('unbound');
  599. for (let i = 0; i < eventNames.length; i++) {
  600. const property = eventNames[i];
  601. const onproperty = 'on' + property;
  602. self.addEventListener(property, function (event) {
  603. let elt = event.target, bound, source;
  604. if (elt) {
  605. source = elt.constructor['name'] + '.' + onproperty;
  606. }
  607. else {
  608. source = 'unknown.' + onproperty;
  609. }
  610. while (elt) {
  611. if (elt[onproperty] && !elt[onproperty][unboundKey]) {
  612. bound = api.wrapWithCurrentZone(elt[onproperty], source);
  613. bound[unboundKey] = elt[onproperty];
  614. elt[onproperty] = bound;
  615. }
  616. elt = elt.parentElement;
  617. }
  618. }, true);
  619. }
  620. }
  621. function registerElementPatch(_global, api) {
  622. const { isBrowser, isMix } = api.getGlobalObjects();
  623. if ((!isBrowser && !isMix) || !('registerElement' in _global.document)) {
  624. return;
  625. }
  626. const callbacks = ['createdCallback', 'attachedCallback', 'detachedCallback', 'attributeChangedCallback'];
  627. api.patchCallbacks(api, document, 'Document', 'registerElement', callbacks);
  628. }
  629. /**
  630. * @fileoverview
  631. * @suppress {missingRequire}
  632. */
  633. (function (_global) {
  634. const symbolPrefix = _global['__Zone_symbol_prefix'] || '__zone_symbol__';
  635. function __symbol__(name) {
  636. return symbolPrefix + name;
  637. }
  638. _global[__symbol__('legacyPatch')] = function () {
  639. const Zone = _global['Zone'];
  640. Zone.__load_patch('defineProperty', (global, Zone, api) => {
  641. api._redefineProperty = _redefineProperty;
  642. propertyPatch();
  643. });
  644. Zone.__load_patch('registerElement', (global, Zone, api) => {
  645. registerElementPatch(global, api);
  646. });
  647. Zone.__load_patch('EventTargetLegacy', (global, Zone, api) => {
  648. eventTargetLegacyPatch(global, api);
  649. propertyDescriptorLegacyPatch(api, global);
  650. });
  651. };
  652. })(typeof window !== 'undefined' ?
  653. window :
  654. typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {});