a zip code crypto-currency system good for red ONLY

zone-node.js 97KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299
  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. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
  10. typeof define === 'function' && define.amd ? define(factory) :
  11. (factory());
  12. }(this, (function () { 'use strict';
  13. /**
  14. * @license
  15. * Copyright Google Inc. All Rights Reserved.
  16. *
  17. * Use of this source code is governed by an MIT-style license that can be
  18. * found in the LICENSE file at https://angular.io/license
  19. */
  20. var Zone$1 = (function (global) {
  21. var FUNCTION = 'function';
  22. var performance = global['performance'];
  23. function mark(name) {
  24. performance && performance['mark'] && performance['mark'](name);
  25. }
  26. function performanceMeasure(name, label) {
  27. performance && performance['measure'] && performance['measure'](name, label);
  28. }
  29. mark('Zone');
  30. if (global['Zone']) {
  31. throw new Error('Zone already loaded.');
  32. }
  33. var Zone = /** @class */ (function () {
  34. function Zone(parent, zoneSpec) {
  35. this._properties = null;
  36. this._parent = parent;
  37. this._name = zoneSpec ? zoneSpec.name || 'unnamed' : '<root>';
  38. this._properties = zoneSpec && zoneSpec.properties || {};
  39. this._zoneDelegate =
  40. new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec);
  41. }
  42. Zone.assertZonePatched = function () {
  43. if (global['Promise'] !== patches['ZoneAwarePromise']) {
  44. throw new Error('Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
  45. 'has been overwritten.\n' +
  46. 'Most likely cause is that a Promise polyfill has been loaded ' +
  47. 'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' +
  48. 'If you must load one, do so before loading zone.js.)');
  49. }
  50. };
  51. Object.defineProperty(Zone, "root", {
  52. get: function () {
  53. var zone = Zone.current;
  54. while (zone.parent) {
  55. zone = zone.parent;
  56. }
  57. return zone;
  58. },
  59. enumerable: true,
  60. configurable: true
  61. });
  62. Object.defineProperty(Zone, "current", {
  63. get: function () {
  64. return _currentZoneFrame.zone;
  65. },
  66. enumerable: true,
  67. configurable: true
  68. });
  69. Object.defineProperty(Zone, "currentTask", {
  70. get: function () {
  71. return _currentTask;
  72. },
  73. enumerable: true,
  74. configurable: true
  75. });
  76. Zone.__load_patch = function (name, fn) {
  77. if (patches.hasOwnProperty(name)) {
  78. throw Error('Already loaded patch: ' + name);
  79. }
  80. else if (!global['__Zone_disable_' + name]) {
  81. var perfName = 'Zone:' + name;
  82. mark(perfName);
  83. patches[name] = fn(global, Zone, _api);
  84. performanceMeasure(perfName, perfName);
  85. }
  86. };
  87. Object.defineProperty(Zone.prototype, "parent", {
  88. get: function () {
  89. return this._parent;
  90. },
  91. enumerable: true,
  92. configurable: true
  93. });
  94. Object.defineProperty(Zone.prototype, "name", {
  95. get: function () {
  96. return this._name;
  97. },
  98. enumerable: true,
  99. configurable: true
  100. });
  101. Zone.prototype.get = function (key) {
  102. var zone = this.getZoneWith(key);
  103. if (zone)
  104. return zone._properties[key];
  105. };
  106. Zone.prototype.getZoneWith = function (key) {
  107. var current = this;
  108. while (current) {
  109. if (current._properties.hasOwnProperty(key)) {
  110. return current;
  111. }
  112. current = current._parent;
  113. }
  114. return null;
  115. };
  116. Zone.prototype.fork = function (zoneSpec) {
  117. if (!zoneSpec)
  118. throw new Error('ZoneSpec required!');
  119. return this._zoneDelegate.fork(this, zoneSpec);
  120. };
  121. Zone.prototype.wrap = function (callback, source) {
  122. if (typeof callback !== FUNCTION) {
  123. throw new Error('Expecting function got: ' + callback);
  124. }
  125. var _callback = this._zoneDelegate.intercept(this, callback, source);
  126. var zone = this;
  127. return function () {
  128. return zone.runGuarded(_callback, this, arguments, source);
  129. };
  130. };
  131. Zone.prototype.run = function (callback, applyThis, applyArgs, source) {
  132. if (applyThis === void 0) { applyThis = undefined; }
  133. if (applyArgs === void 0) { applyArgs = null; }
  134. if (source === void 0) { source = null; }
  135. _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
  136. try {
  137. return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
  138. }
  139. finally {
  140. _currentZoneFrame = _currentZoneFrame.parent;
  141. }
  142. };
  143. Zone.prototype.runGuarded = function (callback, applyThis, applyArgs, source) {
  144. if (applyThis === void 0) { applyThis = null; }
  145. if (applyArgs === void 0) { applyArgs = null; }
  146. if (source === void 0) { source = null; }
  147. _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
  148. try {
  149. try {
  150. return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
  151. }
  152. catch (error) {
  153. if (this._zoneDelegate.handleError(this, error)) {
  154. throw error;
  155. }
  156. }
  157. }
  158. finally {
  159. _currentZoneFrame = _currentZoneFrame.parent;
  160. }
  161. };
  162. Zone.prototype.runTask = function (task, applyThis, applyArgs) {
  163. if (task.zone != this) {
  164. throw new Error('A task can only be run in the zone of creation! (Creation: ' +
  165. (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
  166. }
  167. // https://github.com/angular/zone.js/issues/778, sometimes eventTask
  168. // will run in notScheduled(canceled) state, we should not try to
  169. // run such kind of task but just return
  170. // we have to define an variable here, if not
  171. // typescript compiler will complain below
  172. var isNotScheduled = task.state === notScheduled;
  173. if (isNotScheduled && task.type === eventTask) {
  174. return;
  175. }
  176. var reEntryGuard = task.state != running;
  177. reEntryGuard && task._transitionTo(running, scheduled);
  178. task.runCount++;
  179. var previousTask = _currentTask;
  180. _currentTask = task;
  181. _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
  182. try {
  183. if (task.type == macroTask && task.data && !task.data.isPeriodic) {
  184. task.cancelFn = null;
  185. }
  186. try {
  187. return this._zoneDelegate.invokeTask(this, task, applyThis, applyArgs);
  188. }
  189. catch (error) {
  190. if (this._zoneDelegate.handleError(this, error)) {
  191. throw error;
  192. }
  193. }
  194. }
  195. finally {
  196. // if the task's state is notScheduled or unknown, then it has already been cancelled
  197. // we should not reset the state to scheduled
  198. if (task.state !== notScheduled && task.state !== unknown) {
  199. if (task.type == eventTask || (task.data && task.data.isPeriodic)) {
  200. reEntryGuard && task._transitionTo(scheduled, running);
  201. }
  202. else {
  203. task.runCount = 0;
  204. this._updateTaskCount(task, -1);
  205. reEntryGuard &&
  206. task._transitionTo(notScheduled, running, notScheduled);
  207. }
  208. }
  209. _currentZoneFrame = _currentZoneFrame.parent;
  210. _currentTask = previousTask;
  211. }
  212. };
  213. Zone.prototype.scheduleTask = function (task) {
  214. if (task.zone && task.zone !== this) {
  215. // check if the task was rescheduled, the newZone
  216. // should not be the children of the original zone
  217. var newZone = this;
  218. while (newZone) {
  219. if (newZone === task.zone) {
  220. throw Error("can not reschedule task to " + this
  221. .name + " which is descendants of the original zone " + task.zone.name);
  222. }
  223. newZone = newZone.parent;
  224. }
  225. }
  226. task._transitionTo(scheduling, notScheduled);
  227. var zoneDelegates = [];
  228. task._zoneDelegates = zoneDelegates;
  229. task._zone = this;
  230. try {
  231. task = this._zoneDelegate.scheduleTask(this, task);
  232. }
  233. catch (err) {
  234. // should set task's state to unknown when scheduleTask throw error
  235. // because the err may from reschedule, so the fromState maybe notScheduled
  236. task._transitionTo(unknown, scheduling, notScheduled);
  237. // TODO: @JiaLiPassion, should we check the result from handleError?
  238. this._zoneDelegate.handleError(this, err);
  239. throw err;
  240. }
  241. if (task._zoneDelegates === zoneDelegates) {
  242. // we have to check because internally the delegate can reschedule the task.
  243. this._updateTaskCount(task, 1);
  244. }
  245. if (task.state == scheduling) {
  246. task._transitionTo(scheduled, scheduling);
  247. }
  248. return task;
  249. };
  250. Zone.prototype.scheduleMicroTask = function (source, callback, data, customSchedule) {
  251. return this.scheduleTask(new ZoneTask(microTask, source, callback, data, customSchedule, null));
  252. };
  253. Zone.prototype.scheduleMacroTask = function (source, callback, data, customSchedule, customCancel) {
  254. return this.scheduleTask(new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel));
  255. };
  256. Zone.prototype.scheduleEventTask = function (source, callback, data, customSchedule, customCancel) {
  257. return this.scheduleTask(new ZoneTask(eventTask, source, callback, data, customSchedule, customCancel));
  258. };
  259. Zone.prototype.cancelTask = function (task) {
  260. if (task.zone != this)
  261. throw new Error('A task can only be cancelled in the zone of creation! (Creation: ' +
  262. (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
  263. task._transitionTo(canceling, scheduled, running);
  264. try {
  265. this._zoneDelegate.cancelTask(this, task);
  266. }
  267. catch (err) {
  268. // if error occurs when cancelTask, transit the state to unknown
  269. task._transitionTo(unknown, canceling);
  270. this._zoneDelegate.handleError(this, err);
  271. throw err;
  272. }
  273. this._updateTaskCount(task, -1);
  274. task._transitionTo(notScheduled, canceling);
  275. task.runCount = 0;
  276. return task;
  277. };
  278. Zone.prototype._updateTaskCount = function (task, count) {
  279. var zoneDelegates = task._zoneDelegates;
  280. if (count == -1) {
  281. task._zoneDelegates = null;
  282. }
  283. for (var i = 0; i < zoneDelegates.length; i++) {
  284. zoneDelegates[i]._updateTaskCount(task.type, count);
  285. }
  286. };
  287. Zone.__symbol__ = __symbol__;
  288. return Zone;
  289. }());
  290. var DELEGATE_ZS = {
  291. name: '',
  292. onHasTask: function (delegate, _, target, hasTaskState) {
  293. return delegate.hasTask(target, hasTaskState);
  294. },
  295. onScheduleTask: function (delegate, _, target, task) {
  296. return delegate.scheduleTask(target, task);
  297. },
  298. onInvokeTask: function (delegate, _, target, task, applyThis, applyArgs) { return delegate.invokeTask(target, task, applyThis, applyArgs); },
  299. onCancelTask: function (delegate, _, target, task) {
  300. return delegate.cancelTask(target, task);
  301. }
  302. };
  303. var ZoneDelegate = /** @class */ (function () {
  304. function ZoneDelegate(zone, parentDelegate, zoneSpec) {
  305. this._taskCounts = { 'microTask': 0, 'macroTask': 0, 'eventTask': 0 };
  306. this.zone = zone;
  307. this._parentDelegate = parentDelegate;
  308. this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate._forkZS);
  309. this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate._forkDlgt);
  310. this._forkCurrZone = zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate.zone);
  311. this._interceptZS =
  312. zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS);
  313. this._interceptDlgt =
  314. zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt);
  315. this._interceptCurrZone =
  316. zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate.zone);
  317. this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate._invokeZS);
  318. this._invokeDlgt =
  319. zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt);
  320. this._invokeCurrZone = zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate.zone);
  321. this._handleErrorZS =
  322. zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS);
  323. this._handleErrorDlgt =
  324. zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt);
  325. this._handleErrorCurrZone =
  326. zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate.zone);
  327. this._scheduleTaskZS =
  328. zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS);
  329. this._scheduleTaskDlgt =
  330. zoneSpec && (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt);
  331. this._scheduleTaskCurrZone =
  332. zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate.zone);
  333. this._invokeTaskZS =
  334. zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS);
  335. this._invokeTaskDlgt =
  336. zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt);
  337. this._invokeTaskCurrZone =
  338. zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate.zone);
  339. this._cancelTaskZS =
  340. zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS);
  341. this._cancelTaskDlgt =
  342. zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt);
  343. this._cancelTaskCurrZone =
  344. zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate.zone);
  345. this._hasTaskZS = null;
  346. this._hasTaskDlgt = null;
  347. this._hasTaskDlgtOwner = null;
  348. this._hasTaskCurrZone = null;
  349. var zoneSpecHasTask = zoneSpec && zoneSpec.onHasTask;
  350. var parentHasTask = parentDelegate && parentDelegate._hasTaskZS;
  351. if (zoneSpecHasTask || parentHasTask) {
  352. // If we need to report hasTask, than this ZS needs to do ref counting on tasks. In such
  353. // a case all task related interceptors must go through this ZD. We can't short circuit it.
  354. this._hasTaskZS = zoneSpecHasTask ? zoneSpec : DELEGATE_ZS;
  355. this._hasTaskDlgt = parentDelegate;
  356. this._hasTaskDlgtOwner = this;
  357. this._hasTaskCurrZone = zone;
  358. if (!zoneSpec.onScheduleTask) {
  359. this._scheduleTaskZS = DELEGATE_ZS;
  360. this._scheduleTaskDlgt = parentDelegate;
  361. this._scheduleTaskCurrZone = this.zone;
  362. }
  363. if (!zoneSpec.onInvokeTask) {
  364. this._invokeTaskZS = DELEGATE_ZS;
  365. this._invokeTaskDlgt = parentDelegate;
  366. this._invokeTaskCurrZone = this.zone;
  367. }
  368. if (!zoneSpec.onCancelTask) {
  369. this._cancelTaskZS = DELEGATE_ZS;
  370. this._cancelTaskDlgt = parentDelegate;
  371. this._cancelTaskCurrZone = this.zone;
  372. }
  373. }
  374. }
  375. ZoneDelegate.prototype.fork = function (targetZone, zoneSpec) {
  376. return this._forkZS ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) :
  377. new Zone(targetZone, zoneSpec);
  378. };
  379. ZoneDelegate.prototype.intercept = function (targetZone, callback, source) {
  380. return this._interceptZS ?
  381. this._interceptZS.onIntercept(this._interceptDlgt, this._interceptCurrZone, targetZone, callback, source) :
  382. callback;
  383. };
  384. ZoneDelegate.prototype.invoke = function (targetZone, callback, applyThis, applyArgs, source) {
  385. return this._invokeZS ?
  386. this._invokeZS.onInvoke(this._invokeDlgt, this._invokeCurrZone, targetZone, callback, applyThis, applyArgs, source) :
  387. callback.apply(applyThis, applyArgs);
  388. };
  389. ZoneDelegate.prototype.handleError = function (targetZone, error) {
  390. return this._handleErrorZS ?
  391. this._handleErrorZS.onHandleError(this._handleErrorDlgt, this._handleErrorCurrZone, targetZone, error) :
  392. true;
  393. };
  394. ZoneDelegate.prototype.scheduleTask = function (targetZone, task) {
  395. var returnTask = task;
  396. if (this._scheduleTaskZS) {
  397. if (this._hasTaskZS) {
  398. returnTask._zoneDelegates.push(this._hasTaskDlgtOwner);
  399. }
  400. returnTask = this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt, this._scheduleTaskCurrZone, targetZone, task);
  401. if (!returnTask)
  402. returnTask = task;
  403. }
  404. else {
  405. if (task.scheduleFn) {
  406. task.scheduleFn(task);
  407. }
  408. else if (task.type == microTask) {
  409. scheduleMicroTask(task);
  410. }
  411. else {
  412. throw new Error('Task is missing scheduleFn.');
  413. }
  414. }
  415. return returnTask;
  416. };
  417. ZoneDelegate.prototype.invokeTask = function (targetZone, task, applyThis, applyArgs) {
  418. return this._invokeTaskZS ?
  419. this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this._invokeTaskCurrZone, targetZone, task, applyThis, applyArgs) :
  420. task.callback.apply(applyThis, applyArgs);
  421. };
  422. ZoneDelegate.prototype.cancelTask = function (targetZone, task) {
  423. var value;
  424. if (this._cancelTaskZS) {
  425. value = this._cancelTaskZS.onCancelTask(this._cancelTaskDlgt, this._cancelTaskCurrZone, targetZone, task);
  426. }
  427. else {
  428. if (!task.cancelFn) {
  429. throw Error('Task is not cancelable');
  430. }
  431. value = task.cancelFn(task);
  432. }
  433. return value;
  434. };
  435. ZoneDelegate.prototype.hasTask = function (targetZone, isEmpty) {
  436. // hasTask should not throw error so other ZoneDelegate
  437. // can still trigger hasTask callback
  438. try {
  439. return this._hasTaskZS &&
  440. this._hasTaskZS.onHasTask(this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
  441. }
  442. catch (err) {
  443. this.handleError(targetZone, err);
  444. }
  445. };
  446. ZoneDelegate.prototype._updateTaskCount = function (type, count) {
  447. var counts = this._taskCounts;
  448. var prev = counts[type];
  449. var next = counts[type] = prev + count;
  450. if (next < 0) {
  451. throw new Error('More tasks executed then were scheduled.');
  452. }
  453. if (prev == 0 || next == 0) {
  454. var isEmpty = {
  455. microTask: counts['microTask'] > 0,
  456. macroTask: counts['macroTask'] > 0,
  457. eventTask: counts['eventTask'] > 0,
  458. change: type
  459. };
  460. this.hasTask(this.zone, isEmpty);
  461. }
  462. };
  463. return ZoneDelegate;
  464. }());
  465. var ZoneTask = /** @class */ (function () {
  466. function ZoneTask(type, source, callback, options, scheduleFn, cancelFn) {
  467. this._zone = null;
  468. this.runCount = 0;
  469. this._zoneDelegates = null;
  470. this._state = 'notScheduled';
  471. this.type = type;
  472. this.source = source;
  473. this.data = options;
  474. this.scheduleFn = scheduleFn;
  475. this.cancelFn = cancelFn;
  476. this.callback = callback;
  477. var self = this;
  478. // TODO: @JiaLiPassion options should have interface
  479. if (type === eventTask && options && options.useG) {
  480. this.invoke = ZoneTask.invokeTask;
  481. }
  482. else {
  483. this.invoke = function () {
  484. return ZoneTask.invokeTask.call(global, self, this, arguments);
  485. };
  486. }
  487. }
  488. ZoneTask.invokeTask = function (task, target, args) {
  489. if (!task) {
  490. task = this;
  491. }
  492. _numberOfNestedTaskFrames++;
  493. try {
  494. task.runCount++;
  495. return task.zone.runTask(task, target, args);
  496. }
  497. finally {
  498. if (_numberOfNestedTaskFrames == 1) {
  499. drainMicroTaskQueue();
  500. }
  501. _numberOfNestedTaskFrames--;
  502. }
  503. };
  504. Object.defineProperty(ZoneTask.prototype, "zone", {
  505. get: function () {
  506. return this._zone;
  507. },
  508. enumerable: true,
  509. configurable: true
  510. });
  511. Object.defineProperty(ZoneTask.prototype, "state", {
  512. get: function () {
  513. return this._state;
  514. },
  515. enumerable: true,
  516. configurable: true
  517. });
  518. ZoneTask.prototype.cancelScheduleRequest = function () {
  519. this._transitionTo(notScheduled, scheduling);
  520. };
  521. ZoneTask.prototype._transitionTo = function (toState, fromState1, fromState2) {
  522. if (this._state === fromState1 || this._state === fromState2) {
  523. this._state = toState;
  524. if (toState == notScheduled) {
  525. this._zoneDelegates = null;
  526. }
  527. }
  528. else {
  529. throw new Error(this.type + " '" + this.source + "': can not transition to '" + toState + "', expecting state '" + fromState1 + "'" + (fromState2 ?
  530. ' or \'' + fromState2 + '\'' :
  531. '') + ", was '" + this._state + "'.");
  532. }
  533. };
  534. ZoneTask.prototype.toString = function () {
  535. if (this.data && typeof this.data.handleId !== 'undefined') {
  536. return this.data.handleId;
  537. }
  538. else {
  539. return Object.prototype.toString.call(this);
  540. }
  541. };
  542. // add toJSON method to prevent cyclic error when
  543. // call JSON.stringify(zoneTask)
  544. ZoneTask.prototype.toJSON = function () {
  545. return {
  546. type: this.type,
  547. state: this.state,
  548. source: this.source,
  549. zone: this.zone.name,
  550. runCount: this.runCount
  551. };
  552. };
  553. return ZoneTask;
  554. }());
  555. //////////////////////////////////////////////////////
  556. //////////////////////////////////////////////////////
  557. /// MICROTASK QUEUE
  558. //////////////////////////////////////////////////////
  559. //////////////////////////////////////////////////////
  560. var symbolSetTimeout = __symbol__('setTimeout');
  561. var symbolPromise = __symbol__('Promise');
  562. var symbolThen = __symbol__('then');
  563. var _microTaskQueue = [];
  564. var _isDrainingMicrotaskQueue = false;
  565. var nativeMicroTaskQueuePromise;
  566. function scheduleMicroTask(task) {
  567. // if we are not running in any task, and there has not been anything scheduled
  568. // we must bootstrap the initial task creation by manually scheduling the drain
  569. if (_numberOfNestedTaskFrames === 0 && _microTaskQueue.length === 0) {
  570. // We are not running in Task, so we need to kickstart the microtask queue.
  571. if (!nativeMicroTaskQueuePromise) {
  572. if (global[symbolPromise]) {
  573. nativeMicroTaskQueuePromise = global[symbolPromise].resolve(0);
  574. }
  575. }
  576. if (nativeMicroTaskQueuePromise) {
  577. nativeMicroTaskQueuePromise[symbolThen](drainMicroTaskQueue);
  578. }
  579. else {
  580. global[symbolSetTimeout](drainMicroTaskQueue, 0);
  581. }
  582. }
  583. task && _microTaskQueue.push(task);
  584. }
  585. function drainMicroTaskQueue() {
  586. if (!_isDrainingMicrotaskQueue) {
  587. _isDrainingMicrotaskQueue = true;
  588. while (_microTaskQueue.length) {
  589. var queue = _microTaskQueue;
  590. _microTaskQueue = [];
  591. for (var i = 0; i < queue.length; i++) {
  592. var task = queue[i];
  593. try {
  594. task.zone.runTask(task, null, null);
  595. }
  596. catch (error) {
  597. _api.onUnhandledError(error);
  598. }
  599. }
  600. }
  601. _api.microtaskDrainDone();
  602. _isDrainingMicrotaskQueue = false;
  603. }
  604. }
  605. //////////////////////////////////////////////////////
  606. //////////////////////////////////////////////////////
  607. /// BOOTSTRAP
  608. //////////////////////////////////////////////////////
  609. //////////////////////////////////////////////////////
  610. var NO_ZONE = { name: 'NO ZONE' };
  611. var notScheduled = 'notScheduled', scheduling = 'scheduling', scheduled = 'scheduled', running = 'running', canceling = 'canceling', unknown = 'unknown';
  612. var microTask = 'microTask', macroTask = 'macroTask', eventTask = 'eventTask';
  613. var patches = {};
  614. var _api = {
  615. symbol: __symbol__,
  616. currentZoneFrame: function () { return _currentZoneFrame; },
  617. onUnhandledError: noop,
  618. microtaskDrainDone: noop,
  619. scheduleMicroTask: scheduleMicroTask,
  620. showUncaughtError: function () { return !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; },
  621. patchEventTarget: function () { return []; },
  622. patchOnProperties: noop,
  623. patchMethod: function () { return noop; },
  624. bindArguments: function () { return null; },
  625. setNativePromise: function (NativePromise) {
  626. // sometimes NativePromise.resolve static function
  627. // is not ready yet, (such as core-js/es6.promise)
  628. // so we need to check here.
  629. if (NativePromise && typeof NativePromise.resolve === FUNCTION) {
  630. nativeMicroTaskQueuePromise = NativePromise.resolve(0);
  631. }
  632. },
  633. };
  634. var _currentZoneFrame = { parent: null, zone: new Zone(null, null) };
  635. var _currentTask = null;
  636. var _numberOfNestedTaskFrames = 0;
  637. function noop() { }
  638. function __symbol__(name) {
  639. return '__zone_symbol__' + name;
  640. }
  641. performanceMeasure('Zone', 'Zone');
  642. return global['Zone'] = Zone;
  643. })(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
  644. Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) {
  645. var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  646. var ObjectDefineProperty = Object.defineProperty;
  647. function readableObjectToString(obj) {
  648. if (obj && obj.toString === Object.prototype.toString) {
  649. var className = obj.constructor && obj.constructor.name;
  650. return (className ? className : '') + ': ' + JSON.stringify(obj);
  651. }
  652. return obj ? obj.toString() : Object.prototype.toString.call(obj);
  653. }
  654. var __symbol__ = api.symbol;
  655. var _uncaughtPromiseErrors = [];
  656. var symbolPromise = __symbol__('Promise');
  657. var symbolThen = __symbol__('then');
  658. var creationTrace = '__creationTrace__';
  659. api.onUnhandledError = function (e) {
  660. if (api.showUncaughtError()) {
  661. var rejection = e && e.rejection;
  662. if (rejection) {
  663. console.error('Unhandled Promise rejection:', rejection instanceof Error ? rejection.message : rejection, '; Zone:', e.zone.name, '; Task:', e.task && e.task.source, '; Value:', rejection, rejection instanceof Error ? rejection.stack : undefined);
  664. }
  665. else {
  666. console.error(e);
  667. }
  668. }
  669. };
  670. api.microtaskDrainDone = function () {
  671. while (_uncaughtPromiseErrors.length) {
  672. var _loop_1 = function () {
  673. var uncaughtPromiseError = _uncaughtPromiseErrors.shift();
  674. try {
  675. uncaughtPromiseError.zone.runGuarded(function () {
  676. throw uncaughtPromiseError;
  677. });
  678. }
  679. catch (error) {
  680. handleUnhandledRejection(error);
  681. }
  682. };
  683. while (_uncaughtPromiseErrors.length) {
  684. _loop_1();
  685. }
  686. }
  687. };
  688. var UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__('unhandledPromiseRejectionHandler');
  689. function handleUnhandledRejection(e) {
  690. api.onUnhandledError(e);
  691. try {
  692. var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL];
  693. if (handler && typeof handler === 'function') {
  694. handler.call(this, e);
  695. }
  696. }
  697. catch (err) {
  698. }
  699. }
  700. function isThenable(value) {
  701. return value && value.then;
  702. }
  703. function forwardResolution(value) {
  704. return value;
  705. }
  706. function forwardRejection(rejection) {
  707. return ZoneAwarePromise.reject(rejection);
  708. }
  709. var symbolState = __symbol__('state');
  710. var symbolValue = __symbol__('value');
  711. var symbolFinally = __symbol__('finally');
  712. var symbolParentPromiseValue = __symbol__('parentPromiseValue');
  713. var symbolParentPromiseState = __symbol__('parentPromiseState');
  714. var source = 'Promise.then';
  715. var UNRESOLVED = null;
  716. var RESOLVED = true;
  717. var REJECTED = false;
  718. var REJECTED_NO_CATCH = 0;
  719. function makeResolver(promise, state) {
  720. return function (v) {
  721. try {
  722. resolvePromise(promise, state, v);
  723. }
  724. catch (err) {
  725. resolvePromise(promise, false, err);
  726. }
  727. // Do not return value or you will break the Promise spec.
  728. };
  729. }
  730. var once = function () {
  731. var wasCalled = false;
  732. return function wrapper(wrappedFunction) {
  733. return function () {
  734. if (wasCalled) {
  735. return;
  736. }
  737. wasCalled = true;
  738. wrappedFunction.apply(null, arguments);
  739. };
  740. };
  741. };
  742. var TYPE_ERROR = 'Promise resolved with itself';
  743. var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace');
  744. // Promise Resolution
  745. function resolvePromise(promise, state, value) {
  746. var onceWrapper = once();
  747. if (promise === value) {
  748. throw new TypeError(TYPE_ERROR);
  749. }
  750. if (promise[symbolState] === UNRESOLVED) {
  751. // should only get value.then once based on promise spec.
  752. var then = null;
  753. try {
  754. if (typeof value === 'object' || typeof value === 'function') {
  755. then = value && value.then;
  756. }
  757. }
  758. catch (err) {
  759. onceWrapper(function () {
  760. resolvePromise(promise, false, err);
  761. })();
  762. return promise;
  763. }
  764. // if (value instanceof ZoneAwarePromise) {
  765. if (state !== REJECTED && value instanceof ZoneAwarePromise &&
  766. value.hasOwnProperty(symbolState) && value.hasOwnProperty(symbolValue) &&
  767. value[symbolState] !== UNRESOLVED) {
  768. clearRejectedNoCatch(value);
  769. resolvePromise(promise, value[symbolState], value[symbolValue]);
  770. }
  771. else if (state !== REJECTED && typeof then === 'function') {
  772. try {
  773. then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)));
  774. }
  775. catch (err) {
  776. onceWrapper(function () {
  777. resolvePromise(promise, false, err);
  778. })();
  779. }
  780. }
  781. else {
  782. promise[symbolState] = state;
  783. var queue = promise[symbolValue];
  784. promise[symbolValue] = value;
  785. if (promise[symbolFinally] === symbolFinally) {
  786. // the promise is generated by Promise.prototype.finally
  787. if (state === RESOLVED) {
  788. // the state is resolved, should ignore the value
  789. // and use parent promise value
  790. promise[symbolState] = promise[symbolParentPromiseState];
  791. promise[symbolValue] = promise[symbolParentPromiseValue];
  792. }
  793. }
  794. // record task information in value when error occurs, so we can
  795. // do some additional work such as render longStackTrace
  796. if (state === REJECTED && value instanceof Error) {
  797. // check if longStackTraceZone is here
  798. var trace = Zone.currentTask && Zone.currentTask.data &&
  799. Zone.currentTask.data[creationTrace];
  800. if (trace) {
  801. // only keep the long stack trace into error when in longStackTraceZone
  802. ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace });
  803. }
  804. }
  805. for (var i = 0; i < queue.length;) {
  806. scheduleResolveOrReject(promise, queue[i++], queue[i++], queue[i++], queue[i++]);
  807. }
  808. if (queue.length == 0 && state == REJECTED) {
  809. promise[symbolState] = REJECTED_NO_CATCH;
  810. try {
  811. // try to print more readable error log
  812. throw new Error('Uncaught (in promise): ' + readableObjectToString(value) +
  813. (value && value.stack ? '\n' + value.stack : ''));
  814. }
  815. catch (err) {
  816. var error_1 = err;
  817. error_1.rejection = value;
  818. error_1.promise = promise;
  819. error_1.zone = Zone.current;
  820. error_1.task = Zone.currentTask;
  821. _uncaughtPromiseErrors.push(error_1);
  822. api.scheduleMicroTask(); // to make sure that it is running
  823. }
  824. }
  825. }
  826. }
  827. // Resolving an already resolved promise is a noop.
  828. return promise;
  829. }
  830. var REJECTION_HANDLED_HANDLER = __symbol__('rejectionHandledHandler');
  831. function clearRejectedNoCatch(promise) {
  832. if (promise[symbolState] === REJECTED_NO_CATCH) {
  833. // if the promise is rejected no catch status
  834. // and queue.length > 0, means there is a error handler
  835. // here to handle the rejected promise, we should trigger
  836. // windows.rejectionhandled eventHandler or nodejs rejectionHandled
  837. // eventHandler
  838. try {
  839. var handler = Zone[REJECTION_HANDLED_HANDLER];
  840. if (handler && typeof handler === 'function') {
  841. handler.call(this, { rejection: promise[symbolValue], promise: promise });
  842. }
  843. }
  844. catch (err) {
  845. }
  846. promise[symbolState] = REJECTED;
  847. for (var i = 0; i < _uncaughtPromiseErrors.length; i++) {
  848. if (promise === _uncaughtPromiseErrors[i].promise) {
  849. _uncaughtPromiseErrors.splice(i, 1);
  850. }
  851. }
  852. }
  853. }
  854. function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) {
  855. clearRejectedNoCatch(promise);
  856. var promiseState = promise[symbolState];
  857. var delegate = promiseState ?
  858. (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution :
  859. (typeof onRejected === 'function') ? onRejected : forwardRejection;
  860. zone.scheduleMicroTask(source, function () {
  861. try {
  862. var parentPromiseValue = promise[symbolValue];
  863. var isFinallyPromise = chainPromise && symbolFinally === chainPromise[symbolFinally];
  864. if (isFinallyPromise) {
  865. // if the promise is generated from finally call, keep parent promise's state and value
  866. chainPromise[symbolParentPromiseValue] = parentPromiseValue;
  867. chainPromise[symbolParentPromiseState] = promiseState;
  868. }
  869. // should not pass value to finally callback
  870. var value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ? [] : [parentPromiseValue]);
  871. resolvePromise(chainPromise, true, value);
  872. }
  873. catch (error) {
  874. // if error occurs, should always return this error
  875. resolvePromise(chainPromise, false, error);
  876. }
  877. }, chainPromise);
  878. }
  879. var ZONE_AWARE_PROMISE_TO_STRING = 'function ZoneAwarePromise() { [native code] }';
  880. var ZoneAwarePromise = /** @class */ (function () {
  881. function ZoneAwarePromise(executor) {
  882. var promise = this;
  883. if (!(promise instanceof ZoneAwarePromise)) {
  884. throw new Error('Must be an instanceof Promise.');
  885. }
  886. promise[symbolState] = UNRESOLVED;
  887. promise[symbolValue] = []; // queue;
  888. try {
  889. executor && executor(makeResolver(promise, RESOLVED), makeResolver(promise, REJECTED));
  890. }
  891. catch (error) {
  892. resolvePromise(promise, false, error);
  893. }
  894. }
  895. ZoneAwarePromise.toString = function () {
  896. return ZONE_AWARE_PROMISE_TO_STRING;
  897. };
  898. ZoneAwarePromise.resolve = function (value) {
  899. return resolvePromise(new this(null), RESOLVED, value);
  900. };
  901. ZoneAwarePromise.reject = function (error) {
  902. return resolvePromise(new this(null), REJECTED, error);
  903. };
  904. ZoneAwarePromise.race = function (values) {
  905. var resolve;
  906. var reject;
  907. var promise = new this(function (res, rej) {
  908. resolve = res;
  909. reject = rej;
  910. });
  911. function onResolve(value) {
  912. promise && (promise = null || resolve(value));
  913. }
  914. function onReject(error) {
  915. promise && (promise = null || reject(error));
  916. }
  917. for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
  918. var value = values_1[_i];
  919. if (!isThenable(value)) {
  920. value = this.resolve(value);
  921. }
  922. value.then(onResolve, onReject);
  923. }
  924. return promise;
  925. };
  926. ZoneAwarePromise.all = function (values) {
  927. var resolve;
  928. var reject;
  929. var promise = new this(function (res, rej) {
  930. resolve = res;
  931. reject = rej;
  932. });
  933. var count = 0;
  934. var resolvedValues = [];
  935. for (var _i = 0, values_2 = values; _i < values_2.length; _i++) {
  936. var value = values_2[_i];
  937. if (!isThenable(value)) {
  938. value = this.resolve(value);
  939. }
  940. value.then((function (index) { return function (value) {
  941. resolvedValues[index] = value;
  942. count--;
  943. if (!count) {
  944. resolve(resolvedValues);
  945. }
  946. }; })(count), reject);
  947. count++;
  948. }
  949. if (!count)
  950. resolve(resolvedValues);
  951. return promise;
  952. };
  953. ZoneAwarePromise.prototype.then = function (onFulfilled, onRejected) {
  954. var chainPromise = new this.constructor(null);
  955. var zone = Zone.current;
  956. if (this[symbolState] == UNRESOLVED) {
  957. this[symbolValue].push(zone, chainPromise, onFulfilled, onRejected);
  958. }
  959. else {
  960. scheduleResolveOrReject(this, zone, chainPromise, onFulfilled, onRejected);
  961. }
  962. return chainPromise;
  963. };
  964. ZoneAwarePromise.prototype.catch = function (onRejected) {
  965. return this.then(null, onRejected);
  966. };
  967. ZoneAwarePromise.prototype.finally = function (onFinally) {
  968. var chainPromise = new this.constructor(null);
  969. chainPromise[symbolFinally] = symbolFinally;
  970. var zone = Zone.current;
  971. if (this[symbolState] == UNRESOLVED) {
  972. this[symbolValue].push(zone, chainPromise, onFinally, onFinally);
  973. }
  974. else {
  975. scheduleResolveOrReject(this, zone, chainPromise, onFinally, onFinally);
  976. }
  977. return chainPromise;
  978. };
  979. return ZoneAwarePromise;
  980. }());
  981. // Protect against aggressive optimizers dropping seemingly unused properties.
  982. // E.g. Closure Compiler in advanced mode.
  983. ZoneAwarePromise['resolve'] = ZoneAwarePromise.resolve;
  984. ZoneAwarePromise['reject'] = ZoneAwarePromise.reject;
  985. ZoneAwarePromise['race'] = ZoneAwarePromise.race;
  986. ZoneAwarePromise['all'] = ZoneAwarePromise.all;
  987. var NativePromise = global[symbolPromise] = global['Promise'];
  988. var ZONE_AWARE_PROMISE = Zone.__symbol__('ZoneAwarePromise');
  989. var desc = ObjectGetOwnPropertyDescriptor(global, 'Promise');
  990. if (!desc || desc.configurable) {
  991. desc && delete desc.writable;
  992. desc && delete desc.value;
  993. if (!desc) {
  994. desc = { configurable: true, enumerable: true };
  995. }
  996. desc.get = function () {
  997. // if we already set ZoneAwarePromise, use patched one
  998. // otherwise return native one.
  999. return global[ZONE_AWARE_PROMISE] ? global[ZONE_AWARE_PROMISE] : global[symbolPromise];
  1000. };
  1001. desc.set = function (NewNativePromise) {
  1002. if (NewNativePromise === ZoneAwarePromise) {
  1003. // if the NewNativePromise is ZoneAwarePromise
  1004. // save to global
  1005. global[ZONE_AWARE_PROMISE] = NewNativePromise;
  1006. }
  1007. else {
  1008. // if the NewNativePromise is not ZoneAwarePromise
  1009. // for example: after load zone.js, some library just
  1010. // set es6-promise to global, if we set it to global
  1011. // directly, assertZonePatched will fail and angular
  1012. // will not loaded, so we just set the NewNativePromise
  1013. // to global[symbolPromise], so the result is just like
  1014. // we load ES6 Promise before zone.js
  1015. global[symbolPromise] = NewNativePromise;
  1016. if (!NewNativePromise.prototype[symbolThen]) {
  1017. patchThen(NewNativePromise);
  1018. }
  1019. api.setNativePromise(NewNativePromise);
  1020. }
  1021. };
  1022. ObjectDefineProperty(global, 'Promise', desc);
  1023. }
  1024. global['Promise'] = ZoneAwarePromise;
  1025. var symbolThenPatched = __symbol__('thenPatched');
  1026. function patchThen(Ctor) {
  1027. var proto = Ctor.prototype;
  1028. var prop = ObjectGetOwnPropertyDescriptor(proto, 'then');
  1029. if (prop && (prop.writable === false || !prop.configurable)) {
  1030. // check Ctor.prototype.then propertyDescriptor is writable or not
  1031. // in meteor env, writable is false, we should ignore such case
  1032. return;
  1033. }
  1034. var originalThen = proto.then;
  1035. // Keep a reference to the original method.
  1036. proto[symbolThen] = originalThen;
  1037. Ctor.prototype.then = function (onResolve, onReject) {
  1038. var _this = this;
  1039. var wrapped = new ZoneAwarePromise(function (resolve, reject) {
  1040. originalThen.call(_this, resolve, reject);
  1041. });
  1042. return wrapped.then(onResolve, onReject);
  1043. };
  1044. Ctor[symbolThenPatched] = true;
  1045. }
  1046. function zoneify(fn) {
  1047. return function () {
  1048. var resultPromise = fn.apply(this, arguments);
  1049. if (resultPromise instanceof ZoneAwarePromise) {
  1050. return resultPromise;
  1051. }
  1052. var ctor = resultPromise.constructor;
  1053. if (!ctor[symbolThenPatched]) {
  1054. patchThen(ctor);
  1055. }
  1056. return resultPromise;
  1057. };
  1058. }
  1059. if (NativePromise) {
  1060. patchThen(NativePromise);
  1061. var fetch_1 = global['fetch'];
  1062. if (typeof fetch_1 == 'function') {
  1063. global['fetch'] = zoneify(fetch_1);
  1064. }
  1065. }
  1066. // This is not part of public API, but it is useful for tests, so we expose it.
  1067. Promise[Zone.__symbol__('uncaughtPromiseErrors')] = _uncaughtPromiseErrors;
  1068. return ZoneAwarePromise;
  1069. });
  1070. /**
  1071. * @license
  1072. * Copyright Google Inc. All Rights Reserved.
  1073. *
  1074. * Use of this source code is governed by an MIT-style license that can be
  1075. * found in the LICENSE file at https://angular.io/license
  1076. */
  1077. /**
  1078. * Suppress closure compiler errors about unknown 'Zone' variable
  1079. * @fileoverview
  1080. * @suppress {undefinedVars,globalThis,missingRequire}
  1081. */
  1082. // issue #989, to reduce bundle size, use short name
  1083. /** Object.getOwnPropertyDescriptor */
  1084. var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  1085. /** Object.defineProperty */
  1086. var ObjectDefineProperty = Object.defineProperty;
  1087. /** Object.getPrototypeOf */
  1088. var ObjectGetPrototypeOf = Object.getPrototypeOf;
  1089. /** Object.create */
  1090. /** Array.prototype.slice */
  1091. var ArraySlice = Array.prototype.slice;
  1092. /** addEventListener string const */
  1093. var ADD_EVENT_LISTENER_STR = 'addEventListener';
  1094. /** removeEventListener string const */
  1095. var REMOVE_EVENT_LISTENER_STR = 'removeEventListener';
  1096. /** zoneSymbol addEventListener */
  1097. var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR);
  1098. /** zoneSymbol removeEventListener */
  1099. var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR);
  1100. /** true string const */
  1101. var TRUE_STR = 'true';
  1102. /** false string const */
  1103. var FALSE_STR = 'false';
  1104. /** __zone_symbol__ string const */
  1105. var ZONE_SYMBOL_PREFIX = '__zone_symbol__';
  1106. function wrapWithCurrentZone(callback, source) {
  1107. return Zone.current.wrap(callback, source);
  1108. }
  1109. function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) {
  1110. return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
  1111. }
  1112. var zoneSymbol = Zone.__symbol__;
  1113. var isWindowExists = typeof window !== 'undefined';
  1114. var internalWindow = isWindowExists ? window : undefined;
  1115. var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global;
  1116. var REMOVE_ATTRIBUTE = 'removeAttribute';
  1117. var NULL_ON_PROP_VALUE = [null];
  1118. function bindArguments(args, source) {
  1119. for (var i = args.length - 1; i >= 0; i--) {
  1120. if (typeof args[i] === 'function') {
  1121. args[i] = wrapWithCurrentZone(args[i], source + '_' + i);
  1122. }
  1123. }
  1124. return args;
  1125. }
  1126. function isPropertyWritable(propertyDesc) {
  1127. if (!propertyDesc) {
  1128. return true;
  1129. }
  1130. if (propertyDesc.writable === false) {
  1131. return false;
  1132. }
  1133. return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined');
  1134. }
  1135. var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope);
  1136. // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
  1137. // this code.
  1138. var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' &&
  1139. {}.toString.call(_global.process) === '[object process]');
  1140. var isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']);
  1141. // we are in electron of nw, so we are both browser and nodejs
  1142. // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
  1143. // this code.
  1144. var isMix = typeof _global.process !== 'undefined' &&
  1145. {}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
  1146. !!(isWindowExists && internalWindow['HTMLElement']);
  1147. var zoneSymbolEventNames = {};
  1148. var wrapFn = function (event) {
  1149. // https://github.com/angular/zone.js/issues/911, in IE, sometimes
  1150. // event will be undefined, so we need to use window.event
  1151. event = event || _global.event;
  1152. if (!event) {
  1153. return;
  1154. }
  1155. var eventNameSymbol = zoneSymbolEventNames[event.type];
  1156. if (!eventNameSymbol) {
  1157. eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
  1158. }
  1159. var target = this || event.target || _global;
  1160. var listener = target[eventNameSymbol];
  1161. var result = listener && listener.apply(this, arguments);
  1162. if (result != undefined && !result) {
  1163. event.preventDefault();
  1164. }
  1165. return result;
  1166. };
  1167. function patchProperty(obj, prop, prototype) {
  1168. var desc = ObjectGetOwnPropertyDescriptor(obj, prop);
  1169. if (!desc && prototype) {
  1170. // when patch window object, use prototype to check prop exist or not
  1171. var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop);
  1172. if (prototypeDesc) {
  1173. desc = { enumerable: true, configurable: true };
  1174. }
  1175. }
  1176. // if the descriptor not exists or is not configurable
  1177. // just return
  1178. if (!desc || !desc.configurable) {
  1179. return;
  1180. }
  1181. // A property descriptor cannot have getter/setter and be writable
  1182. // deleting the writable and value properties avoids this error:
  1183. //
  1184. // TypeError: property descriptors must not specify a value or be writable when a
  1185. // getter or setter has been specified
  1186. delete desc.writable;
  1187. delete desc.value;
  1188. var originalDescGet = desc.get;
  1189. var originalDescSet = desc.set;
  1190. // substr(2) cuz 'onclick' -> 'click', etc
  1191. var eventName = prop.substr(2);
  1192. var eventNameSymbol = zoneSymbolEventNames[eventName];
  1193. if (!eventNameSymbol) {
  1194. eventNameSymbol = zoneSymbolEventNames[eventName] = zoneSymbol('ON_PROPERTY' + eventName);
  1195. }
  1196. desc.set = function (newValue) {
  1197. // in some of windows's onproperty callback, this is undefined
  1198. // so we need to check it
  1199. var target = this;
  1200. if (!target && obj === _global) {
  1201. target = _global;
  1202. }
  1203. if (!target) {
  1204. return;
  1205. }
  1206. var previousValue = target[eventNameSymbol];
  1207. if (previousValue) {
  1208. target.removeEventListener(eventName, wrapFn);
  1209. }
  1210. // issue #978, when onload handler was added before loading zone.js
  1211. // we should remove it with originalDescSet
  1212. if (originalDescSet) {
  1213. originalDescSet.apply(target, NULL_ON_PROP_VALUE);
  1214. }
  1215. if (typeof newValue === 'function') {
  1216. target[eventNameSymbol] = newValue;
  1217. target.addEventListener(eventName, wrapFn, false);
  1218. }
  1219. else {
  1220. target[eventNameSymbol] = null;
  1221. }
  1222. };
  1223. // The getter would return undefined for unassigned properties but the default value of an
  1224. // unassigned property is null
  1225. desc.get = function () {
  1226. // in some of windows's onproperty callback, this is undefined
  1227. // so we need to check it
  1228. var target = this;
  1229. if (!target && obj === _global) {
  1230. target = _global;
  1231. }
  1232. if (!target) {
  1233. return null;
  1234. }
  1235. var listener = target[eventNameSymbol];
  1236. if (listener) {
  1237. return listener;
  1238. }
  1239. else if (originalDescGet) {
  1240. // result will be null when use inline event attribute,
  1241. // such as <button onclick="func();">OK</button>
  1242. // because the onclick function is internal raw uncompiled handler
  1243. // the onclick will be evaluated when first time event was triggered or
  1244. // the property is accessed, https://github.com/angular/zone.js/issues/525
  1245. // so we should use original native get to retrieve the handler
  1246. var value = originalDescGet && originalDescGet.call(this);
  1247. if (value) {
  1248. desc.set.call(this, value);
  1249. if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
  1250. target.removeAttribute(prop);
  1251. }
  1252. return value;
  1253. }
  1254. }
  1255. return null;
  1256. };
  1257. ObjectDefineProperty(obj, prop, desc);
  1258. }
  1259. function patchOnProperties(obj, properties, prototype) {
  1260. if (properties) {
  1261. for (var i = 0; i < properties.length; i++) {
  1262. patchProperty(obj, 'on' + properties[i], prototype);
  1263. }
  1264. }
  1265. else {
  1266. var onProperties = [];
  1267. for (var prop in obj) {
  1268. if (prop.substr(0, 2) == 'on') {
  1269. onProperties.push(prop);
  1270. }
  1271. }
  1272. for (var j = 0; j < onProperties.length; j++) {
  1273. patchProperty(obj, onProperties[j], prototype);
  1274. }
  1275. }
  1276. }
  1277. var originalInstanceKey = zoneSymbol('originalInstance');
  1278. // wrap some native API on `window`
  1279. function patchMethod(target, name, patchFn) {
  1280. var proto = target;
  1281. while (proto && !proto.hasOwnProperty(name)) {
  1282. proto = ObjectGetPrototypeOf(proto);
  1283. }
  1284. if (!proto && target[name]) {
  1285. // somehow we did not find it, but we can see it. This happens on IE for Window properties.
  1286. proto = target;
  1287. }
  1288. var delegateName = zoneSymbol(name);
  1289. var delegate;
  1290. if (proto && !(delegate = proto[delegateName])) {
  1291. delegate = proto[delegateName] = proto[name];
  1292. // check whether proto[name] is writable
  1293. // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
  1294. var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
  1295. if (isPropertyWritable(desc)) {
  1296. var patchDelegate_1 = patchFn(delegate, delegateName, name);
  1297. proto[name] = function () {
  1298. return patchDelegate_1(this, arguments);
  1299. };
  1300. attachOriginToPatched(proto[name], delegate);
  1301. }
  1302. }
  1303. return delegate;
  1304. }
  1305. // TODO: @JiaLiPassion, support cancel task later if necessary
  1306. function patchMacroTask(obj, funcName, metaCreator) {
  1307. var setNative = null;
  1308. function scheduleTask(task) {
  1309. var data = task.data;
  1310. data.args[data.cbIdx] = function () {
  1311. task.invoke.apply(this, arguments);
  1312. };
  1313. setNative.apply(data.target, data.args);
  1314. return task;
  1315. }
  1316. setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
  1317. var meta = metaCreator(self, args);
  1318. if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
  1319. return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask, null);
  1320. }
  1321. else {
  1322. // cause an error by calling it directly.
  1323. return delegate.apply(self, args);
  1324. }
  1325. }; });
  1326. }
  1327. function patchMicroTask(obj, funcName, metaCreator) {
  1328. var setNative = null;
  1329. function scheduleTask(task) {
  1330. var data = task.data;
  1331. data.args[data.cbIdx] = function () {
  1332. task.invoke.apply(this, arguments);
  1333. };
  1334. setNative.apply(data.target, data.args);
  1335. return task;
  1336. }
  1337. setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
  1338. var meta = metaCreator(self, args);
  1339. if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
  1340. return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask);
  1341. }
  1342. else {
  1343. // cause an error by calling it directly.
  1344. return delegate.apply(self, args);
  1345. }
  1346. }; });
  1347. }
  1348. function attachOriginToPatched(patched, original) {
  1349. patched[zoneSymbol('OriginalDelegate')] = original;
  1350. }
  1351. /**
  1352. * @license
  1353. * Copyright Google Inc. All Rights Reserved.
  1354. *
  1355. * Use of this source code is governed by an MIT-style license that can be
  1356. * found in the LICENSE file at https://angular.io/license
  1357. */
  1358. // override Function.prototype.toString to make zone.js patched function
  1359. // look like native function
  1360. Zone.__load_patch('toString', function (global) {
  1361. // patch Func.prototype.toString to let them look like native
  1362. var originalFunctionToString = Function.prototype.toString;
  1363. var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
  1364. var PROMISE_SYMBOL = zoneSymbol('Promise');
  1365. var ERROR_SYMBOL = zoneSymbol('Error');
  1366. var newFunctionToString = function toString() {
  1367. if (typeof this === 'function') {
  1368. var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
  1369. if (originalDelegate) {
  1370. if (typeof originalDelegate === 'function') {
  1371. return originalFunctionToString.apply(this[ORIGINAL_DELEGATE_SYMBOL], arguments);
  1372. }
  1373. else {
  1374. return Object.prototype.toString.call(originalDelegate);
  1375. }
  1376. }
  1377. if (this === Promise) {
  1378. var nativePromise = global[PROMISE_SYMBOL];
  1379. if (nativePromise) {
  1380. return originalFunctionToString.apply(nativePromise, arguments);
  1381. }
  1382. }
  1383. if (this === Error) {
  1384. var nativeError = global[ERROR_SYMBOL];
  1385. if (nativeError) {
  1386. return originalFunctionToString.apply(nativeError, arguments);
  1387. }
  1388. }
  1389. }
  1390. return originalFunctionToString.apply(this, arguments);
  1391. };
  1392. newFunctionToString[ORIGINAL_DELEGATE_SYMBOL] = originalFunctionToString;
  1393. Function.prototype.toString = newFunctionToString;
  1394. // patch Object.prototype.toString to let them look like native
  1395. var originalObjectToString = Object.prototype.toString;
  1396. var PROMISE_OBJECT_TO_STRING = '[object Promise]';
  1397. Object.prototype.toString = function () {
  1398. if (this instanceof Promise) {
  1399. return PROMISE_OBJECT_TO_STRING;
  1400. }
  1401. return originalObjectToString.apply(this, arguments);
  1402. };
  1403. });
  1404. /**
  1405. * @license
  1406. * Copyright Google Inc. All Rights Reserved.
  1407. *
  1408. * Use of this source code is governed by an MIT-style license that can be
  1409. * found in the LICENSE file at https://angular.io/license
  1410. */
  1411. /**
  1412. * @fileoverview
  1413. * @suppress {missingRequire}
  1414. */
  1415. // an identifier to tell ZoneTask do not create a new invoke closure
  1416. var OPTIMIZED_ZONE_EVENT_TASK_DATA = {
  1417. useG: true
  1418. };
  1419. var zoneSymbolEventNames$1 = {};
  1420. var globalSources = {};
  1421. var EVENT_NAME_SYMBOL_REGX = /^__zone_symbol__(\w+)(true|false)$/;
  1422. var IMMEDIATE_PROPAGATION_SYMBOL = ('__zone_symbol__propagationStopped');
  1423. function patchEventTarget(_global, apis, patchOptions) {
  1424. var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR;
  1425. var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR;
  1426. var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners';
  1427. var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners';
  1428. var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER);
  1429. var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':';
  1430. var PREPEND_EVENT_LISTENER = 'prependListener';
  1431. var PREPEND_EVENT_LISTENER_SOURCE = '.' + PREPEND_EVENT_LISTENER + ':';
  1432. var invokeTask = function (task, target, event) {
  1433. // for better performance, check isRemoved which is set
  1434. // by removeEventListener
  1435. if (task.isRemoved) {
  1436. return;
  1437. }
  1438. var delegate = task.callback;
  1439. if (typeof delegate === 'object' && delegate.handleEvent) {
  1440. // create the bind version of handleEvent when invoke
  1441. task.callback = function (event) { return delegate.handleEvent(event); };
  1442. task.originalDelegate = delegate;
  1443. }
  1444. // invoke static task.invoke
  1445. task.invoke(task, target, [event]);
  1446. var options = task.options;
  1447. if (options && typeof options === 'object' && options.once) {
  1448. // if options.once is true, after invoke once remove listener here
  1449. // only browser need to do this, nodejs eventEmitter will cal removeListener
  1450. // inside EventEmitter.once
  1451. var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback;
  1452. target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options);
  1453. }
  1454. };
  1455. // global shared zoneAwareCallback to handle all event callback with capture = false
  1456. var globalZoneAwareCallback = function (event) {
  1457. // https://github.com/angular/zone.js/issues/911, in IE, sometimes
  1458. // event will be undefined, so we need to use window.event
  1459. event = event || _global.event;
  1460. if (!event) {
  1461. return;
  1462. }
  1463. // event.target is needed for Samsung TV and SourceBuffer
  1464. // || global is needed https://github.com/angular/zone.js/issues/190
  1465. var target = this || event.target || _global;
  1466. var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]];
  1467. if (tasks) {
  1468. // invoke all tasks which attached to current target with given event.type and capture = false
  1469. // for performance concern, if task.length === 1, just invoke
  1470. if (tasks.length === 1) {
  1471. invokeTask(tasks[0], target, event);
  1472. }
  1473. else {
  1474. // https://github.com/angular/zone.js/issues/836
  1475. // copy the tasks array before invoke, to avoid
  1476. // the callback will remove itself or other listener
  1477. var copyTasks = tasks.slice();
  1478. for (var i = 0; i < copyTasks.length; i++) {
  1479. if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
  1480. break;
  1481. }
  1482. invokeTask(copyTasks[i], target, event);
  1483. }
  1484. }
  1485. }
  1486. };
  1487. // global shared zoneAwareCallback to handle all event callback with capture = true
  1488. var globalZoneAwareCaptureCallback = function (event) {
  1489. // https://github.com/angular/zone.js/issues/911, in IE, sometimes
  1490. // event will be undefined, so we need to use window.event
  1491. event = event || _global.event;
  1492. if (!event) {
  1493. return;
  1494. }
  1495. // event.target is needed for Samsung TV and SourceBuffer
  1496. // || global is needed https://github.com/angular/zone.js/issues/190
  1497. var target = this || event.target || _global;
  1498. var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]];
  1499. if (tasks) {
  1500. // invoke all tasks which attached to current target with given event.type and capture = false
  1501. // for performance concern, if task.length === 1, just invoke
  1502. if (tasks.length === 1) {
  1503. invokeTask(tasks[0], target, event);
  1504. }
  1505. else {
  1506. // https://github.com/angular/zone.js/issues/836
  1507. // copy the tasks array before invoke, to avoid
  1508. // the callback will remove itself or other listener
  1509. var copyTasks = tasks.slice();
  1510. for (var i = 0; i < copyTasks.length; i++) {
  1511. if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
  1512. break;
  1513. }
  1514. invokeTask(copyTasks[i], target, event);
  1515. }
  1516. }
  1517. }
  1518. };
  1519. function patchEventTargetMethods(obj, patchOptions) {
  1520. if (!obj) {
  1521. return false;
  1522. }
  1523. var useGlobalCallback = true;
  1524. if (patchOptions && patchOptions.useG !== undefined) {
  1525. useGlobalCallback = patchOptions.useG;
  1526. }
  1527. var validateHandler = patchOptions && patchOptions.vh;
  1528. var checkDuplicate = true;
  1529. if (patchOptions && patchOptions.chkDup !== undefined) {
  1530. checkDuplicate = patchOptions.chkDup;
  1531. }
  1532. var returnTarget = false;
  1533. if (patchOptions && patchOptions.rt !== undefined) {
  1534. returnTarget = patchOptions.rt;
  1535. }
  1536. var proto = obj;
  1537. while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) {
  1538. proto = ObjectGetPrototypeOf(proto);
  1539. }
  1540. if (!proto && obj[ADD_EVENT_LISTENER]) {
  1541. // somehow we did not find it, but we can see it. This happens on IE for Window properties.
  1542. proto = obj;
  1543. }
  1544. if (!proto) {
  1545. return false;
  1546. }
  1547. if (proto[zoneSymbolAddEventListener]) {
  1548. return false;
  1549. }
  1550. // a shared global taskData to pass data for scheduleEventTask
  1551. // so we do not need to create a new object just for pass some data
  1552. var taskData = {};
  1553. var nativeAddEventListener = proto[zoneSymbolAddEventListener] = proto[ADD_EVENT_LISTENER];
  1554. var nativeRemoveEventListener = proto[zoneSymbol(REMOVE_EVENT_LISTENER)] =
  1555. proto[REMOVE_EVENT_LISTENER];
  1556. var nativeListeners = proto[zoneSymbol(LISTENERS_EVENT_LISTENER)] =
  1557. proto[LISTENERS_EVENT_LISTENER];
  1558. var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] =
  1559. proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER];
  1560. var nativePrependEventListener;
  1561. if (patchOptions && patchOptions.prepend) {
  1562. nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] =
  1563. proto[patchOptions.prepend];
  1564. }
  1565. var customScheduleGlobal = function () {
  1566. // if there is already a task for the eventName + capture,
  1567. // just return, because we use the shared globalZoneAwareCallback here.
  1568. if (taskData.isExisting) {
  1569. return;
  1570. }
  1571. return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options);
  1572. };
  1573. var customCancelGlobal = function (task) {
  1574. // if task is not marked as isRemoved, this call is directly
  1575. // from Zone.prototype.cancelTask, we should remove the task
  1576. // from tasksList of target first
  1577. if (!task.isRemoved) {
  1578. var symbolEventNames = zoneSymbolEventNames$1[task.eventName];
  1579. var symbolEventName = void 0;
  1580. if (symbolEventNames) {
  1581. symbolEventName = symbolEventNames[task.capture ? TRUE_STR : FALSE_STR];
  1582. }
  1583. var existingTasks = symbolEventName && task.target[symbolEventName];
  1584. if (existingTasks) {
  1585. for (var i = 0; i < existingTasks.length; i++) {
  1586. var existingTask = existingTasks[i];
  1587. if (existingTask === task) {
  1588. existingTasks.splice(i, 1);
  1589. // set isRemoved to data for faster invokeTask check
  1590. task.isRemoved = true;
  1591. if (existingTasks.length === 0) {
  1592. // all tasks for the eventName + capture have gone,
  1593. // remove globalZoneAwareCallback and remove the task cache from target
  1594. task.allRemoved = true;
  1595. task.target[symbolEventName] = null;
  1596. }
  1597. break;
  1598. }
  1599. }
  1600. }
  1601. }
  1602. // if all tasks for the eventName + capture have gone,
  1603. // we will really remove the global event callback,
  1604. // if not, return
  1605. if (!task.allRemoved) {
  1606. return;
  1607. }
  1608. return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options);
  1609. };
  1610. var customScheduleNonGlobal = function (task) {
  1611. return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
  1612. };
  1613. var customSchedulePrepend = function (task) {
  1614. return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
  1615. };
  1616. var customCancelNonGlobal = function (task) {
  1617. return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options);
  1618. };
  1619. var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal;
  1620. var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal;
  1621. var compareTaskCallbackVsDelegate = function (task, delegate) {
  1622. var typeOfDelegate = typeof delegate;
  1623. return (typeOfDelegate === 'function' && task.callback === delegate) ||
  1624. (typeOfDelegate === 'object' && task.originalDelegate === delegate);
  1625. };
  1626. var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate;
  1627. var blackListedEvents = Zone[Zone.__symbol__('BLACK_LISTED_EVENTS')];
  1628. var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) {
  1629. if (returnTarget === void 0) { returnTarget = false; }
  1630. if (prepend === void 0) { prepend = false; }
  1631. return function () {
  1632. var target = this || _global;
  1633. var delegate = arguments[1];
  1634. if (!delegate) {
  1635. return nativeListener.apply(this, arguments);
  1636. }
  1637. // don't create the bind delegate function for handleEvent
  1638. // case here to improve addEventListener performance
  1639. // we will create the bind delegate when invoke
  1640. var isHandleEvent = false;
  1641. if (typeof delegate !== 'function') {
  1642. if (!delegate.handleEvent) {
  1643. return nativeListener.apply(this, arguments);
  1644. }
  1645. isHandleEvent = true;
  1646. }
  1647. if (validateHandler && !validateHandler(nativeListener, delegate, target, arguments)) {
  1648. return;
  1649. }
  1650. var eventName = arguments[0];
  1651. var options = arguments[2];
  1652. if (blackListedEvents) {
  1653. // check black list
  1654. for (var i = 0; i < blackListedEvents.length; i++) {
  1655. if (eventName === blackListedEvents[i]) {
  1656. return nativeListener.apply(this, arguments);
  1657. }
  1658. }
  1659. }
  1660. var capture;
  1661. var once = false;
  1662. if (options === undefined) {
  1663. capture = false;
  1664. }
  1665. else if (options === true) {
  1666. capture = true;
  1667. }
  1668. else if (options === false) {
  1669. capture = false;
  1670. }
  1671. else {
  1672. capture = options ? !!options.capture : false;
  1673. once = options ? !!options.once : false;
  1674. }
  1675. var zone = Zone.current;
  1676. var symbolEventNames = zoneSymbolEventNames$1[eventName];
  1677. var symbolEventName;
  1678. if (!symbolEventNames) {
  1679. // the code is duplicate, but I just want to get some better performance
  1680. var falseEventName = eventName + FALSE_STR;
  1681. var trueEventName = eventName + TRUE_STR;
  1682. var symbol = ZONE_SYMBOL_PREFIX + falseEventName;
  1683. var symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
  1684. zoneSymbolEventNames$1[eventName] = {};
  1685. zoneSymbolEventNames$1[eventName][FALSE_STR] = symbol;
  1686. zoneSymbolEventNames$1[eventName][TRUE_STR] = symbolCapture;
  1687. symbolEventName = capture ? symbolCapture : symbol;
  1688. }
  1689. else {
  1690. symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
  1691. }
  1692. var existingTasks = target[symbolEventName];
  1693. var isExisting = false;
  1694. if (existingTasks) {
  1695. // already have task registered
  1696. isExisting = true;
  1697. if (checkDuplicate) {
  1698. for (var i = 0; i < existingTasks.length; i++) {
  1699. if (compare(existingTasks[i], delegate)) {
  1700. // same callback, same capture, same event name, just return
  1701. return;
  1702. }
  1703. }
  1704. }
  1705. }
  1706. else {
  1707. existingTasks = target[symbolEventName] = [];
  1708. }
  1709. var source;
  1710. var constructorName = target.constructor['name'];
  1711. var targetSource = globalSources[constructorName];
  1712. if (targetSource) {
  1713. source = targetSource[eventName];
  1714. }
  1715. if (!source) {
  1716. source = constructorName + addSource + eventName;
  1717. }
  1718. // do not create a new object as task.data to pass those things
  1719. // just use the global shared one
  1720. taskData.options = options;
  1721. if (once) {
  1722. // if addEventListener with once options, we don't pass it to
  1723. // native addEventListener, instead we keep the once setting
  1724. // and handle ourselves.
  1725. taskData.options.once = false;
  1726. }
  1727. taskData.target = target;
  1728. taskData.capture = capture;
  1729. taskData.eventName = eventName;
  1730. taskData.isExisting = isExisting;
  1731. var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null;
  1732. // keep taskData into data to allow onScheduleEventTask to access the task information
  1733. if (data) {
  1734. data.taskData = taskData;
  1735. }
  1736. var task = zone.scheduleEventTask(source, delegate, data, customScheduleFn, customCancelFn);
  1737. // should clear taskData.target to avoid memory leak
  1738. // issue, https://github.com/angular/angular/issues/20442
  1739. taskData.target = null;
  1740. // need to clear up taskData because it is a global object
  1741. if (data) {
  1742. data.taskData = null;
  1743. }
  1744. // have to save those information to task in case
  1745. // application may call task.zone.cancelTask() directly
  1746. if (once) {
  1747. options.once = true;
  1748. }
  1749. task.options = options;
  1750. task.target = target;
  1751. task.capture = capture;
  1752. task.eventName = eventName;
  1753. if (isHandleEvent) {
  1754. // save original delegate for compare to check duplicate
  1755. task.originalDelegate = delegate;
  1756. }
  1757. if (!prepend) {
  1758. existingTasks.push(task);
  1759. }
  1760. else {
  1761. existingTasks.unshift(task);
  1762. }
  1763. if (returnTarget) {
  1764. return target;
  1765. }
  1766. };
  1767. };
  1768. proto[ADD_EVENT_LISTENER] = makeAddListener(nativeAddEventListener, ADD_EVENT_LISTENER_SOURCE, customSchedule, customCancel, returnTarget);
  1769. if (nativePrependEventListener) {
  1770. proto[PREPEND_EVENT_LISTENER] = makeAddListener(nativePrependEventListener, PREPEND_EVENT_LISTENER_SOURCE, customSchedulePrepend, customCancel, returnTarget, true);
  1771. }
  1772. proto[REMOVE_EVENT_LISTENER] = function () {
  1773. var target = this || _global;
  1774. var eventName = arguments[0];
  1775. var options = arguments[2];
  1776. var capture;
  1777. if (options === undefined) {
  1778. capture = false;
  1779. }
  1780. else if (options === true) {
  1781. capture = true;
  1782. }
  1783. else if (options === false) {
  1784. capture = false;
  1785. }
  1786. else {
  1787. capture = options ? !!options.capture : false;
  1788. }
  1789. var delegate = arguments[1];
  1790. if (!delegate) {
  1791. return nativeRemoveEventListener.apply(this, arguments);
  1792. }
  1793. if (validateHandler &&
  1794. !validateHandler(nativeRemoveEventListener, delegate, target, arguments)) {
  1795. return;
  1796. }
  1797. var symbolEventNames = zoneSymbolEventNames$1[eventName];
  1798. var symbolEventName;
  1799. if (symbolEventNames) {
  1800. symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
  1801. }
  1802. var existingTasks = symbolEventName && target[symbolEventName];
  1803. if (existingTasks) {
  1804. for (var i = 0; i < existingTasks.length; i++) {
  1805. var existingTask = existingTasks[i];
  1806. if (compare(existingTask, delegate)) {
  1807. existingTasks.splice(i, 1);
  1808. // set isRemoved to data for faster invokeTask check
  1809. existingTask.isRemoved = true;
  1810. if (existingTasks.length === 0) {
  1811. // all tasks for the eventName + capture have gone,
  1812. // remove globalZoneAwareCallback and remove the task cache from target
  1813. existingTask.allRemoved = true;
  1814. target[symbolEventName] = null;
  1815. }
  1816. existingTask.zone.cancelTask(existingTask);
  1817. if (returnTarget) {
  1818. return target;
  1819. }
  1820. return;
  1821. }
  1822. }
  1823. }
  1824. // issue 930, didn't find the event name or callback
  1825. // from zone kept existingTasks, the callback maybe
  1826. // added outside of zone, we need to call native removeEventListener
  1827. // to try to remove it.
  1828. return nativeRemoveEventListener.apply(this, arguments);
  1829. };
  1830. proto[LISTENERS_EVENT_LISTENER] = function () {
  1831. var target = this || _global;
  1832. var eventName = arguments[0];
  1833. var listeners = [];
  1834. var tasks = findEventTasks(target, eventName);
  1835. for (var i = 0; i < tasks.length; i++) {
  1836. var task = tasks[i];
  1837. var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
  1838. listeners.push(delegate);
  1839. }
  1840. return listeners;
  1841. };
  1842. proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER] = function () {
  1843. var target = this || _global;
  1844. var eventName = arguments[0];
  1845. if (!eventName) {
  1846. var keys = Object.keys(target);
  1847. for (var i = 0; i < keys.length; i++) {
  1848. var prop = keys[i];
  1849. var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
  1850. var evtName = match && match[1];
  1851. // in nodejs EventEmitter, removeListener event is
  1852. // used for monitoring the removeListener call,
  1853. // so just keep removeListener eventListener until
  1854. // all other eventListeners are removed
  1855. if (evtName && evtName !== 'removeListener') {
  1856. this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName);
  1857. }
  1858. }
  1859. // remove removeListener listener finally
  1860. this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener');
  1861. }
  1862. else {
  1863. var symbolEventNames = zoneSymbolEventNames$1[eventName];
  1864. if (symbolEventNames) {
  1865. var symbolEventName = symbolEventNames[FALSE_STR];
  1866. var symbolCaptureEventName = symbolEventNames[TRUE_STR];
  1867. var tasks = target[symbolEventName];
  1868. var captureTasks = target[symbolCaptureEventName];
  1869. if (tasks) {
  1870. var removeTasks = tasks.slice();
  1871. for (var i = 0; i < removeTasks.length; i++) {
  1872. var task = removeTasks[i];
  1873. var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
  1874. this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
  1875. }
  1876. }
  1877. if (captureTasks) {
  1878. var removeTasks = captureTasks.slice();
  1879. for (var i = 0; i < removeTasks.length; i++) {
  1880. var task = removeTasks[i];
  1881. var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
  1882. this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
  1883. }
  1884. }
  1885. }
  1886. }
  1887. if (returnTarget) {
  1888. return this;
  1889. }
  1890. };
  1891. // for native toString patch
  1892. attachOriginToPatched(proto[ADD_EVENT_LISTENER], nativeAddEventListener);
  1893. attachOriginToPatched(proto[REMOVE_EVENT_LISTENER], nativeRemoveEventListener);
  1894. if (nativeRemoveAllListeners) {
  1895. attachOriginToPatched(proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER], nativeRemoveAllListeners);
  1896. }
  1897. if (nativeListeners) {
  1898. attachOriginToPatched(proto[LISTENERS_EVENT_LISTENER], nativeListeners);
  1899. }
  1900. return true;
  1901. }
  1902. var results = [];
  1903. for (var i = 0; i < apis.length; i++) {
  1904. results[i] = patchEventTargetMethods(apis[i], patchOptions);
  1905. }
  1906. return results;
  1907. }
  1908. function findEventTasks(target, eventName) {
  1909. var foundTasks = [];
  1910. for (var prop in target) {
  1911. var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
  1912. var evtName = match && match[1];
  1913. if (evtName && (!eventName || evtName === eventName)) {
  1914. var tasks = target[prop];
  1915. if (tasks) {
  1916. for (var i = 0; i < tasks.length; i++) {
  1917. foundTasks.push(tasks[i]);
  1918. }
  1919. }
  1920. }
  1921. }
  1922. return foundTasks;
  1923. }
  1924. /**
  1925. * @license
  1926. * Copyright Google Inc. All Rights Reserved.
  1927. *
  1928. * Use of this source code is governed by an MIT-style license that can be
  1929. * found in the LICENSE file at https://angular.io/license
  1930. */
  1931. Zone.__load_patch('EventEmitter', function (global) {
  1932. // For EventEmitter
  1933. var EE_ADD_LISTENER = 'addListener';
  1934. var EE_PREPEND_LISTENER = 'prependListener';
  1935. var EE_REMOVE_LISTENER = 'removeListener';
  1936. var EE_REMOVE_ALL_LISTENER = 'removeAllListeners';
  1937. var EE_LISTENERS = 'listeners';
  1938. var EE_ON = 'on';
  1939. var compareTaskCallbackVsDelegate = function (task, delegate) {
  1940. // same callback, same capture, same event name, just return
  1941. return task.callback === delegate || task.callback.listener === delegate;
  1942. };
  1943. function patchEventEmitterMethods(obj) {
  1944. var result = patchEventTarget(global, [obj], {
  1945. useG: false,
  1946. add: EE_ADD_LISTENER,
  1947. rm: EE_REMOVE_LISTENER,
  1948. prepend: EE_PREPEND_LISTENER,
  1949. rmAll: EE_REMOVE_ALL_LISTENER,
  1950. listeners: EE_LISTENERS,
  1951. chkDup: false,
  1952. rt: true,
  1953. diff: compareTaskCallbackVsDelegate
  1954. });
  1955. if (result && result[0]) {
  1956. obj[EE_ON] = obj[EE_ADD_LISTENER];
  1957. }
  1958. }
  1959. // EventEmitter
  1960. var events;
  1961. try {
  1962. events = require('events');
  1963. }
  1964. catch (err) {
  1965. }
  1966. if (events && events.EventEmitter) {
  1967. patchEventEmitterMethods(events.EventEmitter.prototype);
  1968. }
  1969. });
  1970. /**
  1971. * @license
  1972. * Copyright Google Inc. All Rights Reserved.
  1973. *
  1974. * Use of this source code is governed by an MIT-style license that can be
  1975. * found in the LICENSE file at https://angular.io/license
  1976. */
  1977. Zone.__load_patch('fs', function () {
  1978. var fs;
  1979. try {
  1980. fs = require('fs');
  1981. }
  1982. catch (err) {
  1983. }
  1984. // watch, watchFile, unwatchFile has been patched
  1985. // because EventEmitter has been patched
  1986. var TO_PATCH_MACROTASK_METHODS = [
  1987. 'access', 'appendFile', 'chmod', 'chown', 'close', 'exists', 'fchmod',
  1988. 'fchown', 'fdatasync', 'fstat', 'fsync', 'ftruncate', 'futimes', 'lchmod',
  1989. 'lchown', 'link', 'lstat', 'mkdir', 'mkdtemp', 'open', 'read',
  1990. 'readdir', 'readFile', 'readlink', 'realpath', 'rename', 'rmdir', 'stat',
  1991. 'symlink', 'truncate', 'unlink', 'utimes', 'write', 'writeFile',
  1992. ];
  1993. if (fs) {
  1994. TO_PATCH_MACROTASK_METHODS.filter(function (name) { return !!fs[name] && typeof fs[name] === 'function'; })
  1995. .forEach(function (name) {
  1996. patchMacroTask(fs, name, function (self, args) {
  1997. return {
  1998. name: 'fs.' + name,
  1999. args: args,
  2000. cbIdx: args.length > 0 ? args.length - 1 : -1,
  2001. target: self
  2002. };
  2003. });
  2004. });
  2005. }
  2006. });
  2007. /**
  2008. * @license
  2009. * Copyright Google Inc. All Rights Reserved.
  2010. *
  2011. * Use of this source code is governed by an MIT-style license that can be
  2012. * found in the LICENSE file at https://angular.io/license
  2013. */
  2014. /**
  2015. * @fileoverview
  2016. * @suppress {missingRequire}
  2017. */
  2018. var taskSymbol = zoneSymbol('zoneTask');
  2019. function patchTimer(window, setName, cancelName, nameSuffix) {
  2020. var setNative = null;
  2021. var clearNative = null;
  2022. setName += nameSuffix;
  2023. cancelName += nameSuffix;
  2024. var tasksByHandleId = {};
  2025. function scheduleTask(task) {
  2026. var data = task.data;
  2027. function timer() {
  2028. try {
  2029. task.invoke.apply(this, arguments);
  2030. }
  2031. finally {
  2032. // issue-934, task will be cancelled
  2033. // even it is a periodic task such as
  2034. // setInterval
  2035. if (!(task.data && task.data.isPeriodic)) {
  2036. if (typeof data.handleId === 'number') {
  2037. // in non-nodejs env, we remove timerId
  2038. // from local cache
  2039. delete tasksByHandleId[data.handleId];
  2040. }
  2041. else if (data.handleId) {
  2042. // Node returns complex objects as handleIds
  2043. // we remove task reference from timer object
  2044. data.handleId[taskSymbol] = null;
  2045. }
  2046. }
  2047. }
  2048. }
  2049. data.args[0] = timer;
  2050. data.handleId = setNative.apply(window, data.args);
  2051. return task;
  2052. }
  2053. function clearTask(task) {
  2054. return clearNative(task.data.handleId);
  2055. }
  2056. setNative =
  2057. patchMethod(window, setName, function (delegate) { return function (self, args) {
  2058. if (typeof args[0] === 'function') {
  2059. var options = {
  2060. handleId: null,
  2061. isPeriodic: nameSuffix === 'Interval',
  2062. delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : null,
  2063. args: args
  2064. };
  2065. var task = scheduleMacroTaskWithCurrentZone(setName, args[0], options, scheduleTask, clearTask);
  2066. if (!task) {
  2067. return task;
  2068. }
  2069. // Node.js must additionally support the ref and unref functions.
  2070. var handle = task.data.handleId;
  2071. if (typeof handle === 'number') {
  2072. // for non nodejs env, we save handleId: task
  2073. // mapping in local cache for clearTimeout
  2074. tasksByHandleId[handle] = task;
  2075. }
  2076. else if (handle) {
  2077. // for nodejs env, we save task
  2078. // reference in timerId Object for clearTimeout
  2079. handle[taskSymbol] = task;
  2080. }
  2081. // check whether handle is null, because some polyfill or browser
  2082. // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame
  2083. if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' &&
  2084. typeof handle.unref === 'function') {
  2085. task.ref = handle.ref.bind(handle);
  2086. task.unref = handle.unref.bind(handle);
  2087. }
  2088. if (typeof handle === 'number' || handle) {
  2089. return handle;
  2090. }
  2091. return task;
  2092. }
  2093. else {
  2094. // cause an error by calling it directly.
  2095. return delegate.apply(window, args);
  2096. }
  2097. }; });
  2098. clearNative =
  2099. patchMethod(window, cancelName, function (delegate) { return function (self, args) {
  2100. var id = args[0];
  2101. var task;
  2102. if (typeof id === 'number') {
  2103. // non nodejs env.
  2104. task = tasksByHandleId[id];
  2105. }
  2106. else {
  2107. // nodejs env.
  2108. task = id && id[taskSymbol];
  2109. // other environments.
  2110. if (!task) {
  2111. task = id;
  2112. }
  2113. }
  2114. if (task && typeof task.type === 'string') {
  2115. if (task.state !== 'notScheduled' &&
  2116. (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
  2117. if (typeof id === 'number') {
  2118. delete tasksByHandleId[id];
  2119. }
  2120. else if (id) {
  2121. id[taskSymbol] = null;
  2122. }
  2123. // Do not cancel already canceled functions
  2124. task.zone.cancelTask(task);
  2125. }
  2126. }
  2127. else {
  2128. // cause an error by calling it directly.
  2129. delegate.apply(window, args);
  2130. }
  2131. }; });
  2132. }
  2133. /**
  2134. * @license
  2135. * Copyright Google Inc. All Rights Reserved.
  2136. *
  2137. * Use of this source code is governed by an MIT-style license that can be
  2138. * found in the LICENSE file at https://angular.io/license
  2139. */
  2140. var set = 'set';
  2141. var clear = 'clear';
  2142. Zone.__load_patch('node_util', function (global, Zone, api) {
  2143. api.patchOnProperties = patchOnProperties;
  2144. api.patchMethod = patchMethod;
  2145. api.bindArguments = bindArguments;
  2146. });
  2147. Zone.__load_patch('node_timers', function (global, Zone) {
  2148. // Timers
  2149. var globalUseTimeoutFromTimer = false;
  2150. try {
  2151. var timers = require('timers');
  2152. var globalEqualTimersTimeout = global.setTimeout === timers.setTimeout;
  2153. if (!globalEqualTimersTimeout && !isMix) {
  2154. // 1. if isMix, then we are in mix environment such as Electron
  2155. // we should only patch timers.setTimeout because global.setTimeout
  2156. // have been patched
  2157. // 2. if global.setTimeout not equal timers.setTimeout, check
  2158. // whether global.setTimeout use timers.setTimeout or not
  2159. var originSetTimeout_1 = timers.setTimeout;
  2160. timers.setTimeout = function () {
  2161. globalUseTimeoutFromTimer = true;
  2162. return originSetTimeout_1.apply(this, arguments);
  2163. };
  2164. var detectTimeout = global.setTimeout(function () { }, 100);
  2165. clearTimeout(detectTimeout);
  2166. timers.setTimeout = originSetTimeout_1;
  2167. }
  2168. patchTimer(timers, set, clear, 'Timeout');
  2169. patchTimer(timers, set, clear, 'Interval');
  2170. patchTimer(timers, set, clear, 'Immediate');
  2171. }
  2172. catch (error) {
  2173. // timers module not exists, for example, when we using nativeScript
  2174. // timers is not available
  2175. }
  2176. if (isMix) {
  2177. // if we are in mix environment, such as Electron,
  2178. // the global.setTimeout has already been patched,
  2179. // so we just patch timers.setTimeout
  2180. return;
  2181. }
  2182. if (!globalUseTimeoutFromTimer) {
  2183. // 1. global setTimeout equals timers setTimeout
  2184. // 2. or global don't use timers setTimeout(maybe some other library patch setTimeout)
  2185. // 3. or load timers module error happens, we should patch global setTimeout
  2186. patchTimer(global, set, clear, 'Timeout');
  2187. patchTimer(global, set, clear, 'Interval');
  2188. patchTimer(global, set, clear, 'Immediate');
  2189. }
  2190. else {
  2191. // global use timers setTimeout, but not equals
  2192. // this happens when use nodejs v0.10.x, global setTimeout will
  2193. // use a lazy load version of timers setTimeout
  2194. // we should not double patch timer's setTimeout
  2195. // so we only store the __symbol__ for consistency
  2196. global[Zone.__symbol__('setTimeout')] = global.setTimeout;
  2197. global[Zone.__symbol__('setInterval')] = global.setInterval;
  2198. global[Zone.__symbol__('setImmediate')] = global.setImmediate;
  2199. }
  2200. });
  2201. // patch process related methods
  2202. Zone.__load_patch('nextTick', function () {
  2203. // patch nextTick as microTask
  2204. patchMicroTask(process, 'nextTick', function (self, args) {
  2205. return {
  2206. name: 'process.nextTick',
  2207. args: args,
  2208. cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1,
  2209. target: process
  2210. };
  2211. });
  2212. });
  2213. Zone.__load_patch('handleUnhandledPromiseRejection', function (global, Zone, api) {
  2214. Zone[api.symbol('unhandledPromiseRejectionHandler')] =
  2215. findProcessPromiseRejectionHandler('unhandledRejection');
  2216. Zone[api.symbol('rejectionHandledHandler')] =
  2217. findProcessPromiseRejectionHandler('rejectionHandled');
  2218. // handle unhandled promise rejection
  2219. function findProcessPromiseRejectionHandler(evtName) {
  2220. return function (e) {
  2221. var eventTasks = findEventTasks(process, evtName);
  2222. eventTasks.forEach(function (eventTask) {
  2223. // process has added unhandledrejection event listener
  2224. // trigger the event listener
  2225. if (evtName === 'unhandledRejection') {
  2226. eventTask.invoke(e.rejection, e.promise);
  2227. }
  2228. else if (evtName === 'rejectionHandled') {
  2229. eventTask.invoke(e.promise);
  2230. }
  2231. });
  2232. };
  2233. }
  2234. });
  2235. // Crypto
  2236. Zone.__load_patch('crypto', function () {
  2237. var crypto;
  2238. try {
  2239. crypto = require('crypto');
  2240. }
  2241. catch (err) {
  2242. }
  2243. // use the generic patchMacroTask to patch crypto
  2244. if (crypto) {
  2245. var methodNames = ['randomBytes', 'pbkdf2'];
  2246. methodNames.forEach(function (name) {
  2247. patchMacroTask(crypto, name, function (self, args) {
  2248. return {
  2249. name: 'crypto.' + name,
  2250. args: args,
  2251. cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ?
  2252. args.length - 1 :
  2253. -1,
  2254. target: crypto
  2255. };
  2256. });
  2257. });
  2258. }
  2259. });
  2260. Zone.__load_patch('console', function (global, Zone) {
  2261. var consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace'];
  2262. consoleMethods.forEach(function (m) {
  2263. var originalMethod = console[Zone.__symbol__(m)] = console[m];
  2264. if (originalMethod) {
  2265. console[m] = function () {
  2266. var args = ArraySlice.call(arguments);
  2267. if (Zone.current === Zone.root) {
  2268. return originalMethod.apply(this, args);
  2269. }
  2270. else {
  2271. return Zone.root.run(originalMethod, this, args);
  2272. }
  2273. };
  2274. }
  2275. });
  2276. });
  2277. /**
  2278. * @license
  2279. * Copyright Google Inc. All Rights Reserved.
  2280. *
  2281. * Use of this source code is governed by an MIT-style license that can be
  2282. * found in the LICENSE file at https://angular.io/license
  2283. */
  2284. })));