zone.configurations.api.d.ts 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /**
  2. * @license
  3. * Copyright Google LLC 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.dev/license
  7. */
  8. declare global {
  9. /**
  10. * Interface of `zone.js` configurations.
  11. *
  12. * You can define the following configurations on the `window/global` object before
  13. * importing `zone.js` to change `zone.js` default behaviors.
  14. */
  15. interface ZoneGlobalConfigurations {
  16. /**
  17. * Disable the monkey patch of the `Node.js` `EventEmitter` API.
  18. *
  19. * By default, `zone.js` monkey patches the `Node.js` `EventEmitter` APIs to make asynchronous
  20. * callbacks of those APIs in the same zone when scheduled.
  21. *
  22. * Consider the following example:
  23. *
  24. * ```ts
  25. * const EventEmitter = require('events');
  26. * class MyEmitter extends EventEmitter {}
  27. * const myEmitter = new MyEmitter();
  28. *
  29. * const zone = Zone.current.fork({name: 'myZone'});
  30. * zone.run(() => {
  31. * myEmitter.on('event', () => {
  32. * console.log('an event occurs in the zone', Zone.current.name);
  33. * // the callback runs in the zone when it is scheduled,
  34. * // so the output is 'an event occurs in the zone myZone'.
  35. * });
  36. * });
  37. * myEmitter.emit('event');
  38. * ```
  39. *
  40. * If you set `__Zone_disable_EventEmitter = true` before importing `zone.js`,
  41. * `zone.js` does not monkey patch the `EventEmitter` APIs and the above code
  42. * outputs 'an event occurred <root>'.
  43. */
  44. __Zone_disable_EventEmitter?: boolean;
  45. /**
  46. * Disable the monkey patch of the `Node.js` `fs` API.
  47. *
  48. * By default, `zone.js` monkey patches `Node.js` `fs` APIs to make asynchronous callbacks of
  49. * those APIs in the same zone when scheduled.
  50. *
  51. * Consider the following example:
  52. *
  53. * ```ts
  54. * const fs = require('fs');
  55. *
  56. * const zone = Zone.current.fork({name: 'myZone'});
  57. * zone.run(() => {
  58. * fs.stat('/tmp/world', (err, stats) => {
  59. * console.log('fs.stats() callback is invoked in the zone', Zone.current.name);
  60. * // since the callback of the `fs.stat()` runs in the same zone
  61. * // when it is called, so the output is 'fs.stats() callback is invoked in the zone
  62. * myZone'.
  63. * });
  64. * });
  65. * ```
  66. *
  67. * If you set `__Zone_disable_fs = true` before importing `zone.js`,
  68. * `zone.js` does not monkey patch the `fs` API and the above code
  69. * outputs 'get stats occurred <root>'.
  70. */
  71. __Zone_disable_fs?: boolean;
  72. /**
  73. * Disable the monkey patch of the `Node.js` `timer` API.
  74. *
  75. * By default, `zone.js` monkey patches the `Node.js` `timer` APIs to make asynchronous
  76. * callbacks of those APIs in the same zone when scheduled.
  77. *
  78. * Consider the following example:
  79. *
  80. * ```ts
  81. * const zone = Zone.current.fork({name: 'myZone'});
  82. * zone.run(() => {
  83. * setTimeout(() => {
  84. * console.log('setTimeout() callback is invoked in the zone', Zone.current.name);
  85. * // since the callback of `setTimeout()` runs in the same zone
  86. * // when it is scheduled, so the output is 'setTimeout() callback is invoked in the zone
  87. * // myZone'.
  88. * });
  89. * });
  90. * ```
  91. *
  92. * If you set `__Zone_disable_timers = true` before importing `zone.js`,
  93. * `zone.js` does not monkey patch the `timer` APIs and the above code
  94. * outputs 'timeout <root>'.
  95. */
  96. __Zone_disable_node_timers?: boolean;
  97. /**
  98. * Disable the monkey patch of the `Node.js` `process.nextTick()` API.
  99. *
  100. * By default, `zone.js` monkey patches the `Node.js` `process.nextTick()` API to make the
  101. * callback in the same zone when calling `process.nextTick()`.
  102. *
  103. * Consider the following example:
  104. *
  105. * ```ts
  106. * const zone = Zone.current.fork({name: 'myZone'});
  107. * zone.run(() => {
  108. * process.nextTick(() => {
  109. * console.log('process.nextTick() callback is invoked in the zone', Zone.current.name);
  110. * // since the callback of `process.nextTick()` runs in the same zone
  111. * // when it is scheduled, so the output is 'process.nextTick() callback is invoked in the
  112. * // zone myZone'.
  113. * });
  114. * });
  115. * ```
  116. *
  117. * If you set `__Zone_disable_nextTick = true` before importing `zone.js`,
  118. * `zone.js` does not monkey patch the `process.nextTick()` API and the above code
  119. * outputs 'nextTick <root>'.
  120. */
  121. __Zone_disable_nextTick?: boolean;
  122. /**
  123. * Disable the monkey patch of the `Node.js` `crypto` API.
  124. *
  125. * By default, `zone.js` monkey patches the `Node.js` `crypto` APIs to make asynchronous
  126. * callbacks of those APIs in the same zone when called.
  127. *
  128. * Consider the following example:
  129. *
  130. * ```ts
  131. * const crypto = require('crypto');
  132. *
  133. * const zone = Zone.current.fork({name: 'myZone'});
  134. * zone.run(() => {
  135. * crypto.randomBytes(() => {
  136. * console.log('crypto.randomBytes() callback is invoked in the zone', Zone.current.name);
  137. * // since the callback of `crypto.randomBytes()` runs in the same zone
  138. * // when it is called, so the output is 'crypto.randomBytes() callback is invoked in the
  139. * // zone myZone'.
  140. * });
  141. * });
  142. * ```
  143. *
  144. * If you set `__Zone_disable_crypto = true` before importing `zone.js`,
  145. * `zone.js` does not monkey patch the `crypto` API and the above code
  146. * outputs 'crypto <root>'.
  147. */
  148. __Zone_disable_crypto?: boolean;
  149. /**
  150. * Disable the monkey patch of the `Object.defineProperty()` API.
  151. *
  152. * Note: This configuration is available only in the legacy bundle (dist/zone.js). This module
  153. * is not available in the evergreen bundle (zone-evergreen.js).
  154. *
  155. * In the legacy browser, the default behavior of `zone.js` is to monkey patch
  156. * `Object.defineProperty()` and `Object.create()` to try to ensure PropertyDescriptor
  157. * parameter's configurable property to be true. This patch is only needed in some old mobile
  158. * browsers.
  159. *
  160. * If you set `__Zone_disable_defineProperty = true` before importing `zone.js`,
  161. * `zone.js` does not monkey patch the `Object.defineProperty()` API and does not
  162. * modify desc.configurable to true.
  163. *
  164. */
  165. __Zone_disable_defineProperty?: boolean;
  166. /**
  167. * Disable the monkey patch of the browser `registerElement()` API.
  168. *
  169. * NOTE: This configuration is only available in the legacy bundle (dist/zone.js), this
  170. * module is not available in the evergreen bundle (zone-evergreen.js).
  171. *
  172. * In the legacy browser, the default behavior of `zone.js` is to monkey patch the
  173. * `registerElement()` API to make asynchronous callbacks of the API in the same zone when
  174. * `registerElement()` is called.
  175. *
  176. * Consider the following example:
  177. *
  178. * ```ts
  179. * const proto = Object.create(HTMLElement.prototype);
  180. * proto.createdCallback = function() {
  181. * console.log('createdCallback is invoked in the zone', Zone.current.name);
  182. * };
  183. * proto.attachedCallback = function() {
  184. * console.log('attachedCallback is invoked in the zone', Zone.current.name);
  185. * };
  186. * proto.detachedCallback = function() {
  187. * console.log('detachedCallback is invoked in the zone', Zone.current.name);
  188. * };
  189. * proto.attributeChangedCallback = function() {
  190. * console.log('attributeChangedCallback is invoked in the zone', Zone.current.name);
  191. * };
  192. *
  193. * const zone = Zone.current.fork({name: 'myZone'});
  194. * zone.run(() => {
  195. * document.registerElement('x-elem', {prototype: proto});
  196. * });
  197. * ```
  198. *
  199. * When these callbacks are invoked, those callbacks will be in the zone when
  200. * `registerElement()` is called.
  201. *
  202. * If you set `__Zone_disable_registerElement = true` before importing `zone.js`,
  203. * `zone.js` does not monkey patch `registerElement()` API and the above code
  204. * outputs '<root>'.
  205. */
  206. __Zone_disable_registerElement?: boolean;
  207. /**
  208. * Disable the monkey patch of the browser legacy `EventTarget` API.
  209. *
  210. * NOTE: This configuration is only available in the legacy bundle (dist/zone.js), this module
  211. * is not available in the evergreen bundle (zone-evergreen.js).
  212. *
  213. * In some old browsers, the `EventTarget` is not available, so `zone.js` cannot directly monkey
  214. * patch the `EventTarget`. Instead, `zone.js` patches all known HTML elements' prototypes (such
  215. * as `HtmlDivElement`). The callback of the `addEventListener()` will be in the same zone when
  216. * the `addEventListener()` is called.
  217. *
  218. * Consider the following example:
  219. *
  220. * ```ts
  221. * const zone = Zone.current.fork({name: 'myZone'});
  222. * zone.run(() => {
  223. * div.addEventListener('click', () => {
  224. * console.log('div click event listener is invoked in the zone', Zone.current.name);
  225. * // the output is 'div click event listener is invoked in the zone myZone'.
  226. * });
  227. * });
  228. * ```
  229. *
  230. * If you set `__Zone_disable_EventTargetLegacy = true` before importing `zone.js`
  231. * In some old browsers, where `EventTarget` is not available, if you set
  232. * `__Zone_disable_EventTargetLegacy = true` before importing `zone.js`, `zone.js` does not
  233. * monkey patch all HTML element APIs and the above code outputs 'clicked <root>'.
  234. */
  235. __Zone_disable_EventTargetLegacy?: boolean;
  236. /**
  237. * Disable the monkey patch of the browser `timer` APIs.
  238. *
  239. * By default, `zone.js` monkey patches browser timer
  240. * APIs (`setTimeout()`/`setInterval()`/`setImmediate()`) to make asynchronous callbacks of
  241. * those APIs in the same zone when scheduled.
  242. *
  243. * Consider the following example:
  244. *
  245. * ```ts
  246. * const zone = Zone.current.fork({name: 'myZone'});
  247. * zone.run(() => {
  248. * setTimeout(() => {
  249. * console.log('setTimeout() callback is invoked in the zone', Zone.current.name);
  250. * // since the callback of `setTimeout()` runs in the same zone
  251. * // when it is scheduled, so the output is 'setTimeout() callback is invoked in the zone
  252. * // myZone'.
  253. * });
  254. * });
  255. * ```
  256. *
  257. * If you set `__Zone_disable_timers = true` before importing `zone.js`,
  258. * `zone.js` does not monkey patch `timer` API and the above code
  259. * outputs 'timeout <root>'.
  260. *
  261. */
  262. __Zone_disable_timers?: boolean;
  263. /**
  264. * Disable the monkey patch of the browser `requestAnimationFrame()` API.
  265. *
  266. * By default, `zone.js` monkey patches the browser `requestAnimationFrame()` API
  267. * to make the asynchronous callback of the `requestAnimationFrame()` in the same zone when
  268. * scheduled.
  269. *
  270. * Consider the following example:
  271. *
  272. * ```ts
  273. * const zone = Zone.current.fork({name: 'myZone'});
  274. * zone.run(() => {
  275. * requestAnimationFrame(() => {
  276. * console.log('requestAnimationFrame() callback is invoked in the zone',
  277. * Zone.current.name);
  278. * // since the callback of `requestAnimationFrame()` will be in the same zone
  279. * // when it is scheduled, so the output will be 'requestAnimationFrame() callback is
  280. * invoked
  281. * // in the zone myZone'
  282. * });
  283. * });
  284. * ```
  285. *
  286. * If you set `__Zone_disable_requestAnimationFrame = true` before importing `zone.js`,
  287. * `zone.js` does not monkey patch the `requestAnimationFrame()` API and the above code
  288. * outputs 'raf <root>'.
  289. */
  290. __Zone_disable_requestAnimationFrame?: boolean;
  291. /**
  292. *
  293. * Disable the monkey patching of the `queueMicrotask()` API.
  294. *
  295. * By default, `zone.js` monkey patches the `queueMicrotask()` API
  296. * to ensure that `queueMicrotask()` callback is invoked in the same zone as zone used to invoke
  297. * `queueMicrotask()`. And also the callback is running as `microTask` like
  298. * `Promise.prototype.then()`.
  299. *
  300. * Consider the following example:
  301. *
  302. * ```ts
  303. * const zone = Zone.current.fork({name: 'myZone'});
  304. * zone.run(() => {
  305. * queueMicrotask(() => {
  306. * console.log('queueMicrotask() callback is invoked in the zone', Zone.current.name);
  307. * // Since `queueMicrotask()` was invoked in `myZone`, same zone is restored
  308. * // when 'queueMicrotask() callback is invoked, resulting in `myZone` being console
  309. * logged.
  310. * });
  311. * });
  312. * ```
  313. *
  314. * If you set `__Zone_disable_queueMicrotask = true` before importing `zone.js`,
  315. * `zone.js` does not monkey patch the `queueMicrotask()` API and the above code
  316. * output will change to: 'queueMicrotask() callback is invoked in the zone <root>'.
  317. */
  318. __Zone_disable_queueMicrotask?: boolean;
  319. /**
  320. *
  321. * Disable the monkey patch of the browser blocking APIs(`alert()`/`prompt()`/`confirm()`).
  322. */
  323. __Zone_disable_blocking?: boolean;
  324. /**
  325. * Disable the monkey patch of the browser `EventTarget` APIs.
  326. *
  327. * By default, `zone.js` monkey patches EventTarget APIs. The callbacks of the
  328. * `addEventListener()` run in the same zone when the `addEventListener()` is called.
  329. *
  330. * Consider the following example:
  331. *
  332. * ```ts
  333. * const zone = Zone.current.fork({name: 'myZone'});
  334. * zone.run(() => {
  335. * div.addEventListener('click', () => {
  336. * console.log('div event listener is invoked in the zone', Zone.current.name);
  337. * // the output is 'div event listener is invoked in the zone myZone'.
  338. * });
  339. * });
  340. * ```
  341. *
  342. * If you set `__Zone_disable_EventTarget = true` before importing `zone.js`,
  343. * `zone.js` does not monkey patch EventTarget API and the above code
  344. * outputs 'clicked <root>'.
  345. *
  346. */
  347. __Zone_disable_EventTarget?: boolean;
  348. /**
  349. * Disable the monkey patch of the browser `FileReader` APIs.
  350. */
  351. __Zone_disable_FileReader?: boolean;
  352. /**
  353. * Disable the monkey patch of the browser `MutationObserver` APIs.
  354. */
  355. __Zone_disable_MutationObserver?: boolean;
  356. /**
  357. * Disable the monkey patch of the browser `IntersectionObserver` APIs.
  358. */
  359. __Zone_disable_IntersectionObserver?: boolean;
  360. /**
  361. * Disable the monkey patch of the browser onProperty APIs(such as onclick).
  362. *
  363. * By default, `zone.js` monkey patches onXXX properties (such as onclick). The callbacks of
  364. * onXXX properties run in the same zone when the onXXX properties is set.
  365. *
  366. * Consider the following example:
  367. *
  368. * ```ts
  369. * const zone = Zone.current.fork({name: 'myZone'});
  370. * zone.run(() => {
  371. * div.onclick = () => {
  372. * console.log('div click event listener is invoked in the zone', Zone.current.name);
  373. * // the output will be 'div click event listener is invoked in the zone myZone'
  374. * }
  375. * });
  376. * ```
  377. *
  378. * If you set `__Zone_disable_on_property = true` before importing `zone.js`,
  379. * `zone.js` does not monkey patch onXXX properties and the above code
  380. * outputs 'clicked <root>'.
  381. *
  382. */
  383. __Zone_disable_on_property?: boolean;
  384. /**
  385. * Disable the monkey patch of the browser `customElements` APIs.
  386. *
  387. * By default, `zone.js` monkey patches `customElements` APIs to make callbacks run in the
  388. * same zone when the `customElements.define()` is called.
  389. *
  390. * Consider the following example:
  391. *
  392. * ```ts
  393. * class TestCustomElement extends HTMLElement {
  394. * constructor() { super(); }
  395. * connectedCallback() {}
  396. * disconnectedCallback() {}
  397. * attributeChangedCallback(attrName, oldVal, newVal) {}
  398. * adoptedCallback() {}
  399. * formAssociatedCallback(form) {}
  400. * formDisabledCallback(isDisabled) {}
  401. * formResetCallback() {}
  402. * formStateRestoreCallback(state, reason) {}
  403. * }
  404. *
  405. * const zone = Zone.fork({name: 'myZone'});
  406. * zone.run(() => {
  407. * customElements.define('x-elem', TestCustomElement);
  408. * });
  409. * ```
  410. *
  411. * All those callbacks defined in TestCustomElement runs in the zone when
  412. * the `customElements.define()` is called.
  413. *
  414. * If you set `__Zone_disable_customElements = true` before importing `zone.js`,
  415. * `zone.js` does not monkey patch `customElements` APIs and the above code
  416. * runs inside <root> zone.
  417. */
  418. __Zone_disable_customElements?: boolean;
  419. /**
  420. * Disable the monkey patch of the browser `XMLHttpRequest` APIs.
  421. *
  422. * By default, `zone.js` monkey patches `XMLHttpRequest` APIs to make XMLHttpRequest act
  423. * as macroTask.
  424. *
  425. * Consider the following example:
  426. *
  427. * ```ts
  428. * const zone = Zone.current.fork({
  429. * name: 'myZone',
  430. * onScheduleTask: (delegate, curr, target, task) => {
  431. * console.log('task is scheduled', task.type, task.source, task.zone.name);
  432. * return delegate.scheduleTask(target, task);
  433. * }
  434. * })
  435. * const xhr = new XMLHttpRequest();
  436. * zone.run(() => {
  437. * xhr.onload = function() {};
  438. * xhr.open('get', '/', true);
  439. * xhr.send();
  440. * });
  441. * ```
  442. *
  443. * In this example, the instance of XMLHttpRequest runs in the zone and acts as a macroTask. The
  444. * output is 'task is scheduled macroTask, XMLHttpRequest.send, zone'.
  445. *
  446. * If you set `__Zone_disable_XHR = true` before importing `zone.js`,
  447. * `zone.js` does not monkey patch `XMLHttpRequest` APIs and the above onScheduleTask callback
  448. * will not be called.
  449. *
  450. */
  451. __Zone_disable_XHR?: boolean;
  452. /**
  453. * Disable the monkey patch of the browser geolocation APIs.
  454. *
  455. * By default, `zone.js` monkey patches geolocation APIs to make callbacks run in the same zone
  456. * when those APIs are called.
  457. *
  458. * Consider the following examples:
  459. *
  460. * ```ts
  461. * const zone = Zone.current.fork({
  462. * name: 'myZone'
  463. * });
  464. *
  465. * zone.run(() => {
  466. * navigator.geolocation.getCurrentPosition(pos => {
  467. * console.log('navigator.getCurrentPosition() callback is invoked in the zone',
  468. * Zone.current.name);
  469. * // output is 'navigator.getCurrentPosition() callback is invoked in the zone myZone'.
  470. * }
  471. * });
  472. * ```
  473. *
  474. * If set you `__Zone_disable_geolocation = true` before importing `zone.js`,
  475. * `zone.js` does not monkey patch geolocation APIs and the above code
  476. * outputs 'getCurrentPosition <root>'.
  477. *
  478. */
  479. __Zone_disable_geolocation?: boolean;
  480. /**
  481. * Disable the monkey patch of the browser `canvas` APIs.
  482. *
  483. * By default, `zone.js` monkey patches `canvas` APIs to make callbacks run in the same zone
  484. * when those APIs are called.
  485. *
  486. * Consider the following example:
  487. *
  488. * ```ts
  489. * const zone = Zone.current.fork({
  490. * name: 'myZone'
  491. * });
  492. *
  493. * zone.run(() => {
  494. * canvas.toBlob(blog => {
  495. * console.log('canvas.toBlob() callback is invoked in the zone', Zone.current.name);
  496. * // output is 'canvas.toBlob() callback is invoked in the zone myZone'.
  497. * }
  498. * });
  499. * ```
  500. *
  501. * If you set `__Zone_disable_canvas = true` before importing `zone.js`,
  502. * `zone.js` does not monkey patch `canvas` APIs and the above code
  503. * outputs 'canvas.toBlob <root>'.
  504. */
  505. __Zone_disable_canvas?: boolean;
  506. /**
  507. * Disable the `Promise` monkey patch.
  508. *
  509. * By default, `zone.js` monkey patches `Promise` APIs to make the `then()/catch()` callbacks in
  510. * the same zone when those callbacks are called.
  511. *
  512. * Consider the following examples:
  513. *
  514. * ```ts
  515. * const zone = Zone.current.fork({name: 'myZone'});
  516. *
  517. * const p = Promise.resolve(1);
  518. *
  519. * zone.run(() => {
  520. * p.then(() => {
  521. * console.log('then() callback is invoked in the zone', Zone.current.name);
  522. * // output is 'then() callback is invoked in the zone myZone'.
  523. * });
  524. * });
  525. * ```
  526. *
  527. * If you set `__Zone_disable_ZoneAwarePromise = true` before importing `zone.js`,
  528. * `zone.js` does not monkey patch `Promise` APIs and the above code
  529. * outputs 'promise then callback <root>'.
  530. */
  531. __Zone_disable_ZoneAwarePromise?: boolean;
  532. /**
  533. * Define event names that users don't want monkey patched by the `zone.js`.
  534. *
  535. * By default, `zone.js` monkey patches EventTarget.addEventListener(). The event listener
  536. * callback runs in the same zone when the addEventListener() is called.
  537. *
  538. * Sometimes, you don't want all of the event names used in this patched version because it
  539. * impacts performance. For example, you might want `scroll` or `mousemove` event listeners to
  540. * run the native `addEventListener()` for better performance.
  541. *
  542. * Users can achieve this goal by defining `__zone_symbol__UNPATCHED_EVENTS = ['scroll',
  543. * 'mousemove'];` before importing `zone.js`.
  544. */
  545. __zone_symbol__UNPATCHED_EVENTS?: string[];
  546. /**
  547. * Define a list of `on` properties to be ignored when being monkey patched by the `zone.js`.
  548. *
  549. * By default, `zone.js` monkey patches `on` properties on inbuilt browser classes as
  550. * `WebSocket`, `XMLHttpRequest`, `Worker`, `HTMLElement` and others (see `patchTargets` in
  551. * `propertyDescriptorPatch`). `on` properties may be `WebSocket.prototype.onclose`,
  552. * `XMLHttpRequest.prototype.onload`, etc.
  553. *
  554. * Sometimes, we're not able to customise third-party libraries, which setup `on` listeners.
  555. * Given a library creates a `Websocket` and sets `socket.onmessage`, this will impact
  556. * performance if the `onmessage` property is set within the Angular zone, because this will
  557. * trigger change detection on any message coming through the socket. We can exclude specific
  558. * targets and their `on` properties from being patched by zone.js.
  559. *
  560. * Users can achieve this by defining `__Zone_ignore_on_properties`, it expects an array of
  561. * objects where `target` is the actual object `on` properties will be set on:
  562. * ```
  563. * __Zone_ignore_on_properties = [
  564. * {
  565. * target: WebSocket.prototype,
  566. * ignoreProperties: ['message', 'close', 'open']
  567. * }
  568. * ];
  569. * ```
  570. *
  571. * In order to check whether `on` properties have been successfully ignored or not, it's enough
  572. * to open the console in the browser, run `WebSocket.prototype` and expand the object, we
  573. * should see the following:
  574. * ```
  575. * {
  576. * __zone_symbol__ononclosepatched: true,
  577. * __zone_symbol__ononerrorpatched: true,
  578. * __zone_symbol__ononmessagepatched: true,
  579. * __zone_symbol__ononopenpatched: true
  580. * }
  581. * ```
  582. * These `__zone_symbol__*` properties are set by zone.js when `on` properties have been patched
  583. * previously. When `__Zone_ignore_on_properties` is setup, we should not see those properties
  584. * on targets.
  585. */
  586. __Zone_ignore_on_properties?: {
  587. target: any;
  588. ignoreProperties: string[];
  589. }[];
  590. /**
  591. * Define the event names of the passive listeners.
  592. *
  593. * To add passive event listeners, you can use `elem.addEventListener('scroll', listener,
  594. * {passive: true});` or implement your own `EventManagerPlugin`.
  595. *
  596. * You can also define a global variable as follows:
  597. *
  598. * ```
  599. * __zone_symbol__PASSIVE_EVENTS = ['scroll'];
  600. * ```
  601. *
  602. * The preceding code makes all scroll event listeners passive.
  603. */
  604. __zone_symbol__PASSIVE_EVENTS?: string[];
  605. /**
  606. * Disable wrapping uncaught promise rejection.
  607. *
  608. * By default, `zone.js` throws the original error occurs in the uncaught promise rejection.
  609. *
  610. * If you set `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = false;` before
  611. * importing `zone.js`, `zone.js` will wrap the uncaught promise rejection in a new `Error`
  612. * object which contains additional information such as a value of the rejection and a stack
  613. * trace.
  614. */
  615. __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION?: boolean;
  616. /**
  617. * https://github.com/angular/angular/issues/47579
  618. *
  619. * Enables the default `beforeunload` handling behavior, allowing the result of the event
  620. * handling invocation to be set on the event's `returnValue`. The browser may then prompt
  621. * the user with a string returned from the event handler.
  622. */
  623. __zone_symbol__enable_beforeunload?: boolean;
  624. }
  625. /**
  626. * Interface of `zone-testing.js` test configurations.
  627. *
  628. * You can define the following configurations on the `window` or `global` object before
  629. * importing `zone-testing.js` to change `zone-testing.js` default behaviors in the test runner.
  630. */
  631. interface ZoneTestConfigurations {
  632. /**
  633. * Disable the Jasmine integration.
  634. *
  635. * In the `zone-testing.js` bundle, by default, `zone-testing.js` monkey patches Jasmine APIs
  636. * to make Jasmine APIs run in specified zone.
  637. *
  638. * 1. Make the `describe()`/`xdescribe()`/`fdescribe()` methods run in the syncTestZone.
  639. * 2. Make the `it()`/`xit()`/`fit()`/`beforeEach()`/`afterEach()`/`beforeAll()`/`afterAll()`
  640. * methods run in the ProxyZone.
  641. *
  642. * With this patch, `async()`/`fakeAsync()` can work with the Jasmine runner.
  643. *
  644. * If you set `__Zone_disable_jasmine = true` before importing `zone-testing.js`,
  645. * `zone-testing.js` does not monkey patch the jasmine APIs and the `async()`/`fakeAsync()`
  646. * cannot work with the Jasmine runner any longer.
  647. */
  648. __Zone_disable_jasmine?: boolean;
  649. /**
  650. * Disable the Mocha integration.
  651. *
  652. * In the `zone-testing.js` bundle, by default, `zone-testing.js` monkey patches the Mocha APIs
  653. * to make Mocha APIs run in the specified zone.
  654. *
  655. * 1. Make the `describe()`/`xdescribe()`/`fdescribe()` methods run in the syncTestZone.
  656. * 2. Make the `it()`/`xit()`/`fit()`/`beforeEach()`/`afterEach()`/`beforeAll()`/`afterAll()`
  657. * methods run in the ProxyZone.
  658. *
  659. * With this patch, `async()`/`fakeAsync()` can work with the Mocha runner.
  660. *
  661. * If you set `__Zone_disable_mocha = true` before importing `zone-testing.js`,
  662. * `zone-testing.js` does not monkey patch the Mocha APIs and the `async()/`fakeAsync()` can not
  663. * work with the Mocha runner any longer.
  664. */
  665. __Zone_disable_mocha?: boolean;
  666. /**
  667. * Disable the Jest integration.
  668. *
  669. * In the `zone-testing.js` bundle, by default, `zone-testing.js` monkey patches Jest APIs
  670. * to make Jest APIs run in the specified zone.
  671. *
  672. * 1. Make the `describe()`/`xdescribe()`/`fdescribe()` methods run in the syncTestZone.
  673. * 2. Make the `it()`/`xit()`/`fit()`/`beforeEach()`/`afterEach()`/`before()`/`after()` methods
  674. * run in the ProxyZone.
  675. *
  676. * With this patch, `async()`/`fakeAsync()` can work with the Jest runner.
  677. *
  678. * If you set `__Zone_disable_jest = true` before importing `zone-testing.js`,
  679. * `zone-testing.js` does not monkey patch the jest APIs and `async()`/`fakeAsync()` cannot
  680. * work with the Jest runner any longer.
  681. */
  682. __Zone_disable_jest?: boolean;
  683. /**
  684. * Disable monkey patch the jasmine clock APIs.
  685. *
  686. * By default, `zone-testing.js` monkey patches the `jasmine.clock()` API,
  687. * so the `jasmine.clock()` can work with the `fakeAsync()/tick()` API.
  688. *
  689. * Consider the following example:
  690. *
  691. * ```ts
  692. * describe('jasmine.clock integration', () => {
  693. * beforeEach(() => {
  694. * jasmine.clock().install();
  695. * });
  696. * afterEach(() => {
  697. * jasmine.clock().uninstall();
  698. * });
  699. * it('fakeAsync test', fakeAsync(() => {
  700. * setTimeout(spy, 100);
  701. * expect(spy).not.toHaveBeenCalled();
  702. * jasmine.clock().tick(100);
  703. * expect(spy).toHaveBeenCalled();
  704. * }));
  705. * });
  706. * ```
  707. *
  708. * In the `fakeAsync()` method, `jasmine.clock().tick()` works just like `tick()`.
  709. *
  710. * If you set `__zone_symbol__fakeAsyncDisablePatchingClock = true` before importing
  711. * `zone-testing.js`,`zone-testing.js` does not monkey patch the `jasmine.clock()` APIs and the
  712. * `jasmine.clock()` cannot work with `fakeAsync()` any longer.
  713. */
  714. __zone_symbol__fakeAsyncDisablePatchingClock?: boolean;
  715. /**
  716. * Enable auto running into `fakeAsync()` when installing the `jasmine.clock()`.
  717. *
  718. * By default, `zone-testing.js` does not automatically run into `fakeAsync()`
  719. * if the `jasmine.clock().install()` is called.
  720. *
  721. * Consider the following example:
  722. *
  723. * ```ts
  724. * describe('jasmine.clock integration', () => {
  725. * beforeEach(() => {
  726. * jasmine.clock().install();
  727. * });
  728. * afterEach(() => {
  729. * jasmine.clock().uninstall();
  730. * });
  731. * it('fakeAsync test', fakeAsync(() => {
  732. * setTimeout(spy, 100);
  733. * expect(spy).not.toHaveBeenCalled();
  734. * jasmine.clock().tick(100);
  735. * expect(spy).toHaveBeenCalled();
  736. * }));
  737. * });
  738. * ```
  739. *
  740. * You must run `fakeAsync()` to make test cases in the `FakeAsyncTestZone`.
  741. *
  742. * If you set `__zone_symbol__fakeAsyncAutoFakeAsyncWhenClockPatched = true` before importing
  743. * `zone-testing.js`, `zone-testing.js` can run test case automatically in the
  744. * `FakeAsyncTestZone` without calling the `fakeAsync()`.
  745. *
  746. * Consider the following example:
  747. *
  748. * ```ts
  749. * describe('jasmine.clock integration', () => {
  750. * beforeEach(() => {
  751. * jasmine.clock().install();
  752. * });
  753. * afterEach(() => {
  754. * jasmine.clock().uninstall();
  755. * });
  756. * it('fakeAsync test', () => { // here we don't need to call fakeAsync
  757. * setTimeout(spy, 100);
  758. * expect(spy).not.toHaveBeenCalled();
  759. * jasmine.clock().tick(100);
  760. * expect(spy).toHaveBeenCalled();
  761. * });
  762. * });
  763. * ```
  764. *
  765. */
  766. __zone_symbol__fakeAsyncAutoFakeAsyncWhenClockPatched?: boolean;
  767. /**
  768. * Enable waiting for the unresolved promise in the `async()` test.
  769. *
  770. * In the `async()` test, `AsyncTestZone` waits for all the asynchronous tasks to finish. By
  771. * default, if some promises remain unresolved, `AsyncTestZone` does not wait and reports that
  772. * it received an unexpected result.
  773. *
  774. * Consider the following example:
  775. *
  776. * ```ts
  777. * describe('wait never resolved promise', () => {
  778. * it('async with never resolved promise test', async(() => {
  779. * const p = new Promise(() => {});
  780. * p.then(() => {
  781. * // do some expectation.
  782. * });
  783. * }))
  784. * });
  785. * ```
  786. *
  787. * By default, this case passes, because the callback of `p.then()` is never called. Because `p`
  788. * is an unresolved promise, there is no pending asynchronous task, which means the `async()`
  789. * method does not wait.
  790. *
  791. * If you set `__zone_symbol__supportWaitUnResolvedChainedPromise = true`, the above case
  792. * times out, because `async()` will wait for the unresolved promise.
  793. */
  794. __zone_symbol__supportWaitUnResolvedChainedPromise?: boolean;
  795. }
  796. /**
  797. * The interface of the `zone.js` runtime configurations.
  798. *
  799. * These configurations can be defined on the `Zone` object after
  800. * importing zone.js to change behaviors. The differences between
  801. * the `ZoneRuntimeConfigurations` and the `ZoneGlobalConfigurations` are,
  802. *
  803. * 1. `ZoneGlobalConfigurations` must be defined on the `global/window` object before importing
  804. * `zone.js`. The value of the configuration cannot be changed at runtime.
  805. *
  806. * 2. `ZoneRuntimeConfigurations` must be defined on the `Zone` object after importing `zone.js`.
  807. * You can change the value of this configuration at runtime.
  808. *
  809. */
  810. interface ZoneRuntimeConfigurations {
  811. /**
  812. * Ignore outputting errors to the console when uncaught Promise errors occur.
  813. *
  814. * By default, if an uncaught Promise error occurs, `zone.js` outputs the
  815. * error to the console by calling `console.error()`.
  816. *
  817. * If you set `__zone_symbol__ignoreConsoleErrorUncaughtError = true`, `zone.js` does not output
  818. * the uncaught error to `console.error()`.
  819. */
  820. __zone_symbol__ignoreConsoleErrorUncaughtError?: boolean;
  821. }
  822. }
  823. export {};