zone-mix.js 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285
  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 performance = global['performance'];
  22. function mark(name) {
  23. performance && performance['mark'] && performance['mark'](name);
  24. }
  25. function performanceMeasure(name, label) {
  26. performance && performance['measure'] && performance['measure'](name, label);
  27. }
  28. mark('Zone');
  29. var checkDuplicate = global[('__zone_symbol__forceDuplicateZoneCheck')] === true;
  30. if (global['Zone']) {
  31. // if global['Zone'] already exists (maybe zone.js was already loaded or
  32. // some other lib also registered a global object named Zone), we may need
  33. // to throw an error, but sometimes user may not want this error.
  34. // For example,
  35. // we have two web pages, page1 includes zone.js, page2 doesn't.
  36. // and the 1st time user load page1 and page2, everything work fine,
  37. // but when user load page2 again, error occurs because global['Zone'] already exists.
  38. // so we add a flag to let user choose whether to throw this error or not.
  39. // By default, if existing Zone is from zone.js, we will not throw the error.
  40. if (checkDuplicate || typeof global['Zone'].__symbol__ !== 'function') {
  41. throw new Error('Zone already loaded.');
  42. }
  43. else {
  44. return global['Zone'];
  45. }
  46. }
  47. var Zone = /** @class */ (function () {
  48. function Zone(parent, zoneSpec) {
  49. this._parent = parent;
  50. this._name = zoneSpec ? zoneSpec.name || 'unnamed' : '<root>';
  51. this._properties = zoneSpec && zoneSpec.properties || {};
  52. this._zoneDelegate =
  53. new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec);
  54. }
  55. Zone.assertZonePatched = function () {
  56. if (global['Promise'] !== patches['ZoneAwarePromise']) {
  57. throw new Error('Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
  58. 'has been overwritten.\n' +
  59. 'Most likely cause is that a Promise polyfill has been loaded ' +
  60. 'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' +
  61. 'If you must load one, do so before loading zone.js.)');
  62. }
  63. };
  64. Object.defineProperty(Zone, "root", {
  65. get: function () {
  66. var zone = Zone.current;
  67. while (zone.parent) {
  68. zone = zone.parent;
  69. }
  70. return zone;
  71. },
  72. enumerable: true,
  73. configurable: true
  74. });
  75. Object.defineProperty(Zone, "current", {
  76. get: function () {
  77. return _currentZoneFrame.zone;
  78. },
  79. enumerable: true,
  80. configurable: true
  81. });
  82. Object.defineProperty(Zone, "currentTask", {
  83. get: function () {
  84. return _currentTask;
  85. },
  86. enumerable: true,
  87. configurable: true
  88. });
  89. Zone.__load_patch = function (name, fn) {
  90. if (patches.hasOwnProperty(name)) {
  91. if (checkDuplicate) {
  92. throw Error('Already loaded patch: ' + name);
  93. }
  94. }
  95. else if (!global['__Zone_disable_' + name]) {
  96. var perfName = 'Zone:' + name;
  97. mark(perfName);
  98. patches[name] = fn(global, Zone, _api);
  99. performanceMeasure(perfName, perfName);
  100. }
  101. };
  102. Object.defineProperty(Zone.prototype, "parent", {
  103. get: function () {
  104. return this._parent;
  105. },
  106. enumerable: true,
  107. configurable: true
  108. });
  109. Object.defineProperty(Zone.prototype, "name", {
  110. get: function () {
  111. return this._name;
  112. },
  113. enumerable: true,
  114. configurable: true
  115. });
  116. Zone.prototype.get = function (key) {
  117. var zone = this.getZoneWith(key);
  118. if (zone)
  119. return zone._properties[key];
  120. };
  121. Zone.prototype.getZoneWith = function (key) {
  122. var current = this;
  123. while (current) {
  124. if (current._properties.hasOwnProperty(key)) {
  125. return current;
  126. }
  127. current = current._parent;
  128. }
  129. return null;
  130. };
  131. Zone.prototype.fork = function (zoneSpec) {
  132. if (!zoneSpec)
  133. throw new Error('ZoneSpec required!');
  134. return this._zoneDelegate.fork(this, zoneSpec);
  135. };
  136. Zone.prototype.wrap = function (callback, source) {
  137. if (typeof callback !== 'function') {
  138. throw new Error('Expecting function got: ' + callback);
  139. }
  140. var _callback = this._zoneDelegate.intercept(this, callback, source);
  141. var zone = this;
  142. return function () {
  143. return zone.runGuarded(_callback, this, arguments, source);
  144. };
  145. };
  146. Zone.prototype.run = function (callback, applyThis, applyArgs, source) {
  147. _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
  148. try {
  149. return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
  150. }
  151. finally {
  152. _currentZoneFrame = _currentZoneFrame.parent;
  153. }
  154. };
  155. Zone.prototype.runGuarded = function (callback, applyThis, applyArgs, source) {
  156. if (applyThis === void 0) { applyThis = null; }
  157. _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
  158. try {
  159. try {
  160. return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
  161. }
  162. catch (error) {
  163. if (this._zoneDelegate.handleError(this, error)) {
  164. throw error;
  165. }
  166. }
  167. }
  168. finally {
  169. _currentZoneFrame = _currentZoneFrame.parent;
  170. }
  171. };
  172. Zone.prototype.runTask = function (task, applyThis, applyArgs) {
  173. if (task.zone != this) {
  174. throw new Error('A task can only be run in the zone of creation! (Creation: ' +
  175. (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
  176. }
  177. // https://github.com/angular/zone.js/issues/778, sometimes eventTask
  178. // will run in notScheduled(canceled) state, we should not try to
  179. // run such kind of task but just return
  180. if (task.state === notScheduled && (task.type === eventTask || task.type === macroTask)) {
  181. return;
  182. }
  183. var reEntryGuard = task.state != running;
  184. reEntryGuard && task._transitionTo(running, scheduled);
  185. task.runCount++;
  186. var previousTask = _currentTask;
  187. _currentTask = task;
  188. _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
  189. try {
  190. if (task.type == macroTask && task.data && !task.data.isPeriodic) {
  191. task.cancelFn = undefined;
  192. }
  193. try {
  194. return this._zoneDelegate.invokeTask(this, task, applyThis, applyArgs);
  195. }
  196. catch (error) {
  197. if (this._zoneDelegate.handleError(this, error)) {
  198. throw error;
  199. }
  200. }
  201. }
  202. finally {
  203. // if the task's state is notScheduled or unknown, then it has already been cancelled
  204. // we should not reset the state to scheduled
  205. if (task.state !== notScheduled && task.state !== unknown) {
  206. if (task.type == eventTask || (task.data && task.data.isPeriodic)) {
  207. reEntryGuard && task._transitionTo(scheduled, running);
  208. }
  209. else {
  210. task.runCount = 0;
  211. this._updateTaskCount(task, -1);
  212. reEntryGuard &&
  213. task._transitionTo(notScheduled, running, notScheduled);
  214. }
  215. }
  216. _currentZoneFrame = _currentZoneFrame.parent;
  217. _currentTask = previousTask;
  218. }
  219. };
  220. Zone.prototype.scheduleTask = function (task) {
  221. if (task.zone && task.zone !== this) {
  222. // check if the task was rescheduled, the newZone
  223. // should not be the children of the original zone
  224. var newZone = this;
  225. while (newZone) {
  226. if (newZone === task.zone) {
  227. throw Error("can not reschedule task to " + this.name + " which is descendants of the original zone " + task.zone.name);
  228. }
  229. newZone = newZone.parent;
  230. }
  231. }
  232. task._transitionTo(scheduling, notScheduled);
  233. var zoneDelegates = [];
  234. task._zoneDelegates = zoneDelegates;
  235. task._zone = this;
  236. try {
  237. task = this._zoneDelegate.scheduleTask(this, task);
  238. }
  239. catch (err) {
  240. // should set task's state to unknown when scheduleTask throw error
  241. // because the err may from reschedule, so the fromState maybe notScheduled
  242. task._transitionTo(unknown, scheduling, notScheduled);
  243. // TODO: @JiaLiPassion, should we check the result from handleError?
  244. this._zoneDelegate.handleError(this, err);
  245. throw err;
  246. }
  247. if (task._zoneDelegates === zoneDelegates) {
  248. // we have to check because internally the delegate can reschedule the task.
  249. this._updateTaskCount(task, 1);
  250. }
  251. if (task.state == scheduling) {
  252. task._transitionTo(scheduled, scheduling);
  253. }
  254. return task;
  255. };
  256. Zone.prototype.scheduleMicroTask = function (source, callback, data, customSchedule) {
  257. return this.scheduleTask(new ZoneTask(microTask, source, callback, data, customSchedule, undefined));
  258. };
  259. Zone.prototype.scheduleMacroTask = function (source, callback, data, customSchedule, customCancel) {
  260. return this.scheduleTask(new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel));
  261. };
  262. Zone.prototype.scheduleEventTask = function (source, callback, data, customSchedule, customCancel) {
  263. return this.scheduleTask(new ZoneTask(eventTask, source, callback, data, customSchedule, customCancel));
  264. };
  265. Zone.prototype.cancelTask = function (task) {
  266. if (task.zone != this)
  267. throw new Error('A task can only be cancelled in the zone of creation! (Creation: ' +
  268. (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
  269. task._transitionTo(canceling, scheduled, running);
  270. try {
  271. this._zoneDelegate.cancelTask(this, task);
  272. }
  273. catch (err) {
  274. // if error occurs when cancelTask, transit the state to unknown
  275. task._transitionTo(unknown, canceling);
  276. this._zoneDelegate.handleError(this, err);
  277. throw err;
  278. }
  279. this._updateTaskCount(task, -1);
  280. task._transitionTo(notScheduled, canceling);
  281. task.runCount = 0;
  282. return task;
  283. };
  284. Zone.prototype._updateTaskCount = function (task, count) {
  285. var zoneDelegates = task._zoneDelegates;
  286. if (count == -1) {
  287. task._zoneDelegates = null;
  288. }
  289. for (var i = 0; i < zoneDelegates.length; i++) {
  290. zoneDelegates[i]._updateTaskCount(task.type, count);
  291. }
  292. };
  293. Zone.__symbol__ = __symbol__;
  294. return Zone;
  295. }());
  296. var DELEGATE_ZS = {
  297. name: '',
  298. onHasTask: function (delegate, _, target, hasTaskState) { return delegate.hasTask(target, hasTaskState); },
  299. onScheduleTask: function (delegate, _, target, task) {
  300. return delegate.scheduleTask(target, task);
  301. },
  302. onInvokeTask: function (delegate, _, target, task, applyThis, applyArgs) {
  303. return delegate.invokeTask(target, task, applyThis, applyArgs);
  304. },
  305. onCancelTask: function (delegate, _, target, task) { return delegate.cancelTask(target, task); }
  306. };
  307. var ZoneDelegate = /** @class */ (function () {
  308. function ZoneDelegate(zone, parentDelegate, zoneSpec) {
  309. this._taskCounts = { 'microTask': 0, 'macroTask': 0, 'eventTask': 0 };
  310. this.zone = zone;
  311. this._parentDelegate = parentDelegate;
  312. this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate._forkZS);
  313. this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate._forkDlgt);
  314. this._forkCurrZone = zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate.zone);
  315. this._interceptZS =
  316. zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS);
  317. this._interceptDlgt =
  318. zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt);
  319. this._interceptCurrZone =
  320. zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate.zone);
  321. this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate._invokeZS);
  322. this._invokeDlgt =
  323. zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt);
  324. this._invokeCurrZone = zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate.zone);
  325. this._handleErrorZS =
  326. zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS);
  327. this._handleErrorDlgt =
  328. zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt);
  329. this._handleErrorCurrZone =
  330. zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate.zone);
  331. this._scheduleTaskZS =
  332. zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS);
  333. this._scheduleTaskDlgt = zoneSpec &&
  334. (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt);
  335. this._scheduleTaskCurrZone =
  336. zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate.zone);
  337. this._invokeTaskZS =
  338. zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS);
  339. this._invokeTaskDlgt =
  340. zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt);
  341. this._invokeTaskCurrZone =
  342. zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate.zone);
  343. this._cancelTaskZS =
  344. zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS);
  345. this._cancelTaskDlgt =
  346. zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt);
  347. this._cancelTaskCurrZone =
  348. zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate.zone);
  349. this._hasTaskZS = null;
  350. this._hasTaskDlgt = null;
  351. this._hasTaskDlgtOwner = null;
  352. this._hasTaskCurrZone = null;
  353. var zoneSpecHasTask = zoneSpec && zoneSpec.onHasTask;
  354. var parentHasTask = parentDelegate && parentDelegate._hasTaskZS;
  355. if (zoneSpecHasTask || parentHasTask) {
  356. // If we need to report hasTask, than this ZS needs to do ref counting on tasks. In such
  357. // a case all task related interceptors must go through this ZD. We can't short circuit it.
  358. this._hasTaskZS = zoneSpecHasTask ? zoneSpec : DELEGATE_ZS;
  359. this._hasTaskDlgt = parentDelegate;
  360. this._hasTaskDlgtOwner = this;
  361. this._hasTaskCurrZone = zone;
  362. if (!zoneSpec.onScheduleTask) {
  363. this._scheduleTaskZS = DELEGATE_ZS;
  364. this._scheduleTaskDlgt = parentDelegate;
  365. this._scheduleTaskCurrZone = this.zone;
  366. }
  367. if (!zoneSpec.onInvokeTask) {
  368. this._invokeTaskZS = DELEGATE_ZS;
  369. this._invokeTaskDlgt = parentDelegate;
  370. this._invokeTaskCurrZone = this.zone;
  371. }
  372. if (!zoneSpec.onCancelTask) {
  373. this._cancelTaskZS = DELEGATE_ZS;
  374. this._cancelTaskDlgt = parentDelegate;
  375. this._cancelTaskCurrZone = this.zone;
  376. }
  377. }
  378. }
  379. ZoneDelegate.prototype.fork = function (targetZone, zoneSpec) {
  380. return this._forkZS ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) :
  381. new Zone(targetZone, zoneSpec);
  382. };
  383. ZoneDelegate.prototype.intercept = function (targetZone, callback, source) {
  384. return this._interceptZS ?
  385. this._interceptZS.onIntercept(this._interceptDlgt, this._interceptCurrZone, targetZone, callback, source) :
  386. callback;
  387. };
  388. ZoneDelegate.prototype.invoke = function (targetZone, callback, applyThis, applyArgs, source) {
  389. return this._invokeZS ? this._invokeZS.onInvoke(this._invokeDlgt, this._invokeCurrZone, targetZone, callback, applyThis, applyArgs, source) :
  390. callback.apply(applyThis, applyArgs);
  391. };
  392. ZoneDelegate.prototype.handleError = function (targetZone, error) {
  393. return this._handleErrorZS ?
  394. this._handleErrorZS.onHandleError(this._handleErrorDlgt, this._handleErrorCurrZone, targetZone, error) :
  395. true;
  396. };
  397. ZoneDelegate.prototype.scheduleTask = function (targetZone, task) {
  398. var returnTask = task;
  399. if (this._scheduleTaskZS) {
  400. if (this._hasTaskZS) {
  401. returnTask._zoneDelegates.push(this._hasTaskDlgtOwner);
  402. }
  403. returnTask = this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt, this._scheduleTaskCurrZone, targetZone, task);
  404. if (!returnTask)
  405. returnTask = task;
  406. }
  407. else {
  408. if (task.scheduleFn) {
  409. task.scheduleFn(task);
  410. }
  411. else if (task.type == microTask) {
  412. scheduleMicroTask(task);
  413. }
  414. else {
  415. throw new Error('Task is missing scheduleFn.');
  416. }
  417. }
  418. return returnTask;
  419. };
  420. ZoneDelegate.prototype.invokeTask = function (targetZone, task, applyThis, applyArgs) {
  421. return this._invokeTaskZS ? this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this._invokeTaskCurrZone, targetZone, task, applyThis, applyArgs) :
  422. task.callback.apply(applyThis, applyArgs);
  423. };
  424. ZoneDelegate.prototype.cancelTask = function (targetZone, task) {
  425. var value;
  426. if (this._cancelTaskZS) {
  427. value = this._cancelTaskZS.onCancelTask(this._cancelTaskDlgt, this._cancelTaskCurrZone, targetZone, task);
  428. }
  429. else {
  430. if (!task.cancelFn) {
  431. throw Error('Task is not cancelable');
  432. }
  433. value = task.cancelFn(task);
  434. }
  435. return value;
  436. };
  437. ZoneDelegate.prototype.hasTask = function (targetZone, isEmpty) {
  438. // hasTask should not throw error so other ZoneDelegate
  439. // can still trigger hasTask callback
  440. try {
  441. this._hasTaskZS &&
  442. this._hasTaskZS.onHasTask(this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
  443. }
  444. catch (err) {
  445. this.handleError(targetZone, err);
  446. }
  447. };
  448. ZoneDelegate.prototype._updateTaskCount = function (type, count) {
  449. var counts = this._taskCounts;
  450. var prev = counts[type];
  451. var next = counts[type] = prev + count;
  452. if (next < 0) {
  453. throw new Error('More tasks executed then were scheduled.');
  454. }
  455. if (prev == 0 || next == 0) {
  456. var isEmpty = {
  457. microTask: counts['microTask'] > 0,
  458. macroTask: counts['macroTask'] > 0,
  459. eventTask: counts['eventTask'] > 0,
  460. change: type
  461. };
  462. this.hasTask(this.zone, isEmpty);
  463. }
  464. };
  465. return ZoneDelegate;
  466. }());
  467. var ZoneTask = /** @class */ (function () {
  468. function ZoneTask(type, source, callback, options, scheduleFn, cancelFn) {
  469. this._zone = null;
  470. this.runCount = 0;
  471. this._zoneDelegates = null;
  472. this._state = 'notScheduled';
  473. this.type = type;
  474. this.source = source;
  475. this.data = options;
  476. this.scheduleFn = scheduleFn;
  477. this.cancelFn = cancelFn;
  478. this.callback = callback;
  479. var self = this;
  480. // TODO: @JiaLiPassion options should have interface
  481. if (type === eventTask && options && options.useG) {
  482. this.invoke = ZoneTask.invokeTask;
  483. }
  484. else {
  485. this.invoke = function () {
  486. return ZoneTask.invokeTask.call(global, self, this, arguments);
  487. };
  488. }
  489. }
  490. ZoneTask.invokeTask = function (task, target, args) {
  491. if (!task) {
  492. task = this;
  493. }
  494. _numberOfNestedTaskFrames++;
  495. try {
  496. task.runCount++;
  497. return task.zone.runTask(task, target, args);
  498. }
  499. finally {
  500. if (_numberOfNestedTaskFrames == 1) {
  501. drainMicroTaskQueue();
  502. }
  503. _numberOfNestedTaskFrames--;
  504. }
  505. };
  506. Object.defineProperty(ZoneTask.prototype, "zone", {
  507. get: function () {
  508. return this._zone;
  509. },
  510. enumerable: true,
  511. configurable: true
  512. });
  513. Object.defineProperty(ZoneTask.prototype, "state", {
  514. get: function () {
  515. return this._state;
  516. },
  517. enumerable: true,
  518. configurable: true
  519. });
  520. ZoneTask.prototype.cancelScheduleRequest = function () {
  521. this._transitionTo(notScheduled, scheduling);
  522. };
  523. ZoneTask.prototype._transitionTo = function (toState, fromState1, fromState2) {
  524. if (this._state === fromState1 || this._state === fromState2) {
  525. this._state = toState;
  526. if (toState == notScheduled) {
  527. this._zoneDelegates = null;
  528. }
  529. }
  530. else {
  531. throw new Error(this.type + " '" + this.source + "': can not transition to '" + toState + "', expecting state '" + fromState1 + "'" + (fromState2 ? ' or \'' + fromState2 + '\'' : '') + ", was '" + this._state + "'.");
  532. }
  533. };
  534. ZoneTask.prototype.toString = function () {
  535. if (this.data && typeof this.data.handleId !== 'undefined') {
  536. return this.data.handleId.toString();
  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. var nativeThen = nativeMicroTaskQueuePromise[symbolThen];
  578. if (!nativeThen) {
  579. // native Promise is not patchable, we need to use `then` directly
  580. // issue 1078
  581. nativeThen = nativeMicroTaskQueuePromise['then'];
  582. }
  583. nativeThen.call(nativeMicroTaskQueuePromise, drainMicroTaskQueue);
  584. }
  585. else {
  586. global[symbolSetTimeout](drainMicroTaskQueue, 0);
  587. }
  588. }
  589. task && _microTaskQueue.push(task);
  590. }
  591. function drainMicroTaskQueue() {
  592. if (!_isDrainingMicrotaskQueue) {
  593. _isDrainingMicrotaskQueue = true;
  594. while (_microTaskQueue.length) {
  595. var queue = _microTaskQueue;
  596. _microTaskQueue = [];
  597. for (var i = 0; i < queue.length; i++) {
  598. var task = queue[i];
  599. try {
  600. task.zone.runTask(task, null, null);
  601. }
  602. catch (error) {
  603. _api.onUnhandledError(error);
  604. }
  605. }
  606. }
  607. _api.microtaskDrainDone();
  608. _isDrainingMicrotaskQueue = false;
  609. }
  610. }
  611. //////////////////////////////////////////////////////
  612. //////////////////////////////////////////////////////
  613. /// BOOTSTRAP
  614. //////////////////////////////////////////////////////
  615. //////////////////////////////////////////////////////
  616. var NO_ZONE = { name: 'NO ZONE' };
  617. var notScheduled = 'notScheduled', scheduling = 'scheduling', scheduled = 'scheduled', running = 'running', canceling = 'canceling', unknown = 'unknown';
  618. var microTask = 'microTask', macroTask = 'macroTask', eventTask = 'eventTask';
  619. var patches = {};
  620. var _api = {
  621. symbol: __symbol__,
  622. currentZoneFrame: function () { return _currentZoneFrame; },
  623. onUnhandledError: noop,
  624. microtaskDrainDone: noop,
  625. scheduleMicroTask: scheduleMicroTask,
  626. showUncaughtError: function () { return !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; },
  627. patchEventTarget: function () { return []; },
  628. patchOnProperties: noop,
  629. patchMethod: function () { return noop; },
  630. bindArguments: function () { return []; },
  631. patchThen: function () { return noop; },
  632. patchMacroTask: function () { return noop; },
  633. setNativePromise: function (NativePromise) {
  634. // sometimes NativePromise.resolve static function
  635. // is not ready yet, (such as core-js/es6.promise)
  636. // so we need to check here.
  637. if (NativePromise && typeof NativePromise.resolve === 'function') {
  638. nativeMicroTaskQueuePromise = NativePromise.resolve(0);
  639. }
  640. },
  641. patchEventPrototype: function () { return noop; },
  642. isIEOrEdge: function () { return false; },
  643. getGlobalObjects: function () { return undefined; },
  644. ObjectDefineProperty: function () { return noop; },
  645. ObjectGetOwnPropertyDescriptor: function () { return undefined; },
  646. ObjectCreate: function () { return undefined; },
  647. ArraySlice: function () { return []; },
  648. patchClass: function () { return noop; },
  649. wrapWithCurrentZone: function () { return noop; },
  650. filterProperties: function () { return []; },
  651. attachOriginToPatched: function () { return noop; },
  652. _redefineProperty: function () { return noop; },
  653. patchCallbacks: function () { return noop; }
  654. };
  655. var _currentZoneFrame = { parent: null, zone: new Zone(null, null) };
  656. var _currentTask = null;
  657. var _numberOfNestedTaskFrames = 0;
  658. function noop() { }
  659. function __symbol__(name) {
  660. return '__zone_symbol__' + name;
  661. }
  662. performanceMeasure('Zone', 'Zone');
  663. return global['Zone'] = Zone;
  664. })(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
  665. var __values = (undefined && undefined.__values) || function (o) {
  666. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  667. if (m) return m.call(o);
  668. return {
  669. next: function () {
  670. if (o && i >= o.length) o = void 0;
  671. return { value: o && o[i++], done: !o };
  672. }
  673. };
  674. };
  675. /**
  676. * @license
  677. * Copyright Google Inc. All Rights Reserved.
  678. *
  679. * Use of this source code is governed by an MIT-style license that can be
  680. * found in the LICENSE file at https://angular.io/license
  681. */
  682. Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) {
  683. var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  684. var ObjectDefineProperty = Object.defineProperty;
  685. function readableObjectToString(obj) {
  686. if (obj && obj.toString === Object.prototype.toString) {
  687. var className = obj.constructor && obj.constructor.name;
  688. return (className ? className : '') + ': ' + JSON.stringify(obj);
  689. }
  690. return obj ? obj.toString() : Object.prototype.toString.call(obj);
  691. }
  692. var __symbol__ = api.symbol;
  693. var _uncaughtPromiseErrors = [];
  694. var symbolPromise = __symbol__('Promise');
  695. var symbolThen = __symbol__('then');
  696. var creationTrace = '__creationTrace__';
  697. api.onUnhandledError = function (e) {
  698. if (api.showUncaughtError()) {
  699. var rejection = e && e.rejection;
  700. if (rejection) {
  701. 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);
  702. }
  703. else {
  704. console.error(e);
  705. }
  706. }
  707. };
  708. api.microtaskDrainDone = function () {
  709. while (_uncaughtPromiseErrors.length) {
  710. var _loop_1 = function () {
  711. var uncaughtPromiseError = _uncaughtPromiseErrors.shift();
  712. try {
  713. uncaughtPromiseError.zone.runGuarded(function () {
  714. throw uncaughtPromiseError;
  715. });
  716. }
  717. catch (error) {
  718. handleUnhandledRejection(error);
  719. }
  720. };
  721. while (_uncaughtPromiseErrors.length) {
  722. _loop_1();
  723. }
  724. }
  725. };
  726. var UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__('unhandledPromiseRejectionHandler');
  727. function handleUnhandledRejection(e) {
  728. api.onUnhandledError(e);
  729. try {
  730. var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL];
  731. if (handler && typeof handler === 'function') {
  732. handler.call(this, e);
  733. }
  734. }
  735. catch (err) {
  736. }
  737. }
  738. function isThenable(value) {
  739. return value && value.then;
  740. }
  741. function forwardResolution(value) {
  742. return value;
  743. }
  744. function forwardRejection(rejection) {
  745. return ZoneAwarePromise.reject(rejection);
  746. }
  747. var symbolState = __symbol__('state');
  748. var symbolValue = __symbol__('value');
  749. var symbolFinally = __symbol__('finally');
  750. var symbolParentPromiseValue = __symbol__('parentPromiseValue');
  751. var symbolParentPromiseState = __symbol__('parentPromiseState');
  752. var source = 'Promise.then';
  753. var UNRESOLVED = null;
  754. var RESOLVED = true;
  755. var REJECTED = false;
  756. var REJECTED_NO_CATCH = 0;
  757. function makeResolver(promise, state) {
  758. return function (v) {
  759. try {
  760. resolvePromise(promise, state, v);
  761. }
  762. catch (err) {
  763. resolvePromise(promise, false, err);
  764. }
  765. // Do not return value or you will break the Promise spec.
  766. };
  767. }
  768. var once = function () {
  769. var wasCalled = false;
  770. return function wrapper(wrappedFunction) {
  771. return function () {
  772. if (wasCalled) {
  773. return;
  774. }
  775. wasCalled = true;
  776. wrappedFunction.apply(null, arguments);
  777. };
  778. };
  779. };
  780. var TYPE_ERROR = 'Promise resolved with itself';
  781. var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace');
  782. // Promise Resolution
  783. function resolvePromise(promise, state, value) {
  784. var onceWrapper = once();
  785. if (promise === value) {
  786. throw new TypeError(TYPE_ERROR);
  787. }
  788. if (promise[symbolState] === UNRESOLVED) {
  789. // should only get value.then once based on promise spec.
  790. var then = null;
  791. try {
  792. if (typeof value === 'object' || typeof value === 'function') {
  793. then = value && value.then;
  794. }
  795. }
  796. catch (err) {
  797. onceWrapper(function () {
  798. resolvePromise(promise, false, err);
  799. })();
  800. return promise;
  801. }
  802. // if (value instanceof ZoneAwarePromise) {
  803. if (state !== REJECTED && value instanceof ZoneAwarePromise &&
  804. value.hasOwnProperty(symbolState) && value.hasOwnProperty(symbolValue) &&
  805. value[symbolState] !== UNRESOLVED) {
  806. clearRejectedNoCatch(value);
  807. resolvePromise(promise, value[symbolState], value[symbolValue]);
  808. }
  809. else if (state !== REJECTED && typeof then === 'function') {
  810. try {
  811. then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)));
  812. }
  813. catch (err) {
  814. onceWrapper(function () {
  815. resolvePromise(promise, false, err);
  816. })();
  817. }
  818. }
  819. else {
  820. promise[symbolState] = state;
  821. var queue = promise[symbolValue];
  822. promise[symbolValue] = value;
  823. if (promise[symbolFinally] === symbolFinally) {
  824. // the promise is generated by Promise.prototype.finally
  825. if (state === RESOLVED) {
  826. // the state is resolved, should ignore the value
  827. // and use parent promise value
  828. promise[symbolState] = promise[symbolParentPromiseState];
  829. promise[symbolValue] = promise[symbolParentPromiseValue];
  830. }
  831. }
  832. // record task information in value when error occurs, so we can
  833. // do some additional work such as render longStackTrace
  834. if (state === REJECTED && value instanceof Error) {
  835. // check if longStackTraceZone is here
  836. var trace = Zone.currentTask && Zone.currentTask.data &&
  837. Zone.currentTask.data[creationTrace];
  838. if (trace) {
  839. // only keep the long stack trace into error when in longStackTraceZone
  840. ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace });
  841. }
  842. }
  843. for (var i = 0; i < queue.length;) {
  844. scheduleResolveOrReject(promise, queue[i++], queue[i++], queue[i++], queue[i++]);
  845. }
  846. if (queue.length == 0 && state == REJECTED) {
  847. promise[symbolState] = REJECTED_NO_CATCH;
  848. try {
  849. // try to print more readable error log
  850. throw new Error('Uncaught (in promise): ' + readableObjectToString(value) +
  851. (value && value.stack ? '\n' + value.stack : ''));
  852. }
  853. catch (err) {
  854. var error_1 = err;
  855. error_1.rejection = value;
  856. error_1.promise = promise;
  857. error_1.zone = Zone.current;
  858. error_1.task = Zone.currentTask;
  859. _uncaughtPromiseErrors.push(error_1);
  860. api.scheduleMicroTask(); // to make sure that it is running
  861. }
  862. }
  863. }
  864. }
  865. // Resolving an already resolved promise is a noop.
  866. return promise;
  867. }
  868. var REJECTION_HANDLED_HANDLER = __symbol__('rejectionHandledHandler');
  869. function clearRejectedNoCatch(promise) {
  870. if (promise[symbolState] === REJECTED_NO_CATCH) {
  871. // if the promise is rejected no catch status
  872. // and queue.length > 0, means there is a error handler
  873. // here to handle the rejected promise, we should trigger
  874. // windows.rejectionhandled eventHandler or nodejs rejectionHandled
  875. // eventHandler
  876. try {
  877. var handler = Zone[REJECTION_HANDLED_HANDLER];
  878. if (handler && typeof handler === 'function') {
  879. handler.call(this, { rejection: promise[symbolValue], promise: promise });
  880. }
  881. }
  882. catch (err) {
  883. }
  884. promise[symbolState] = REJECTED;
  885. for (var i = 0; i < _uncaughtPromiseErrors.length; i++) {
  886. if (promise === _uncaughtPromiseErrors[i].promise) {
  887. _uncaughtPromiseErrors.splice(i, 1);
  888. }
  889. }
  890. }
  891. }
  892. function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) {
  893. clearRejectedNoCatch(promise);
  894. var promiseState = promise[symbolState];
  895. var delegate = promiseState ?
  896. (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution :
  897. (typeof onRejected === 'function') ? onRejected : forwardRejection;
  898. zone.scheduleMicroTask(source, function () {
  899. try {
  900. var parentPromiseValue = promise[symbolValue];
  901. var isFinallyPromise = chainPromise && symbolFinally === chainPromise[symbolFinally];
  902. if (isFinallyPromise) {
  903. // if the promise is generated from finally call, keep parent promise's state and value
  904. chainPromise[symbolParentPromiseValue] = parentPromiseValue;
  905. chainPromise[symbolParentPromiseState] = promiseState;
  906. }
  907. // should not pass value to finally callback
  908. var value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ?
  909. [] :
  910. [parentPromiseValue]);
  911. resolvePromise(chainPromise, true, value);
  912. }
  913. catch (error) {
  914. // if error occurs, should always return this error
  915. resolvePromise(chainPromise, false, error);
  916. }
  917. }, chainPromise);
  918. }
  919. var ZONE_AWARE_PROMISE_TO_STRING = 'function ZoneAwarePromise() { [native code] }';
  920. var ZoneAwarePromise = /** @class */ (function () {
  921. function ZoneAwarePromise(executor) {
  922. var promise = this;
  923. if (!(promise instanceof ZoneAwarePromise)) {
  924. throw new Error('Must be an instanceof Promise.');
  925. }
  926. promise[symbolState] = UNRESOLVED;
  927. promise[symbolValue] = []; // queue;
  928. try {
  929. executor && executor(makeResolver(promise, RESOLVED), makeResolver(promise, REJECTED));
  930. }
  931. catch (error) {
  932. resolvePromise(promise, false, error);
  933. }
  934. }
  935. ZoneAwarePromise.toString = function () {
  936. return ZONE_AWARE_PROMISE_TO_STRING;
  937. };
  938. ZoneAwarePromise.resolve = function (value) {
  939. return resolvePromise(new this(null), RESOLVED, value);
  940. };
  941. ZoneAwarePromise.reject = function (error) {
  942. return resolvePromise(new this(null), REJECTED, error);
  943. };
  944. ZoneAwarePromise.race = function (values) {
  945. var e_1, _a;
  946. var resolve;
  947. var reject;
  948. var promise = new this(function (res, rej) {
  949. resolve = res;
  950. reject = rej;
  951. });
  952. function onResolve(value) {
  953. resolve(value);
  954. }
  955. function onReject(error) {
  956. reject(error);
  957. }
  958. try {
  959. for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
  960. var value = values_1_1.value;
  961. if (!isThenable(value)) {
  962. value = this.resolve(value);
  963. }
  964. value.then(onResolve, onReject);
  965. }
  966. }
  967. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  968. finally {
  969. try {
  970. if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
  971. }
  972. finally { if (e_1) throw e_1.error; }
  973. }
  974. return promise;
  975. };
  976. ZoneAwarePromise.all = function (values) {
  977. var e_2, _a;
  978. var resolve;
  979. var reject;
  980. var promise = new this(function (res, rej) {
  981. resolve = res;
  982. reject = rej;
  983. });
  984. // Start at 2 to prevent prematurely resolving if .then is called immediately.
  985. var unresolvedCount = 2;
  986. var valueIndex = 0;
  987. var resolvedValues = [];
  988. var _loop_2 = function (value) {
  989. if (!isThenable(value)) {
  990. value = this_1.resolve(value);
  991. }
  992. var curValueIndex = valueIndex;
  993. value.then(function (value) {
  994. resolvedValues[curValueIndex] = value;
  995. unresolvedCount--;
  996. if (unresolvedCount === 0) {
  997. resolve(resolvedValues);
  998. }
  999. }, reject);
  1000. unresolvedCount++;
  1001. valueIndex++;
  1002. };
  1003. var this_1 = this;
  1004. try {
  1005. for (var values_2 = __values(values), values_2_1 = values_2.next(); !values_2_1.done; values_2_1 = values_2.next()) {
  1006. var value = values_2_1.value;
  1007. _loop_2(value);
  1008. }
  1009. }
  1010. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  1011. finally {
  1012. try {
  1013. if (values_2_1 && !values_2_1.done && (_a = values_2.return)) _a.call(values_2);
  1014. }
  1015. finally { if (e_2) throw e_2.error; }
  1016. }
  1017. // Make the unresolvedCount zero-based again.
  1018. unresolvedCount -= 2;
  1019. if (unresolvedCount === 0) {
  1020. resolve(resolvedValues);
  1021. }
  1022. return promise;
  1023. };
  1024. Object.defineProperty(ZoneAwarePromise.prototype, Symbol.toStringTag, {
  1025. get: function () {
  1026. return 'Promise';
  1027. },
  1028. enumerable: true,
  1029. configurable: true
  1030. });
  1031. ZoneAwarePromise.prototype.then = function (onFulfilled, onRejected) {
  1032. var chainPromise = new this.constructor(null);
  1033. var zone = Zone.current;
  1034. if (this[symbolState] == UNRESOLVED) {
  1035. this[symbolValue].push(zone, chainPromise, onFulfilled, onRejected);
  1036. }
  1037. else {
  1038. scheduleResolveOrReject(this, zone, chainPromise, onFulfilled, onRejected);
  1039. }
  1040. return chainPromise;
  1041. };
  1042. ZoneAwarePromise.prototype.catch = function (onRejected) {
  1043. return this.then(null, onRejected);
  1044. };
  1045. ZoneAwarePromise.prototype.finally = function (onFinally) {
  1046. var chainPromise = new this.constructor(null);
  1047. chainPromise[symbolFinally] = symbolFinally;
  1048. var zone = Zone.current;
  1049. if (this[symbolState] == UNRESOLVED) {
  1050. this[symbolValue].push(zone, chainPromise, onFinally, onFinally);
  1051. }
  1052. else {
  1053. scheduleResolveOrReject(this, zone, chainPromise, onFinally, onFinally);
  1054. }
  1055. return chainPromise;
  1056. };
  1057. return ZoneAwarePromise;
  1058. }());
  1059. // Protect against aggressive optimizers dropping seemingly unused properties.
  1060. // E.g. Closure Compiler in advanced mode.
  1061. ZoneAwarePromise['resolve'] = ZoneAwarePromise.resolve;
  1062. ZoneAwarePromise['reject'] = ZoneAwarePromise.reject;
  1063. ZoneAwarePromise['race'] = ZoneAwarePromise.race;
  1064. ZoneAwarePromise['all'] = ZoneAwarePromise.all;
  1065. var NativePromise = global[symbolPromise] = global['Promise'];
  1066. var ZONE_AWARE_PROMISE = Zone.__symbol__('ZoneAwarePromise');
  1067. var desc = ObjectGetOwnPropertyDescriptor(global, 'Promise');
  1068. if (!desc || desc.configurable) {
  1069. desc && delete desc.writable;
  1070. desc && delete desc.value;
  1071. if (!desc) {
  1072. desc = { configurable: true, enumerable: true };
  1073. }
  1074. desc.get = function () {
  1075. // if we already set ZoneAwarePromise, use patched one
  1076. // otherwise return native one.
  1077. return global[ZONE_AWARE_PROMISE] ? global[ZONE_AWARE_PROMISE] : global[symbolPromise];
  1078. };
  1079. desc.set = function (NewNativePromise) {
  1080. if (NewNativePromise === ZoneAwarePromise) {
  1081. // if the NewNativePromise is ZoneAwarePromise
  1082. // save to global
  1083. global[ZONE_AWARE_PROMISE] = NewNativePromise;
  1084. }
  1085. else {
  1086. // if the NewNativePromise is not ZoneAwarePromise
  1087. // for example: after load zone.js, some library just
  1088. // set es6-promise to global, if we set it to global
  1089. // directly, assertZonePatched will fail and angular
  1090. // will not loaded, so we just set the NewNativePromise
  1091. // to global[symbolPromise], so the result is just like
  1092. // we load ES6 Promise before zone.js
  1093. global[symbolPromise] = NewNativePromise;
  1094. if (!NewNativePromise.prototype[symbolThen]) {
  1095. patchThen(NewNativePromise);
  1096. }
  1097. api.setNativePromise(NewNativePromise);
  1098. }
  1099. };
  1100. ObjectDefineProperty(global, 'Promise', desc);
  1101. }
  1102. global['Promise'] = ZoneAwarePromise;
  1103. var symbolThenPatched = __symbol__('thenPatched');
  1104. function patchThen(Ctor) {
  1105. var proto = Ctor.prototype;
  1106. var prop = ObjectGetOwnPropertyDescriptor(proto, 'then');
  1107. if (prop && (prop.writable === false || !prop.configurable)) {
  1108. // check Ctor.prototype.then propertyDescriptor is writable or not
  1109. // in meteor env, writable is false, we should ignore such case
  1110. return;
  1111. }
  1112. var originalThen = proto.then;
  1113. // Keep a reference to the original method.
  1114. proto[symbolThen] = originalThen;
  1115. Ctor.prototype.then = function (onResolve, onReject) {
  1116. var _this = this;
  1117. var wrapped = new ZoneAwarePromise(function (resolve, reject) {
  1118. originalThen.call(_this, resolve, reject);
  1119. });
  1120. return wrapped.then(onResolve, onReject);
  1121. };
  1122. Ctor[symbolThenPatched] = true;
  1123. }
  1124. api.patchThen = patchThen;
  1125. function zoneify(fn) {
  1126. return function () {
  1127. var resultPromise = fn.apply(this, arguments);
  1128. if (resultPromise instanceof ZoneAwarePromise) {
  1129. return resultPromise;
  1130. }
  1131. var ctor = resultPromise.constructor;
  1132. if (!ctor[symbolThenPatched]) {
  1133. patchThen(ctor);
  1134. }
  1135. return resultPromise;
  1136. };
  1137. }
  1138. if (NativePromise) {
  1139. patchThen(NativePromise);
  1140. var fetch_1 = global['fetch'];
  1141. if (typeof fetch_1 == 'function') {
  1142. global[api.symbol('fetch')] = fetch_1;
  1143. global['fetch'] = zoneify(fetch_1);
  1144. }
  1145. }
  1146. // This is not part of public API, but it is useful for tests, so we expose it.
  1147. Promise[Zone.__symbol__('uncaughtPromiseErrors')] = _uncaughtPromiseErrors;
  1148. return ZoneAwarePromise;
  1149. });
  1150. /**
  1151. * @license
  1152. * Copyright Google Inc. All Rights Reserved.
  1153. *
  1154. * Use of this source code is governed by an MIT-style license that can be
  1155. * found in the LICENSE file at https://angular.io/license
  1156. */
  1157. /**
  1158. * Suppress closure compiler errors about unknown 'Zone' variable
  1159. * @fileoverview
  1160. * @suppress {undefinedVars,globalThis,missingRequire}
  1161. */
  1162. // issue #989, to reduce bundle size, use short name
  1163. /** Object.getOwnPropertyDescriptor */
  1164. var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  1165. /** Object.defineProperty */
  1166. var ObjectDefineProperty = Object.defineProperty;
  1167. /** Object.getPrototypeOf */
  1168. var ObjectGetPrototypeOf = Object.getPrototypeOf;
  1169. /** Object.create */
  1170. /** Array.prototype.slice */
  1171. var ArraySlice = Array.prototype.slice;
  1172. /** addEventListener string const */
  1173. var ADD_EVENT_LISTENER_STR = 'addEventListener';
  1174. /** removeEventListener string const */
  1175. var REMOVE_EVENT_LISTENER_STR = 'removeEventListener';
  1176. /** zoneSymbol addEventListener */
  1177. var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR);
  1178. /** zoneSymbol removeEventListener */
  1179. var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR);
  1180. /** true string const */
  1181. var TRUE_STR = 'true';
  1182. /** false string const */
  1183. var FALSE_STR = 'false';
  1184. /** __zone_symbol__ string const */
  1185. var ZONE_SYMBOL_PREFIX = '__zone_symbol__';
  1186. function wrapWithCurrentZone(callback, source) {
  1187. return Zone.current.wrap(callback, source);
  1188. }
  1189. function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) {
  1190. return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
  1191. }
  1192. var zoneSymbol = Zone.__symbol__;
  1193. var isWindowExists = typeof window !== 'undefined';
  1194. var internalWindow = isWindowExists ? window : undefined;
  1195. var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global;
  1196. var REMOVE_ATTRIBUTE = 'removeAttribute';
  1197. var NULL_ON_PROP_VALUE = [null];
  1198. function bindArguments(args, source) {
  1199. for (var i = args.length - 1; i >= 0; i--) {
  1200. if (typeof args[i] === 'function') {
  1201. args[i] = wrapWithCurrentZone(args[i], source + '_' + i);
  1202. }
  1203. }
  1204. return args;
  1205. }
  1206. function patchPrototype(prototype, fnNames) {
  1207. var source = prototype.constructor['name'];
  1208. var _loop_1 = function (i) {
  1209. var name_1 = fnNames[i];
  1210. var delegate = prototype[name_1];
  1211. if (delegate) {
  1212. var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, name_1);
  1213. if (!isPropertyWritable(prototypeDesc)) {
  1214. return "continue";
  1215. }
  1216. prototype[name_1] = (function (delegate) {
  1217. var patched = function () {
  1218. return delegate.apply(this, bindArguments(arguments, source + '.' + name_1));
  1219. };
  1220. attachOriginToPatched(patched, delegate);
  1221. return patched;
  1222. })(delegate);
  1223. }
  1224. };
  1225. for (var i = 0; i < fnNames.length; i++) {
  1226. _loop_1(i);
  1227. }
  1228. }
  1229. function isPropertyWritable(propertyDesc) {
  1230. if (!propertyDesc) {
  1231. return true;
  1232. }
  1233. if (propertyDesc.writable === false) {
  1234. return false;
  1235. }
  1236. return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined');
  1237. }
  1238. var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope);
  1239. // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
  1240. // this code.
  1241. var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' &&
  1242. {}.toString.call(_global.process) === '[object process]');
  1243. var isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']);
  1244. // we are in electron of nw, so we are both browser and nodejs
  1245. // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
  1246. // this code.
  1247. var isMix = typeof _global.process !== 'undefined' &&
  1248. {}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
  1249. !!(isWindowExists && internalWindow['HTMLElement']);
  1250. var zoneSymbolEventNames = {};
  1251. var wrapFn = function (event) {
  1252. // https://github.com/angular/zone.js/issues/911, in IE, sometimes
  1253. // event will be undefined, so we need to use window.event
  1254. event = event || _global.event;
  1255. if (!event) {
  1256. return;
  1257. }
  1258. var eventNameSymbol = zoneSymbolEventNames[event.type];
  1259. if (!eventNameSymbol) {
  1260. eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
  1261. }
  1262. var target = this || event.target || _global;
  1263. var listener = target[eventNameSymbol];
  1264. var result;
  1265. if (isBrowser && target === internalWindow && event.type === 'error') {
  1266. // window.onerror have different signiture
  1267. // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror#window.onerror
  1268. // and onerror callback will prevent default when callback return true
  1269. var errorEvent = event;
  1270. result = listener &&
  1271. listener.call(this, errorEvent.message, errorEvent.filename, errorEvent.lineno, errorEvent.colno, errorEvent.error);
  1272. if (result === true) {
  1273. event.preventDefault();
  1274. }
  1275. }
  1276. else {
  1277. result = listener && listener.apply(this, arguments);
  1278. if (result != undefined && !result) {
  1279. event.preventDefault();
  1280. }
  1281. }
  1282. return result;
  1283. };
  1284. function patchProperty(obj, prop, prototype) {
  1285. var desc = ObjectGetOwnPropertyDescriptor(obj, prop);
  1286. if (!desc && prototype) {
  1287. // when patch window object, use prototype to check prop exist or not
  1288. var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop);
  1289. if (prototypeDesc) {
  1290. desc = { enumerable: true, configurable: true };
  1291. }
  1292. }
  1293. // if the descriptor not exists or is not configurable
  1294. // just return
  1295. if (!desc || !desc.configurable) {
  1296. return;
  1297. }
  1298. var onPropPatchedSymbol = zoneSymbol('on' + prop + 'patched');
  1299. if (obj.hasOwnProperty(onPropPatchedSymbol) && obj[onPropPatchedSymbol]) {
  1300. return;
  1301. }
  1302. // A property descriptor cannot have getter/setter and be writable
  1303. // deleting the writable and value properties avoids this error:
  1304. //
  1305. // TypeError: property descriptors must not specify a value or be writable when a
  1306. // getter or setter has been specified
  1307. delete desc.writable;
  1308. delete desc.value;
  1309. var originalDescGet = desc.get;
  1310. var originalDescSet = desc.set;
  1311. // substr(2) cuz 'onclick' -> 'click', etc
  1312. var eventName = prop.substr(2);
  1313. var eventNameSymbol = zoneSymbolEventNames[eventName];
  1314. if (!eventNameSymbol) {
  1315. eventNameSymbol = zoneSymbolEventNames[eventName] = zoneSymbol('ON_PROPERTY' + eventName);
  1316. }
  1317. desc.set = function (newValue) {
  1318. // in some of windows's onproperty callback, this is undefined
  1319. // so we need to check it
  1320. var target = this;
  1321. if (!target && obj === _global) {
  1322. target = _global;
  1323. }
  1324. if (!target) {
  1325. return;
  1326. }
  1327. var previousValue = target[eventNameSymbol];
  1328. if (previousValue) {
  1329. target.removeEventListener(eventName, wrapFn);
  1330. }
  1331. // issue #978, when onload handler was added before loading zone.js
  1332. // we should remove it with originalDescSet
  1333. if (originalDescSet) {
  1334. originalDescSet.apply(target, NULL_ON_PROP_VALUE);
  1335. }
  1336. if (typeof newValue === 'function') {
  1337. target[eventNameSymbol] = newValue;
  1338. target.addEventListener(eventName, wrapFn, false);
  1339. }
  1340. else {
  1341. target[eventNameSymbol] = null;
  1342. }
  1343. };
  1344. // The getter would return undefined for unassigned properties but the default value of an
  1345. // unassigned property is null
  1346. desc.get = function () {
  1347. // in some of windows's onproperty callback, this is undefined
  1348. // so we need to check it
  1349. var target = this;
  1350. if (!target && obj === _global) {
  1351. target = _global;
  1352. }
  1353. if (!target) {
  1354. return null;
  1355. }
  1356. var listener = target[eventNameSymbol];
  1357. if (listener) {
  1358. return listener;
  1359. }
  1360. else if (originalDescGet) {
  1361. // result will be null when use inline event attribute,
  1362. // such as <button onclick="func();">OK</button>
  1363. // because the onclick function is internal raw uncompiled handler
  1364. // the onclick will be evaluated when first time event was triggered or
  1365. // the property is accessed, https://github.com/angular/zone.js/issues/525
  1366. // so we should use original native get to retrieve the handler
  1367. var value = originalDescGet && originalDescGet.call(this);
  1368. if (value) {
  1369. desc.set.call(this, value);
  1370. if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
  1371. target.removeAttribute(prop);
  1372. }
  1373. return value;
  1374. }
  1375. }
  1376. return null;
  1377. };
  1378. ObjectDefineProperty(obj, prop, desc);
  1379. obj[onPropPatchedSymbol] = true;
  1380. }
  1381. function patchOnProperties(obj, properties, prototype) {
  1382. if (properties) {
  1383. for (var i = 0; i < properties.length; i++) {
  1384. patchProperty(obj, 'on' + properties[i], prototype);
  1385. }
  1386. }
  1387. else {
  1388. var onProperties = [];
  1389. for (var prop in obj) {
  1390. if (prop.substr(0, 2) == 'on') {
  1391. onProperties.push(prop);
  1392. }
  1393. }
  1394. for (var j = 0; j < onProperties.length; j++) {
  1395. patchProperty(obj, onProperties[j], prototype);
  1396. }
  1397. }
  1398. }
  1399. var originalInstanceKey = zoneSymbol('originalInstance');
  1400. // wrap some native API on `window`
  1401. function patchClass(className) {
  1402. var OriginalClass = _global[className];
  1403. if (!OriginalClass)
  1404. return;
  1405. // keep original class in global
  1406. _global[zoneSymbol(className)] = OriginalClass;
  1407. _global[className] = function () {
  1408. var a = bindArguments(arguments, className);
  1409. switch (a.length) {
  1410. case 0:
  1411. this[originalInstanceKey] = new OriginalClass();
  1412. break;
  1413. case 1:
  1414. this[originalInstanceKey] = new OriginalClass(a[0]);
  1415. break;
  1416. case 2:
  1417. this[originalInstanceKey] = new OriginalClass(a[0], a[1]);
  1418. break;
  1419. case 3:
  1420. this[originalInstanceKey] = new OriginalClass(a[0], a[1], a[2]);
  1421. break;
  1422. case 4:
  1423. this[originalInstanceKey] = new OriginalClass(a[0], a[1], a[2], a[3]);
  1424. break;
  1425. default:
  1426. throw new Error('Arg list too long.');
  1427. }
  1428. };
  1429. // attach original delegate to patched function
  1430. attachOriginToPatched(_global[className], OriginalClass);
  1431. var instance = new OriginalClass(function () { });
  1432. var prop;
  1433. for (prop in instance) {
  1434. // https://bugs.webkit.org/show_bug.cgi?id=44721
  1435. if (className === 'XMLHttpRequest' && prop === 'responseBlob')
  1436. continue;
  1437. (function (prop) {
  1438. if (typeof instance[prop] === 'function') {
  1439. _global[className].prototype[prop] = function () {
  1440. return this[originalInstanceKey][prop].apply(this[originalInstanceKey], arguments);
  1441. };
  1442. }
  1443. else {
  1444. ObjectDefineProperty(_global[className].prototype, prop, {
  1445. set: function (fn) {
  1446. if (typeof fn === 'function') {
  1447. this[originalInstanceKey][prop] = wrapWithCurrentZone(fn, className + '.' + prop);
  1448. // keep callback in wrapped function so we can
  1449. // use it in Function.prototype.toString to return
  1450. // the native one.
  1451. attachOriginToPatched(this[originalInstanceKey][prop], fn);
  1452. }
  1453. else {
  1454. this[originalInstanceKey][prop] = fn;
  1455. }
  1456. },
  1457. get: function () {
  1458. return this[originalInstanceKey][prop];
  1459. }
  1460. });
  1461. }
  1462. }(prop));
  1463. }
  1464. for (prop in OriginalClass) {
  1465. if (prop !== 'prototype' && OriginalClass.hasOwnProperty(prop)) {
  1466. _global[className][prop] = OriginalClass[prop];
  1467. }
  1468. }
  1469. }
  1470. function copySymbolProperties(src, dest) {
  1471. if (typeof Object.getOwnPropertySymbols !== 'function') {
  1472. return;
  1473. }
  1474. var symbols = Object.getOwnPropertySymbols(src);
  1475. symbols.forEach(function (symbol) {
  1476. var desc = Object.getOwnPropertyDescriptor(src, symbol);
  1477. Object.defineProperty(dest, symbol, {
  1478. get: function () {
  1479. return src[symbol];
  1480. },
  1481. set: function (value) {
  1482. if (desc && (!desc.writable || typeof desc.set !== 'function')) {
  1483. // if src[symbol] is not writable or not have a setter, just return
  1484. return;
  1485. }
  1486. src[symbol] = value;
  1487. },
  1488. enumerable: desc ? desc.enumerable : true,
  1489. configurable: desc ? desc.configurable : true
  1490. });
  1491. });
  1492. }
  1493. var shouldCopySymbolProperties = false;
  1494. function setShouldCopySymbolProperties(flag) {
  1495. shouldCopySymbolProperties = flag;
  1496. }
  1497. function patchMethod(target, name, patchFn) {
  1498. var proto = target;
  1499. while (proto && !proto.hasOwnProperty(name)) {
  1500. proto = ObjectGetPrototypeOf(proto);
  1501. }
  1502. if (!proto && target[name]) {
  1503. // somehow we did not find it, but we can see it. This happens on IE for Window properties.
  1504. proto = target;
  1505. }
  1506. var delegateName = zoneSymbol(name);
  1507. var delegate = null;
  1508. if (proto && !(delegate = proto[delegateName])) {
  1509. delegate = proto[delegateName] = proto[name];
  1510. // check whether proto[name] is writable
  1511. // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
  1512. var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
  1513. if (isPropertyWritable(desc)) {
  1514. var patchDelegate_1 = patchFn(delegate, delegateName, name);
  1515. proto[name] = function () {
  1516. return patchDelegate_1(this, arguments);
  1517. };
  1518. attachOriginToPatched(proto[name], delegate);
  1519. if (shouldCopySymbolProperties) {
  1520. copySymbolProperties(delegate, proto[name]);
  1521. }
  1522. }
  1523. }
  1524. return delegate;
  1525. }
  1526. // TODO: @JiaLiPassion, support cancel task later if necessary
  1527. function patchMacroTask(obj, funcName, metaCreator) {
  1528. var setNative = null;
  1529. function scheduleTask(task) {
  1530. var data = task.data;
  1531. data.args[data.cbIdx] = function () {
  1532. task.invoke.apply(this, arguments);
  1533. };
  1534. setNative.apply(data.target, data.args);
  1535. return task;
  1536. }
  1537. setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
  1538. var meta = metaCreator(self, args);
  1539. if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
  1540. return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask);
  1541. }
  1542. else {
  1543. // cause an error by calling it directly.
  1544. return delegate.apply(self, args);
  1545. }
  1546. }; });
  1547. }
  1548. function patchMicroTask(obj, funcName, metaCreator) {
  1549. var setNative = null;
  1550. function scheduleTask(task) {
  1551. var data = task.data;
  1552. data.args[data.cbIdx] = function () {
  1553. task.invoke.apply(this, arguments);
  1554. };
  1555. setNative.apply(data.target, data.args);
  1556. return task;
  1557. }
  1558. setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
  1559. var meta = metaCreator(self, args);
  1560. if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
  1561. return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask);
  1562. }
  1563. else {
  1564. // cause an error by calling it directly.
  1565. return delegate.apply(self, args);
  1566. }
  1567. }; });
  1568. }
  1569. function attachOriginToPatched(patched, original) {
  1570. patched[zoneSymbol('OriginalDelegate')] = original;
  1571. }
  1572. function isIE() {
  1573. try {
  1574. var ua = internalWindow.navigator.userAgent;
  1575. if (ua.indexOf('MSIE ') !== -1 || ua.indexOf('Trident/') !== -1) {
  1576. return true;
  1577. }
  1578. }
  1579. catch (error) {
  1580. }
  1581. return false;
  1582. }
  1583. /**
  1584. * @license
  1585. * Copyright Google Inc. All Rights Reserved.
  1586. *
  1587. * Use of this source code is governed by an MIT-style license that can be
  1588. * found in the LICENSE file at https://angular.io/license
  1589. */
  1590. // override Function.prototype.toString to make zone.js patched function
  1591. // look like native function
  1592. Zone.__load_patch('toString', function (global) {
  1593. // patch Func.prototype.toString to let them look like native
  1594. var originalFunctionToString = Function.prototype.toString;
  1595. var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
  1596. var PROMISE_SYMBOL = zoneSymbol('Promise');
  1597. var ERROR_SYMBOL = zoneSymbol('Error');
  1598. var newFunctionToString = function toString() {
  1599. if (typeof this === 'function') {
  1600. var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
  1601. if (originalDelegate) {
  1602. if (typeof originalDelegate === 'function') {
  1603. return originalFunctionToString.call(originalDelegate);
  1604. }
  1605. else {
  1606. return Object.prototype.toString.call(originalDelegate);
  1607. }
  1608. }
  1609. if (this === Promise) {
  1610. var nativePromise = global[PROMISE_SYMBOL];
  1611. if (nativePromise) {
  1612. return originalFunctionToString.call(nativePromise);
  1613. }
  1614. }
  1615. if (this === Error) {
  1616. var nativeError = global[ERROR_SYMBOL];
  1617. if (nativeError) {
  1618. return originalFunctionToString.call(nativeError);
  1619. }
  1620. }
  1621. }
  1622. return originalFunctionToString.call(this);
  1623. };
  1624. newFunctionToString[ORIGINAL_DELEGATE_SYMBOL] = originalFunctionToString;
  1625. Function.prototype.toString = newFunctionToString;
  1626. // patch Object.prototype.toString to let them look like native
  1627. var originalObjectToString = Object.prototype.toString;
  1628. var PROMISE_OBJECT_TO_STRING = '[object Promise]';
  1629. Object.prototype.toString = function () {
  1630. if (this instanceof Promise) {
  1631. return PROMISE_OBJECT_TO_STRING;
  1632. }
  1633. return originalObjectToString.call(this);
  1634. };
  1635. });
  1636. /**
  1637. * @license
  1638. * Copyright Google Inc. All Rights Reserved.
  1639. *
  1640. * Use of this source code is governed by an MIT-style license that can be
  1641. * found in the LICENSE file at https://angular.io/license
  1642. */
  1643. /**
  1644. * @fileoverview
  1645. * @suppress {missingRequire}
  1646. */
  1647. var passiveSupported = false;
  1648. if (typeof window !== 'undefined') {
  1649. try {
  1650. var options = Object.defineProperty({}, 'passive', {
  1651. get: function () {
  1652. passiveSupported = true;
  1653. }
  1654. });
  1655. window.addEventListener('test', options, options);
  1656. window.removeEventListener('test', options, options);
  1657. }
  1658. catch (err) {
  1659. passiveSupported = false;
  1660. }
  1661. }
  1662. // an identifier to tell ZoneTask do not create a new invoke closure
  1663. var OPTIMIZED_ZONE_EVENT_TASK_DATA = {
  1664. useG: true
  1665. };
  1666. var zoneSymbolEventNames$1 = {};
  1667. var globalSources = {};
  1668. var EVENT_NAME_SYMBOL_REGX = /^__zone_symbol__(\w+)(true|false)$/;
  1669. var IMMEDIATE_PROPAGATION_SYMBOL = ('__zone_symbol__propagationStopped');
  1670. function patchEventTarget(_global, apis, patchOptions) {
  1671. var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR;
  1672. var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR;
  1673. var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners';
  1674. var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners';
  1675. var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER);
  1676. var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':';
  1677. var PREPEND_EVENT_LISTENER = 'prependListener';
  1678. var PREPEND_EVENT_LISTENER_SOURCE = '.' + PREPEND_EVENT_LISTENER + ':';
  1679. var invokeTask = function (task, target, event) {
  1680. // for better performance, check isRemoved which is set
  1681. // by removeEventListener
  1682. if (task.isRemoved) {
  1683. return;
  1684. }
  1685. var delegate = task.callback;
  1686. if (typeof delegate === 'object' && delegate.handleEvent) {
  1687. // create the bind version of handleEvent when invoke
  1688. task.callback = function (event) { return delegate.handleEvent(event); };
  1689. task.originalDelegate = delegate;
  1690. }
  1691. // invoke static task.invoke
  1692. task.invoke(task, target, [event]);
  1693. var options = task.options;
  1694. if (options && typeof options === 'object' && options.once) {
  1695. // if options.once is true, after invoke once remove listener here
  1696. // only browser need to do this, nodejs eventEmitter will cal removeListener
  1697. // inside EventEmitter.once
  1698. var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback;
  1699. target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options);
  1700. }
  1701. };
  1702. // global shared zoneAwareCallback to handle all event callback with capture = false
  1703. var globalZoneAwareCallback = function (event) {
  1704. // https://github.com/angular/zone.js/issues/911, in IE, sometimes
  1705. // event will be undefined, so we need to use window.event
  1706. event = event || _global.event;
  1707. if (!event) {
  1708. return;
  1709. }
  1710. // event.target is needed for Samsung TV and SourceBuffer
  1711. // || global is needed https://github.com/angular/zone.js/issues/190
  1712. var target = this || event.target || _global;
  1713. var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]];
  1714. if (tasks) {
  1715. // invoke all tasks which attached to current target with given event.type and capture = false
  1716. // for performance concern, if task.length === 1, just invoke
  1717. if (tasks.length === 1) {
  1718. invokeTask(tasks[0], target, event);
  1719. }
  1720. else {
  1721. // https://github.com/angular/zone.js/issues/836
  1722. // copy the tasks array before invoke, to avoid
  1723. // the callback will remove itself or other listener
  1724. var copyTasks = tasks.slice();
  1725. for (var i = 0; i < copyTasks.length; i++) {
  1726. if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
  1727. break;
  1728. }
  1729. invokeTask(copyTasks[i], target, event);
  1730. }
  1731. }
  1732. }
  1733. };
  1734. // global shared zoneAwareCallback to handle all event callback with capture = true
  1735. var globalZoneAwareCaptureCallback = function (event) {
  1736. // https://github.com/angular/zone.js/issues/911, in IE, sometimes
  1737. // event will be undefined, so we need to use window.event
  1738. event = event || _global.event;
  1739. if (!event) {
  1740. return;
  1741. }
  1742. // event.target is needed for Samsung TV and SourceBuffer
  1743. // || global is needed https://github.com/angular/zone.js/issues/190
  1744. var target = this || event.target || _global;
  1745. var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]];
  1746. if (tasks) {
  1747. // invoke all tasks which attached to current target with given event.type and capture = false
  1748. // for performance concern, if task.length === 1, just invoke
  1749. if (tasks.length === 1) {
  1750. invokeTask(tasks[0], target, event);
  1751. }
  1752. else {
  1753. // https://github.com/angular/zone.js/issues/836
  1754. // copy the tasks array before invoke, to avoid
  1755. // the callback will remove itself or other listener
  1756. var copyTasks = tasks.slice();
  1757. for (var i = 0; i < copyTasks.length; i++) {
  1758. if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
  1759. break;
  1760. }
  1761. invokeTask(copyTasks[i], target, event);
  1762. }
  1763. }
  1764. }
  1765. };
  1766. function patchEventTargetMethods(obj, patchOptions) {
  1767. if (!obj) {
  1768. return false;
  1769. }
  1770. var useGlobalCallback = true;
  1771. if (patchOptions && patchOptions.useG !== undefined) {
  1772. useGlobalCallback = patchOptions.useG;
  1773. }
  1774. var validateHandler = patchOptions && patchOptions.vh;
  1775. var checkDuplicate = true;
  1776. if (patchOptions && patchOptions.chkDup !== undefined) {
  1777. checkDuplicate = patchOptions.chkDup;
  1778. }
  1779. var returnTarget = false;
  1780. if (patchOptions && patchOptions.rt !== undefined) {
  1781. returnTarget = patchOptions.rt;
  1782. }
  1783. var proto = obj;
  1784. while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) {
  1785. proto = ObjectGetPrototypeOf(proto);
  1786. }
  1787. if (!proto && obj[ADD_EVENT_LISTENER]) {
  1788. // somehow we did not find it, but we can see it. This happens on IE for Window properties.
  1789. proto = obj;
  1790. }
  1791. if (!proto) {
  1792. return false;
  1793. }
  1794. if (proto[zoneSymbolAddEventListener]) {
  1795. return false;
  1796. }
  1797. var eventNameToString = patchOptions && patchOptions.eventNameToString;
  1798. // a shared global taskData to pass data for scheduleEventTask
  1799. // so we do not need to create a new object just for pass some data
  1800. var taskData = {};
  1801. var nativeAddEventListener = proto[zoneSymbolAddEventListener] = proto[ADD_EVENT_LISTENER];
  1802. var nativeRemoveEventListener = proto[zoneSymbol(REMOVE_EVENT_LISTENER)] =
  1803. proto[REMOVE_EVENT_LISTENER];
  1804. var nativeListeners = proto[zoneSymbol(LISTENERS_EVENT_LISTENER)] =
  1805. proto[LISTENERS_EVENT_LISTENER];
  1806. var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] =
  1807. proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER];
  1808. var nativePrependEventListener;
  1809. if (patchOptions && patchOptions.prepend) {
  1810. nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] =
  1811. proto[patchOptions.prepend];
  1812. }
  1813. function checkIsPassive(task) {
  1814. if (!passiveSupported && typeof taskData.options !== 'boolean' &&
  1815. typeof taskData.options !== 'undefined' && taskData.options !== null) {
  1816. // options is a non-null non-undefined object
  1817. // passive is not supported
  1818. // don't pass options as object
  1819. // just pass capture as a boolean
  1820. task.options = !!taskData.options.capture;
  1821. taskData.options = task.options;
  1822. }
  1823. }
  1824. var customScheduleGlobal = function (task) {
  1825. // if there is already a task for the eventName + capture,
  1826. // just return, because we use the shared globalZoneAwareCallback here.
  1827. if (taskData.isExisting) {
  1828. return;
  1829. }
  1830. checkIsPassive(task);
  1831. return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options);
  1832. };
  1833. var customCancelGlobal = function (task) {
  1834. // if task is not marked as isRemoved, this call is directly
  1835. // from Zone.prototype.cancelTask, we should remove the task
  1836. // from tasksList of target first
  1837. if (!task.isRemoved) {
  1838. var symbolEventNames = zoneSymbolEventNames$1[task.eventName];
  1839. var symbolEventName = void 0;
  1840. if (symbolEventNames) {
  1841. symbolEventName = symbolEventNames[task.capture ? TRUE_STR : FALSE_STR];
  1842. }
  1843. var existingTasks = symbolEventName && task.target[symbolEventName];
  1844. if (existingTasks) {
  1845. for (var i = 0; i < existingTasks.length; i++) {
  1846. var existingTask = existingTasks[i];
  1847. if (existingTask === task) {
  1848. existingTasks.splice(i, 1);
  1849. // set isRemoved to data for faster invokeTask check
  1850. task.isRemoved = true;
  1851. if (existingTasks.length === 0) {
  1852. // all tasks for the eventName + capture have gone,
  1853. // remove globalZoneAwareCallback and remove the task cache from target
  1854. task.allRemoved = true;
  1855. task.target[symbolEventName] = null;
  1856. }
  1857. break;
  1858. }
  1859. }
  1860. }
  1861. }
  1862. // if all tasks for the eventName + capture have gone,
  1863. // we will really remove the global event callback,
  1864. // if not, return
  1865. if (!task.allRemoved) {
  1866. return;
  1867. }
  1868. return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options);
  1869. };
  1870. var customScheduleNonGlobal = function (task) {
  1871. checkIsPassive(task);
  1872. return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
  1873. };
  1874. var customSchedulePrepend = function (task) {
  1875. return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
  1876. };
  1877. var customCancelNonGlobal = function (task) {
  1878. return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options);
  1879. };
  1880. var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal;
  1881. var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal;
  1882. var compareTaskCallbackVsDelegate = function (task, delegate) {
  1883. var typeOfDelegate = typeof delegate;
  1884. return (typeOfDelegate === 'function' && task.callback === delegate) ||
  1885. (typeOfDelegate === 'object' && task.originalDelegate === delegate);
  1886. };
  1887. var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate;
  1888. var blackListedEvents = Zone[Zone.__symbol__('BLACK_LISTED_EVENTS')];
  1889. var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) {
  1890. if (returnTarget === void 0) { returnTarget = false; }
  1891. if (prepend === void 0) { prepend = false; }
  1892. return function () {
  1893. var target = this || _global;
  1894. var eventName = arguments[0];
  1895. var delegate = arguments[1];
  1896. if (!delegate) {
  1897. return nativeListener.apply(this, arguments);
  1898. }
  1899. if (isNode && eventName === 'uncaughtException') {
  1900. // don't patch uncaughtException of nodejs to prevent endless loop
  1901. return nativeListener.apply(this, arguments);
  1902. }
  1903. // don't create the bind delegate function for handleEvent
  1904. // case here to improve addEventListener performance
  1905. // we will create the bind delegate when invoke
  1906. var isHandleEvent = false;
  1907. if (typeof delegate !== 'function') {
  1908. if (!delegate.handleEvent) {
  1909. return nativeListener.apply(this, arguments);
  1910. }
  1911. isHandleEvent = true;
  1912. }
  1913. if (validateHandler && !validateHandler(nativeListener, delegate, target, arguments)) {
  1914. return;
  1915. }
  1916. var options = arguments[2];
  1917. if (blackListedEvents) {
  1918. // check black list
  1919. for (var i = 0; i < blackListedEvents.length; i++) {
  1920. if (eventName === blackListedEvents[i]) {
  1921. return nativeListener.apply(this, arguments);
  1922. }
  1923. }
  1924. }
  1925. var capture;
  1926. var once = false;
  1927. if (options === undefined) {
  1928. capture = false;
  1929. }
  1930. else if (options === true) {
  1931. capture = true;
  1932. }
  1933. else if (options === false) {
  1934. capture = false;
  1935. }
  1936. else {
  1937. capture = options ? !!options.capture : false;
  1938. once = options ? !!options.once : false;
  1939. }
  1940. var zone = Zone.current;
  1941. var symbolEventNames = zoneSymbolEventNames$1[eventName];
  1942. var symbolEventName;
  1943. if (!symbolEventNames) {
  1944. // the code is duplicate, but I just want to get some better performance
  1945. var falseEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + FALSE_STR;
  1946. var trueEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + TRUE_STR;
  1947. var symbol = ZONE_SYMBOL_PREFIX + falseEventName;
  1948. var symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
  1949. zoneSymbolEventNames$1[eventName] = {};
  1950. zoneSymbolEventNames$1[eventName][FALSE_STR] = symbol;
  1951. zoneSymbolEventNames$1[eventName][TRUE_STR] = symbolCapture;
  1952. symbolEventName = capture ? symbolCapture : symbol;
  1953. }
  1954. else {
  1955. symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
  1956. }
  1957. var existingTasks = target[symbolEventName];
  1958. var isExisting = false;
  1959. if (existingTasks) {
  1960. // already have task registered
  1961. isExisting = true;
  1962. if (checkDuplicate) {
  1963. for (var i = 0; i < existingTasks.length; i++) {
  1964. if (compare(existingTasks[i], delegate)) {
  1965. // same callback, same capture, same event name, just return
  1966. return;
  1967. }
  1968. }
  1969. }
  1970. }
  1971. else {
  1972. existingTasks = target[symbolEventName] = [];
  1973. }
  1974. var source;
  1975. var constructorName = target.constructor['name'];
  1976. var targetSource = globalSources[constructorName];
  1977. if (targetSource) {
  1978. source = targetSource[eventName];
  1979. }
  1980. if (!source) {
  1981. source = constructorName + addSource +
  1982. (eventNameToString ? eventNameToString(eventName) : eventName);
  1983. }
  1984. // do not create a new object as task.data to pass those things
  1985. // just use the global shared one
  1986. taskData.options = options;
  1987. if (once) {
  1988. // if addEventListener with once options, we don't pass it to
  1989. // native addEventListener, instead we keep the once setting
  1990. // and handle ourselves.
  1991. taskData.options.once = false;
  1992. }
  1993. taskData.target = target;
  1994. taskData.capture = capture;
  1995. taskData.eventName = eventName;
  1996. taskData.isExisting = isExisting;
  1997. var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : undefined;
  1998. // keep taskData into data to allow onScheduleEventTask to access the task information
  1999. if (data) {
  2000. data.taskData = taskData;
  2001. }
  2002. var task = zone.scheduleEventTask(source, delegate, data, customScheduleFn, customCancelFn);
  2003. // should clear taskData.target to avoid memory leak
  2004. // issue, https://github.com/angular/angular/issues/20442
  2005. taskData.target = null;
  2006. // need to clear up taskData because it is a global object
  2007. if (data) {
  2008. data.taskData = null;
  2009. }
  2010. // have to save those information to task in case
  2011. // application may call task.zone.cancelTask() directly
  2012. if (once) {
  2013. options.once = true;
  2014. }
  2015. if (!(!passiveSupported && typeof task.options === 'boolean')) {
  2016. // if not support passive, and we pass an option object
  2017. // to addEventListener, we should save the options to task
  2018. task.options = options;
  2019. }
  2020. task.target = target;
  2021. task.capture = capture;
  2022. task.eventName = eventName;
  2023. if (isHandleEvent) {
  2024. // save original delegate for compare to check duplicate
  2025. task.originalDelegate = delegate;
  2026. }
  2027. if (!prepend) {
  2028. existingTasks.push(task);
  2029. }
  2030. else {
  2031. existingTasks.unshift(task);
  2032. }
  2033. if (returnTarget) {
  2034. return target;
  2035. }
  2036. };
  2037. };
  2038. proto[ADD_EVENT_LISTENER] = makeAddListener(nativeAddEventListener, ADD_EVENT_LISTENER_SOURCE, customSchedule, customCancel, returnTarget);
  2039. if (nativePrependEventListener) {
  2040. proto[PREPEND_EVENT_LISTENER] = makeAddListener(nativePrependEventListener, PREPEND_EVENT_LISTENER_SOURCE, customSchedulePrepend, customCancel, returnTarget, true);
  2041. }
  2042. proto[REMOVE_EVENT_LISTENER] = function () {
  2043. var target = this || _global;
  2044. var eventName = arguments[0];
  2045. var options = arguments[2];
  2046. var capture;
  2047. if (options === undefined) {
  2048. capture = false;
  2049. }
  2050. else if (options === true) {
  2051. capture = true;
  2052. }
  2053. else if (options === false) {
  2054. capture = false;
  2055. }
  2056. else {
  2057. capture = options ? !!options.capture : false;
  2058. }
  2059. var delegate = arguments[1];
  2060. if (!delegate) {
  2061. return nativeRemoveEventListener.apply(this, arguments);
  2062. }
  2063. if (validateHandler &&
  2064. !validateHandler(nativeRemoveEventListener, delegate, target, arguments)) {
  2065. return;
  2066. }
  2067. var symbolEventNames = zoneSymbolEventNames$1[eventName];
  2068. var symbolEventName;
  2069. if (symbolEventNames) {
  2070. symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
  2071. }
  2072. var existingTasks = symbolEventName && target[symbolEventName];
  2073. if (existingTasks) {
  2074. for (var i = 0; i < existingTasks.length; i++) {
  2075. var existingTask = existingTasks[i];
  2076. if (compare(existingTask, delegate)) {
  2077. existingTasks.splice(i, 1);
  2078. // set isRemoved to data for faster invokeTask check
  2079. existingTask.isRemoved = true;
  2080. if (existingTasks.length === 0) {
  2081. // all tasks for the eventName + capture have gone,
  2082. // remove globalZoneAwareCallback and remove the task cache from target
  2083. existingTask.allRemoved = true;
  2084. target[symbolEventName] = null;
  2085. }
  2086. existingTask.zone.cancelTask(existingTask);
  2087. if (returnTarget) {
  2088. return target;
  2089. }
  2090. return;
  2091. }
  2092. }
  2093. }
  2094. // issue 930, didn't find the event name or callback
  2095. // from zone kept existingTasks, the callback maybe
  2096. // added outside of zone, we need to call native removeEventListener
  2097. // to try to remove it.
  2098. return nativeRemoveEventListener.apply(this, arguments);
  2099. };
  2100. proto[LISTENERS_EVENT_LISTENER] = function () {
  2101. var target = this || _global;
  2102. var eventName = arguments[0];
  2103. var listeners = [];
  2104. var tasks = findEventTasks(target, eventNameToString ? eventNameToString(eventName) : eventName);
  2105. for (var i = 0; i < tasks.length; i++) {
  2106. var task = tasks[i];
  2107. var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
  2108. listeners.push(delegate);
  2109. }
  2110. return listeners;
  2111. };
  2112. proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER] = function () {
  2113. var target = this || _global;
  2114. var eventName = arguments[0];
  2115. if (!eventName) {
  2116. var keys = Object.keys(target);
  2117. for (var i = 0; i < keys.length; i++) {
  2118. var prop = keys[i];
  2119. var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
  2120. var evtName = match && match[1];
  2121. // in nodejs EventEmitter, removeListener event is
  2122. // used for monitoring the removeListener call,
  2123. // so just keep removeListener eventListener until
  2124. // all other eventListeners are removed
  2125. if (evtName && evtName !== 'removeListener') {
  2126. this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName);
  2127. }
  2128. }
  2129. // remove removeListener listener finally
  2130. this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener');
  2131. }
  2132. else {
  2133. var symbolEventNames = zoneSymbolEventNames$1[eventName];
  2134. if (symbolEventNames) {
  2135. var symbolEventName = symbolEventNames[FALSE_STR];
  2136. var symbolCaptureEventName = symbolEventNames[TRUE_STR];
  2137. var tasks = target[symbolEventName];
  2138. var captureTasks = target[symbolCaptureEventName];
  2139. if (tasks) {
  2140. var removeTasks = tasks.slice();
  2141. for (var i = 0; i < removeTasks.length; i++) {
  2142. var task = removeTasks[i];
  2143. var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
  2144. this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
  2145. }
  2146. }
  2147. if (captureTasks) {
  2148. var removeTasks = captureTasks.slice();
  2149. for (var i = 0; i < removeTasks.length; i++) {
  2150. var task = removeTasks[i];
  2151. var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
  2152. this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
  2153. }
  2154. }
  2155. }
  2156. }
  2157. if (returnTarget) {
  2158. return this;
  2159. }
  2160. };
  2161. // for native toString patch
  2162. attachOriginToPatched(proto[ADD_EVENT_LISTENER], nativeAddEventListener);
  2163. attachOriginToPatched(proto[REMOVE_EVENT_LISTENER], nativeRemoveEventListener);
  2164. if (nativeRemoveAllListeners) {
  2165. attachOriginToPatched(proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER], nativeRemoveAllListeners);
  2166. }
  2167. if (nativeListeners) {
  2168. attachOriginToPatched(proto[LISTENERS_EVENT_LISTENER], nativeListeners);
  2169. }
  2170. return true;
  2171. }
  2172. var results = [];
  2173. for (var i = 0; i < apis.length; i++) {
  2174. results[i] = patchEventTargetMethods(apis[i], patchOptions);
  2175. }
  2176. return results;
  2177. }
  2178. function findEventTasks(target, eventName) {
  2179. var foundTasks = [];
  2180. for (var prop in target) {
  2181. var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
  2182. var evtName = match && match[1];
  2183. if (evtName && (!eventName || evtName === eventName)) {
  2184. var tasks = target[prop];
  2185. if (tasks) {
  2186. for (var i = 0; i < tasks.length; i++) {
  2187. foundTasks.push(tasks[i]);
  2188. }
  2189. }
  2190. }
  2191. }
  2192. return foundTasks;
  2193. }
  2194. /**
  2195. * @license
  2196. * Copyright Google Inc. All Rights Reserved.
  2197. *
  2198. * Use of this source code is governed by an MIT-style license that can be
  2199. * found in the LICENSE file at https://angular.io/license
  2200. */
  2201. /**
  2202. * @fileoverview
  2203. * @suppress {missingRequire}
  2204. */
  2205. var taskSymbol = zoneSymbol('zoneTask');
  2206. function patchTimer(window, setName, cancelName, nameSuffix) {
  2207. var setNative = null;
  2208. var clearNative = null;
  2209. setName += nameSuffix;
  2210. cancelName += nameSuffix;
  2211. var tasksByHandleId = {};
  2212. function scheduleTask(task) {
  2213. var data = task.data;
  2214. function timer() {
  2215. try {
  2216. task.invoke.apply(this, arguments);
  2217. }
  2218. finally {
  2219. // issue-934, task will be cancelled
  2220. // even it is a periodic task such as
  2221. // setInterval
  2222. if (!(task.data && task.data.isPeriodic)) {
  2223. if (typeof data.handleId === 'number') {
  2224. // in non-nodejs env, we remove timerId
  2225. // from local cache
  2226. delete tasksByHandleId[data.handleId];
  2227. }
  2228. else if (data.handleId) {
  2229. // Node returns complex objects as handleIds
  2230. // we remove task reference from timer object
  2231. data.handleId[taskSymbol] = null;
  2232. }
  2233. }
  2234. }
  2235. }
  2236. data.args[0] = timer;
  2237. data.handleId = setNative.apply(window, data.args);
  2238. return task;
  2239. }
  2240. function clearTask(task) {
  2241. return clearNative(task.data.handleId);
  2242. }
  2243. setNative =
  2244. patchMethod(window, setName, function (delegate) { return function (self, args) {
  2245. if (typeof args[0] === 'function') {
  2246. var options = {
  2247. isPeriodic: nameSuffix === 'Interval',
  2248. delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 :
  2249. undefined,
  2250. args: args
  2251. };
  2252. var task = scheduleMacroTaskWithCurrentZone(setName, args[0], options, scheduleTask, clearTask);
  2253. if (!task) {
  2254. return task;
  2255. }
  2256. // Node.js must additionally support the ref and unref functions.
  2257. var handle = task.data.handleId;
  2258. if (typeof handle === 'number') {
  2259. // for non nodejs env, we save handleId: task
  2260. // mapping in local cache for clearTimeout
  2261. tasksByHandleId[handle] = task;
  2262. }
  2263. else if (handle) {
  2264. // for nodejs env, we save task
  2265. // reference in timerId Object for clearTimeout
  2266. handle[taskSymbol] = task;
  2267. }
  2268. // check whether handle is null, because some polyfill or browser
  2269. // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame
  2270. if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' &&
  2271. typeof handle.unref === 'function') {
  2272. task.ref = handle.ref.bind(handle);
  2273. task.unref = handle.unref.bind(handle);
  2274. }
  2275. if (typeof handle === 'number' || handle) {
  2276. return handle;
  2277. }
  2278. return task;
  2279. }
  2280. else {
  2281. // cause an error by calling it directly.
  2282. return delegate.apply(window, args);
  2283. }
  2284. }; });
  2285. clearNative =
  2286. patchMethod(window, cancelName, function (delegate) { return function (self, args) {
  2287. var id = args[0];
  2288. var task;
  2289. if (typeof id === 'number') {
  2290. // non nodejs env.
  2291. task = tasksByHandleId[id];
  2292. }
  2293. else {
  2294. // nodejs env.
  2295. task = id && id[taskSymbol];
  2296. // other environments.
  2297. if (!task) {
  2298. task = id;
  2299. }
  2300. }
  2301. if (task && typeof task.type === 'string') {
  2302. if (task.state !== 'notScheduled' &&
  2303. (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
  2304. if (typeof id === 'number') {
  2305. delete tasksByHandleId[id];
  2306. }
  2307. else if (id) {
  2308. id[taskSymbol] = null;
  2309. }
  2310. // Do not cancel already canceled functions
  2311. task.zone.cancelTask(task);
  2312. }
  2313. }
  2314. else {
  2315. // cause an error by calling it directly.
  2316. delegate.apply(window, args);
  2317. }
  2318. }; });
  2319. }
  2320. /**
  2321. * @license
  2322. * Copyright Google Inc. All Rights Reserved.
  2323. *
  2324. * Use of this source code is governed by an MIT-style license that can be
  2325. * found in the LICENSE file at https://angular.io/license
  2326. */
  2327. function patchCustomElements(_global, api) {
  2328. var _a = api.getGlobalObjects(), isBrowser = _a.isBrowser, isMix = _a.isMix;
  2329. if ((!isBrowser && !isMix) || !_global['customElements'] || !('customElements' in _global)) {
  2330. return;
  2331. }
  2332. var callbacks = ['connectedCallback', 'disconnectedCallback', 'adoptedCallback', 'attributeChangedCallback'];
  2333. api.patchCallbacks(api, _global.customElements, 'customElements', 'define', callbacks);
  2334. }
  2335. /**
  2336. * @license
  2337. * Copyright Google Inc. All Rights Reserved.
  2338. *
  2339. * Use of this source code is governed by an MIT-style license that can be
  2340. * found in the LICENSE file at https://angular.io/license
  2341. */
  2342. /*
  2343. * This is necessary for Chrome and Chrome mobile, to enable
  2344. * things like redefining `createdCallback` on an element.
  2345. */
  2346. var zoneSymbol$1 = Zone.__symbol__;
  2347. var _defineProperty = Object[zoneSymbol$1('defineProperty')] = Object.defineProperty;
  2348. var _getOwnPropertyDescriptor = Object[zoneSymbol$1('getOwnPropertyDescriptor')] =
  2349. Object.getOwnPropertyDescriptor;
  2350. var _create = Object.create;
  2351. var unconfigurablesKey = zoneSymbol$1('unconfigurables');
  2352. function propertyPatch() {
  2353. Object.defineProperty = function (obj, prop, desc) {
  2354. if (isUnconfigurable(obj, prop)) {
  2355. throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj);
  2356. }
  2357. var originalConfigurableFlag = desc.configurable;
  2358. if (prop !== 'prototype') {
  2359. desc = rewriteDescriptor(obj, prop, desc);
  2360. }
  2361. return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag);
  2362. };
  2363. Object.defineProperties = function (obj, props) {
  2364. Object.keys(props).forEach(function (prop) {
  2365. Object.defineProperty(obj, prop, props[prop]);
  2366. });
  2367. return obj;
  2368. };
  2369. Object.create = function (obj, proto) {
  2370. if (typeof proto === 'object' && !Object.isFrozen(proto)) {
  2371. Object.keys(proto).forEach(function (prop) {
  2372. proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
  2373. });
  2374. }
  2375. return _create(obj, proto);
  2376. };
  2377. Object.getOwnPropertyDescriptor = function (obj, prop) {
  2378. var desc = _getOwnPropertyDescriptor(obj, prop);
  2379. if (desc && isUnconfigurable(obj, prop)) {
  2380. desc.configurable = false;
  2381. }
  2382. return desc;
  2383. };
  2384. }
  2385. function isUnconfigurable(obj, prop) {
  2386. return obj && obj[unconfigurablesKey] && obj[unconfigurablesKey][prop];
  2387. }
  2388. function rewriteDescriptor(obj, prop, desc) {
  2389. // issue-927, if the desc is frozen, don't try to change the desc
  2390. if (!Object.isFrozen(desc)) {
  2391. desc.configurable = true;
  2392. }
  2393. if (!desc.configurable) {
  2394. // issue-927, if the obj is frozen, don't try to set the desc to obj
  2395. if (!obj[unconfigurablesKey] && !Object.isFrozen(obj)) {
  2396. _defineProperty(obj, unconfigurablesKey, { writable: true, value: {} });
  2397. }
  2398. if (obj[unconfigurablesKey]) {
  2399. obj[unconfigurablesKey][prop] = true;
  2400. }
  2401. }
  2402. return desc;
  2403. }
  2404. function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) {
  2405. try {
  2406. return _defineProperty(obj, prop, desc);
  2407. }
  2408. catch (error) {
  2409. if (desc.configurable) {
  2410. // In case of errors, when the configurable flag was likely set by rewriteDescriptor(), let's
  2411. // retry with the original flag value
  2412. if (typeof originalConfigurableFlag == 'undefined') {
  2413. delete desc.configurable;
  2414. }
  2415. else {
  2416. desc.configurable = originalConfigurableFlag;
  2417. }
  2418. try {
  2419. return _defineProperty(obj, prop, desc);
  2420. }
  2421. catch (error) {
  2422. var descJson = null;
  2423. try {
  2424. descJson = JSON.stringify(desc);
  2425. }
  2426. catch (error) {
  2427. descJson = desc.toString();
  2428. }
  2429. console.log("Attempting to configure '" + prop + "' with descriptor '" + descJson + "' on object '" + obj + "' and got error, giving up: " + error);
  2430. }
  2431. }
  2432. else {
  2433. throw error;
  2434. }
  2435. }
  2436. }
  2437. /**
  2438. * @license
  2439. * Copyright Google Inc. All Rights Reserved.
  2440. *
  2441. * Use of this source code is governed by an MIT-style license that can be
  2442. * found in the LICENSE file at https://angular.io/license
  2443. */
  2444. function eventTargetPatch(_global, api) {
  2445. if (Zone[api.symbol('patchEventTarget')]) {
  2446. // EventTarget is already patched.
  2447. return;
  2448. }
  2449. var _a = api.getGlobalObjects(), eventNames = _a.eventNames, zoneSymbolEventNames = _a.zoneSymbolEventNames, TRUE_STR = _a.TRUE_STR, FALSE_STR = _a.FALSE_STR, ZONE_SYMBOL_PREFIX = _a.ZONE_SYMBOL_PREFIX;
  2450. // predefine all __zone_symbol__ + eventName + true/false string
  2451. for (var i = 0; i < eventNames.length; i++) {
  2452. var eventName = eventNames[i];
  2453. var falseEventName = eventName + FALSE_STR;
  2454. var trueEventName = eventName + TRUE_STR;
  2455. var symbol = ZONE_SYMBOL_PREFIX + falseEventName;
  2456. var symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
  2457. zoneSymbolEventNames[eventName] = {};
  2458. zoneSymbolEventNames[eventName][FALSE_STR] = symbol;
  2459. zoneSymbolEventNames[eventName][TRUE_STR] = symbolCapture;
  2460. }
  2461. var EVENT_TARGET = _global['EventTarget'];
  2462. if (!EVENT_TARGET || !EVENT_TARGET.prototype) {
  2463. return;
  2464. }
  2465. api.patchEventTarget(_global, [EVENT_TARGET && EVENT_TARGET.prototype]);
  2466. return true;
  2467. }
  2468. function patchEvent(global, api) {
  2469. api.patchEventPrototype(global, api);
  2470. }
  2471. /**
  2472. * @license
  2473. * Copyright Google Inc. All Rights Reserved.
  2474. *
  2475. * Use of this source code is governed by an MIT-style license that can be
  2476. * found in the LICENSE file at https://angular.io/license
  2477. */
  2478. /**
  2479. * @fileoverview
  2480. * @suppress {globalThis}
  2481. */
  2482. var globalEventHandlersEventNames = [
  2483. 'abort',
  2484. 'animationcancel',
  2485. 'animationend',
  2486. 'animationiteration',
  2487. 'auxclick',
  2488. 'beforeinput',
  2489. 'blur',
  2490. 'cancel',
  2491. 'canplay',
  2492. 'canplaythrough',
  2493. 'change',
  2494. 'compositionstart',
  2495. 'compositionupdate',
  2496. 'compositionend',
  2497. 'cuechange',
  2498. 'click',
  2499. 'close',
  2500. 'contextmenu',
  2501. 'curechange',
  2502. 'dblclick',
  2503. 'drag',
  2504. 'dragend',
  2505. 'dragenter',
  2506. 'dragexit',
  2507. 'dragleave',
  2508. 'dragover',
  2509. 'drop',
  2510. 'durationchange',
  2511. 'emptied',
  2512. 'ended',
  2513. 'error',
  2514. 'focus',
  2515. 'focusin',
  2516. 'focusout',
  2517. 'gotpointercapture',
  2518. 'input',
  2519. 'invalid',
  2520. 'keydown',
  2521. 'keypress',
  2522. 'keyup',
  2523. 'load',
  2524. 'loadstart',
  2525. 'loadeddata',
  2526. 'loadedmetadata',
  2527. 'lostpointercapture',
  2528. 'mousedown',
  2529. 'mouseenter',
  2530. 'mouseleave',
  2531. 'mousemove',
  2532. 'mouseout',
  2533. 'mouseover',
  2534. 'mouseup',
  2535. 'mousewheel',
  2536. 'orientationchange',
  2537. 'pause',
  2538. 'play',
  2539. 'playing',
  2540. 'pointercancel',
  2541. 'pointerdown',
  2542. 'pointerenter',
  2543. 'pointerleave',
  2544. 'pointerlockchange',
  2545. 'mozpointerlockchange',
  2546. 'webkitpointerlockerchange',
  2547. 'pointerlockerror',
  2548. 'mozpointerlockerror',
  2549. 'webkitpointerlockerror',
  2550. 'pointermove',
  2551. 'pointout',
  2552. 'pointerover',
  2553. 'pointerup',
  2554. 'progress',
  2555. 'ratechange',
  2556. 'reset',
  2557. 'resize',
  2558. 'scroll',
  2559. 'seeked',
  2560. 'seeking',
  2561. 'select',
  2562. 'selectionchange',
  2563. 'selectstart',
  2564. 'show',
  2565. 'sort',
  2566. 'stalled',
  2567. 'submit',
  2568. 'suspend',
  2569. 'timeupdate',
  2570. 'volumechange',
  2571. 'touchcancel',
  2572. 'touchmove',
  2573. 'touchstart',
  2574. 'touchend',
  2575. 'transitioncancel',
  2576. 'transitionend',
  2577. 'waiting',
  2578. 'wheel'
  2579. ];
  2580. var documentEventNames = [
  2581. 'afterscriptexecute', 'beforescriptexecute', 'DOMContentLoaded', 'freeze', 'fullscreenchange',
  2582. 'mozfullscreenchange', 'webkitfullscreenchange', 'msfullscreenchange', 'fullscreenerror',
  2583. 'mozfullscreenerror', 'webkitfullscreenerror', 'msfullscreenerror', 'readystatechange',
  2584. 'visibilitychange', 'resume'
  2585. ];
  2586. var windowEventNames = [
  2587. 'absolutedeviceorientation',
  2588. 'afterinput',
  2589. 'afterprint',
  2590. 'appinstalled',
  2591. 'beforeinstallprompt',
  2592. 'beforeprint',
  2593. 'beforeunload',
  2594. 'devicelight',
  2595. 'devicemotion',
  2596. 'deviceorientation',
  2597. 'deviceorientationabsolute',
  2598. 'deviceproximity',
  2599. 'hashchange',
  2600. 'languagechange',
  2601. 'message',
  2602. 'mozbeforepaint',
  2603. 'offline',
  2604. 'online',
  2605. 'paint',
  2606. 'pageshow',
  2607. 'pagehide',
  2608. 'popstate',
  2609. 'rejectionhandled',
  2610. 'storage',
  2611. 'unhandledrejection',
  2612. 'unload',
  2613. 'userproximity',
  2614. 'vrdisplyconnected',
  2615. 'vrdisplaydisconnected',
  2616. 'vrdisplaypresentchange'
  2617. ];
  2618. var htmlElementEventNames = [
  2619. 'beforecopy', 'beforecut', 'beforepaste', 'copy', 'cut', 'paste', 'dragstart', 'loadend',
  2620. 'animationstart', 'search', 'transitionrun', 'transitionstart', 'webkitanimationend',
  2621. 'webkitanimationiteration', 'webkitanimationstart', 'webkittransitionend'
  2622. ];
  2623. var mediaElementEventNames = ['encrypted', 'waitingforkey', 'msneedkey', 'mozinterruptbegin', 'mozinterruptend'];
  2624. var ieElementEventNames = [
  2625. 'activate',
  2626. 'afterupdate',
  2627. 'ariarequest',
  2628. 'beforeactivate',
  2629. 'beforedeactivate',
  2630. 'beforeeditfocus',
  2631. 'beforeupdate',
  2632. 'cellchange',
  2633. 'controlselect',
  2634. 'dataavailable',
  2635. 'datasetchanged',
  2636. 'datasetcomplete',
  2637. 'errorupdate',
  2638. 'filterchange',
  2639. 'layoutcomplete',
  2640. 'losecapture',
  2641. 'move',
  2642. 'moveend',
  2643. 'movestart',
  2644. 'propertychange',
  2645. 'resizeend',
  2646. 'resizestart',
  2647. 'rowenter',
  2648. 'rowexit',
  2649. 'rowsdelete',
  2650. 'rowsinserted',
  2651. 'command',
  2652. 'compassneedscalibration',
  2653. 'deactivate',
  2654. 'help',
  2655. 'mscontentzoom',
  2656. 'msmanipulationstatechanged',
  2657. 'msgesturechange',
  2658. 'msgesturedoubletap',
  2659. 'msgestureend',
  2660. 'msgesturehold',
  2661. 'msgesturestart',
  2662. 'msgesturetap',
  2663. 'msgotpointercapture',
  2664. 'msinertiastart',
  2665. 'mslostpointercapture',
  2666. 'mspointercancel',
  2667. 'mspointerdown',
  2668. 'mspointerenter',
  2669. 'mspointerhover',
  2670. 'mspointerleave',
  2671. 'mspointermove',
  2672. 'mspointerout',
  2673. 'mspointerover',
  2674. 'mspointerup',
  2675. 'pointerout',
  2676. 'mssitemodejumplistitemremoved',
  2677. 'msthumbnailclick',
  2678. 'stop',
  2679. 'storagecommit'
  2680. ];
  2681. var webglEventNames = ['webglcontextrestored', 'webglcontextlost', 'webglcontextcreationerror'];
  2682. var formEventNames = ['autocomplete', 'autocompleteerror'];
  2683. var detailEventNames = ['toggle'];
  2684. var frameEventNames = ['load'];
  2685. var frameSetEventNames = ['blur', 'error', 'focus', 'load', 'resize', 'scroll', 'messageerror'];
  2686. var marqueeEventNames = ['bounce', 'finish', 'start'];
  2687. var XMLHttpRequestEventNames = [
  2688. 'loadstart', 'progress', 'abort', 'error', 'load', 'progress', 'timeout', 'loadend',
  2689. 'readystatechange'
  2690. ];
  2691. var IDBIndexEventNames = ['upgradeneeded', 'complete', 'abort', 'success', 'error', 'blocked', 'versionchange', 'close'];
  2692. var websocketEventNames = ['close', 'error', 'open', 'message'];
  2693. var workerEventNames = ['error', 'message'];
  2694. var eventNames = globalEventHandlersEventNames.concat(webglEventNames, formEventNames, detailEventNames, documentEventNames, windowEventNames, htmlElementEventNames, ieElementEventNames);
  2695. function filterProperties(target, onProperties, ignoreProperties) {
  2696. if (!ignoreProperties || ignoreProperties.length === 0) {
  2697. return onProperties;
  2698. }
  2699. var tip = ignoreProperties.filter(function (ip) { return ip.target === target; });
  2700. if (!tip || tip.length === 0) {
  2701. return onProperties;
  2702. }
  2703. var targetIgnoreProperties = tip[0].ignoreProperties;
  2704. return onProperties.filter(function (op) { return targetIgnoreProperties.indexOf(op) === -1; });
  2705. }
  2706. function patchFilteredProperties(target, onProperties, ignoreProperties, prototype) {
  2707. // check whether target is available, sometimes target will be undefined
  2708. // because different browser or some 3rd party plugin.
  2709. if (!target) {
  2710. return;
  2711. }
  2712. var filteredProperties = filterProperties(target, onProperties, ignoreProperties);
  2713. patchOnProperties(target, filteredProperties, prototype);
  2714. }
  2715. function propertyDescriptorPatch(api, _global) {
  2716. if (isNode && !isMix) {
  2717. return;
  2718. }
  2719. if (Zone[api.symbol('patchEvents')]) {
  2720. // events are already been patched by legacy patch.
  2721. return;
  2722. }
  2723. var supportsWebSocket = typeof WebSocket !== 'undefined';
  2724. var ignoreProperties = _global['__Zone_ignore_on_properties'];
  2725. // for browsers that we can patch the descriptor: Chrome & Firefox
  2726. if (isBrowser) {
  2727. var internalWindow = window;
  2728. var ignoreErrorProperties = isIE ? [{ target: internalWindow, ignoreProperties: ['error'] }] : [];
  2729. // in IE/Edge, onProp not exist in window object, but in WindowPrototype
  2730. // so we need to pass WindowPrototype to check onProp exist or not
  2731. patchFilteredProperties(internalWindow, eventNames.concat(['messageerror']), ignoreProperties ? ignoreProperties.concat(ignoreErrorProperties) : ignoreProperties, ObjectGetPrototypeOf(internalWindow));
  2732. patchFilteredProperties(Document.prototype, eventNames, ignoreProperties);
  2733. if (typeof internalWindow['SVGElement'] !== 'undefined') {
  2734. patchFilteredProperties(internalWindow['SVGElement'].prototype, eventNames, ignoreProperties);
  2735. }
  2736. patchFilteredProperties(Element.prototype, eventNames, ignoreProperties);
  2737. patchFilteredProperties(HTMLElement.prototype, eventNames, ignoreProperties);
  2738. patchFilteredProperties(HTMLMediaElement.prototype, mediaElementEventNames, ignoreProperties);
  2739. patchFilteredProperties(HTMLFrameSetElement.prototype, windowEventNames.concat(frameSetEventNames), ignoreProperties);
  2740. patchFilteredProperties(HTMLBodyElement.prototype, windowEventNames.concat(frameSetEventNames), ignoreProperties);
  2741. patchFilteredProperties(HTMLFrameElement.prototype, frameEventNames, ignoreProperties);
  2742. patchFilteredProperties(HTMLIFrameElement.prototype, frameEventNames, ignoreProperties);
  2743. var HTMLMarqueeElement_1 = internalWindow['HTMLMarqueeElement'];
  2744. if (HTMLMarqueeElement_1) {
  2745. patchFilteredProperties(HTMLMarqueeElement_1.prototype, marqueeEventNames, ignoreProperties);
  2746. }
  2747. var Worker_1 = internalWindow['Worker'];
  2748. if (Worker_1) {
  2749. patchFilteredProperties(Worker_1.prototype, workerEventNames, ignoreProperties);
  2750. }
  2751. }
  2752. var XMLHttpRequest = _global['XMLHttpRequest'];
  2753. if (XMLHttpRequest) {
  2754. // XMLHttpRequest is not available in ServiceWorker, so we need to check here
  2755. patchFilteredProperties(XMLHttpRequest.prototype, XMLHttpRequestEventNames, ignoreProperties);
  2756. }
  2757. var XMLHttpRequestEventTarget = _global['XMLHttpRequestEventTarget'];
  2758. if (XMLHttpRequestEventTarget) {
  2759. patchFilteredProperties(XMLHttpRequestEventTarget && XMLHttpRequestEventTarget.prototype, XMLHttpRequestEventNames, ignoreProperties);
  2760. }
  2761. if (typeof IDBIndex !== 'undefined') {
  2762. patchFilteredProperties(IDBIndex.prototype, IDBIndexEventNames, ignoreProperties);
  2763. patchFilteredProperties(IDBRequest.prototype, IDBIndexEventNames, ignoreProperties);
  2764. patchFilteredProperties(IDBOpenDBRequest.prototype, IDBIndexEventNames, ignoreProperties);
  2765. patchFilteredProperties(IDBDatabase.prototype, IDBIndexEventNames, ignoreProperties);
  2766. patchFilteredProperties(IDBTransaction.prototype, IDBIndexEventNames, ignoreProperties);
  2767. patchFilteredProperties(IDBCursor.prototype, IDBIndexEventNames, ignoreProperties);
  2768. }
  2769. if (supportsWebSocket) {
  2770. patchFilteredProperties(WebSocket.prototype, websocketEventNames, ignoreProperties);
  2771. }
  2772. }
  2773. /**
  2774. * @license
  2775. * Copyright Google Inc. All Rights Reserved.
  2776. *
  2777. * Use of this source code is governed by an MIT-style license that can be
  2778. * found in the LICENSE file at https://angular.io/license
  2779. */
  2780. /**
  2781. * @fileoverview
  2782. * @suppress {missingRequire}
  2783. */
  2784. Zone.__load_patch('legacy', function (global) {
  2785. var legacyPatch = global[Zone.__symbol__('legacyPatch')];
  2786. if (legacyPatch) {
  2787. legacyPatch();
  2788. }
  2789. });
  2790. Zone.__load_patch('timers', function (global) {
  2791. var set = 'set';
  2792. var clear = 'clear';
  2793. patchTimer(global, set, clear, 'Timeout');
  2794. patchTimer(global, set, clear, 'Interval');
  2795. patchTimer(global, set, clear, 'Immediate');
  2796. });
  2797. Zone.__load_patch('requestAnimationFrame', function (global) {
  2798. patchTimer(global, 'request', 'cancel', 'AnimationFrame');
  2799. patchTimer(global, 'mozRequest', 'mozCancel', 'AnimationFrame');
  2800. patchTimer(global, 'webkitRequest', 'webkitCancel', 'AnimationFrame');
  2801. });
  2802. Zone.__load_patch('blocking', function (global, Zone) {
  2803. var blockingMethods = ['alert', 'prompt', 'confirm'];
  2804. for (var i = 0; i < blockingMethods.length; i++) {
  2805. var name_1 = blockingMethods[i];
  2806. patchMethod(global, name_1, function (delegate, symbol, name) {
  2807. return function (s, args) {
  2808. return Zone.current.run(delegate, global, args, name);
  2809. };
  2810. });
  2811. }
  2812. });
  2813. Zone.__load_patch('EventTarget', function (global, Zone, api) {
  2814. patchEvent(global, api);
  2815. eventTargetPatch(global, api);
  2816. // patch XMLHttpRequestEventTarget's addEventListener/removeEventListener
  2817. var XMLHttpRequestEventTarget = global['XMLHttpRequestEventTarget'];
  2818. if (XMLHttpRequestEventTarget && XMLHttpRequestEventTarget.prototype) {
  2819. api.patchEventTarget(global, [XMLHttpRequestEventTarget.prototype]);
  2820. }
  2821. patchClass('MutationObserver');
  2822. patchClass('WebKitMutationObserver');
  2823. patchClass('IntersectionObserver');
  2824. patchClass('FileReader');
  2825. });
  2826. Zone.__load_patch('on_property', function (global, Zone, api) {
  2827. propertyDescriptorPatch(api, global);
  2828. propertyPatch();
  2829. });
  2830. Zone.__load_patch('customElements', function (global, Zone, api) {
  2831. patchCustomElements(global, api);
  2832. });
  2833. Zone.__load_patch('XHR', function (global, Zone) {
  2834. // Treat XMLHttpRequest as a macrotask.
  2835. patchXHR(global);
  2836. var XHR_TASK = zoneSymbol('xhrTask');
  2837. var XHR_SYNC = zoneSymbol('xhrSync');
  2838. var XHR_LISTENER = zoneSymbol('xhrListener');
  2839. var XHR_SCHEDULED = zoneSymbol('xhrScheduled');
  2840. var XHR_URL = zoneSymbol('xhrURL');
  2841. var XHR_ERROR_BEFORE_SCHEDULED = zoneSymbol('xhrErrorBeforeScheduled');
  2842. function patchXHR(window) {
  2843. var XMLHttpRequest = window['XMLHttpRequest'];
  2844. if (!XMLHttpRequest) {
  2845. // XMLHttpRequest is not available in service worker
  2846. return;
  2847. }
  2848. var XMLHttpRequestPrototype = XMLHttpRequest.prototype;
  2849. function findPendingTask(target) {
  2850. return target[XHR_TASK];
  2851. }
  2852. var oriAddListener = XMLHttpRequestPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER];
  2853. var oriRemoveListener = XMLHttpRequestPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
  2854. if (!oriAddListener) {
  2855. var XMLHttpRequestEventTarget_1 = window['XMLHttpRequestEventTarget'];
  2856. if (XMLHttpRequestEventTarget_1) {
  2857. var XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget_1.prototype;
  2858. oriAddListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER];
  2859. oriRemoveListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
  2860. }
  2861. }
  2862. var READY_STATE_CHANGE = 'readystatechange';
  2863. var SCHEDULED = 'scheduled';
  2864. function scheduleTask(task) {
  2865. var data = task.data;
  2866. var target = data.target;
  2867. target[XHR_SCHEDULED] = false;
  2868. target[XHR_ERROR_BEFORE_SCHEDULED] = false;
  2869. // remove existing event listener
  2870. var listener = target[XHR_LISTENER];
  2871. if (!oriAddListener) {
  2872. oriAddListener = target[ZONE_SYMBOL_ADD_EVENT_LISTENER];
  2873. oriRemoveListener = target[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
  2874. }
  2875. if (listener) {
  2876. oriRemoveListener.call(target, READY_STATE_CHANGE, listener);
  2877. }
  2878. var newListener = target[XHR_LISTENER] = function () {
  2879. if (target.readyState === target.DONE) {
  2880. // sometimes on some browsers XMLHttpRequest will fire onreadystatechange with
  2881. // readyState=4 multiple times, so we need to check task state here
  2882. if (!data.aborted && target[XHR_SCHEDULED] && task.state === SCHEDULED) {
  2883. // check whether the xhr has registered onload listener
  2884. // if that is the case, the task should invoke after all
  2885. // onload listeners finish.
  2886. var loadTasks = target['__zone_symbol__loadfalse'];
  2887. if (loadTasks && loadTasks.length > 0) {
  2888. var oriInvoke_1 = task.invoke;
  2889. task.invoke = function () {
  2890. // need to load the tasks again, because in other
  2891. // load listener, they may remove themselves
  2892. var loadTasks = target['__zone_symbol__loadfalse'];
  2893. for (var i = 0; i < loadTasks.length; i++) {
  2894. if (loadTasks[i] === task) {
  2895. loadTasks.splice(i, 1);
  2896. }
  2897. }
  2898. if (!data.aborted && task.state === SCHEDULED) {
  2899. oriInvoke_1.call(task);
  2900. }
  2901. };
  2902. loadTasks.push(task);
  2903. }
  2904. else {
  2905. task.invoke();
  2906. }
  2907. }
  2908. else if (!data.aborted && target[XHR_SCHEDULED] === false) {
  2909. // error occurs when xhr.send()
  2910. target[XHR_ERROR_BEFORE_SCHEDULED] = true;
  2911. }
  2912. }
  2913. };
  2914. oriAddListener.call(target, READY_STATE_CHANGE, newListener);
  2915. var storedTask = target[XHR_TASK];
  2916. if (!storedTask) {
  2917. target[XHR_TASK] = task;
  2918. }
  2919. sendNative.apply(target, data.args);
  2920. target[XHR_SCHEDULED] = true;
  2921. return task;
  2922. }
  2923. function placeholderCallback() { }
  2924. function clearTask(task) {
  2925. var data = task.data;
  2926. // Note - ideally, we would call data.target.removeEventListener here, but it's too late
  2927. // to prevent it from firing. So instead, we store info for the event listener.
  2928. data.aborted = true;
  2929. return abortNative.apply(data.target, data.args);
  2930. }
  2931. var openNative = patchMethod(XMLHttpRequestPrototype, 'open', function () { return function (self, args) {
  2932. self[XHR_SYNC] = args[2] == false;
  2933. self[XHR_URL] = args[1];
  2934. return openNative.apply(self, args);
  2935. }; });
  2936. var XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send';
  2937. var fetchTaskAborting = zoneSymbol('fetchTaskAborting');
  2938. var fetchTaskScheduling = zoneSymbol('fetchTaskScheduling');
  2939. var sendNative = patchMethod(XMLHttpRequestPrototype, 'send', function () { return function (self, args) {
  2940. if (Zone.current[fetchTaskScheduling] === true) {
  2941. // a fetch is scheduling, so we are using xhr to polyfill fetch
  2942. // and because we already schedule macroTask for fetch, we should
  2943. // not schedule a macroTask for xhr again
  2944. return sendNative.apply(self, args);
  2945. }
  2946. if (self[XHR_SYNC]) {
  2947. // if the XHR is sync there is no task to schedule, just execute the code.
  2948. return sendNative.apply(self, args);
  2949. }
  2950. else {
  2951. var options = { target: self, url: self[XHR_URL], isPeriodic: false, args: args, aborted: false };
  2952. var task = scheduleMacroTaskWithCurrentZone(XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask);
  2953. if (self && self[XHR_ERROR_BEFORE_SCHEDULED] === true && !options.aborted &&
  2954. task.state === SCHEDULED) {
  2955. // xhr request throw error when send
  2956. // we should invoke task instead of leaving a scheduled
  2957. // pending macroTask
  2958. task.invoke();
  2959. }
  2960. }
  2961. }; });
  2962. var abortNative = patchMethod(XMLHttpRequestPrototype, 'abort', function () { return function (self, args) {
  2963. var task = findPendingTask(self);
  2964. if (task && typeof task.type == 'string') {
  2965. // If the XHR has already completed, do nothing.
  2966. // If the XHR has already been aborted, do nothing.
  2967. // Fix #569, call abort multiple times before done will cause
  2968. // macroTask task count be negative number
  2969. if (task.cancelFn == null || (task.data && task.data.aborted)) {
  2970. return;
  2971. }
  2972. task.zone.cancelTask(task);
  2973. }
  2974. else if (Zone.current[fetchTaskAborting] === true) {
  2975. // the abort is called from fetch polyfill, we need to call native abort of XHR.
  2976. return abortNative.apply(self, args);
  2977. }
  2978. // Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no
  2979. // task
  2980. // to cancel. Do nothing.
  2981. }; });
  2982. }
  2983. });
  2984. Zone.__load_patch('geolocation', function (global) {
  2985. /// GEO_LOCATION
  2986. if (global['navigator'] && global['navigator'].geolocation) {
  2987. patchPrototype(global['navigator'].geolocation, ['getCurrentPosition', 'watchPosition']);
  2988. }
  2989. });
  2990. Zone.__load_patch('PromiseRejectionEvent', function (global, Zone) {
  2991. // handle unhandled promise rejection
  2992. function findPromiseRejectionHandler(evtName) {
  2993. return function (e) {
  2994. var eventTasks = findEventTasks(global, evtName);
  2995. eventTasks.forEach(function (eventTask) {
  2996. // windows has added unhandledrejection event listener
  2997. // trigger the event listener
  2998. var PromiseRejectionEvent = global['PromiseRejectionEvent'];
  2999. if (PromiseRejectionEvent) {
  3000. var evt = new PromiseRejectionEvent(evtName, { promise: e.promise, reason: e.rejection });
  3001. eventTask.invoke(evt);
  3002. }
  3003. });
  3004. };
  3005. }
  3006. if (global['PromiseRejectionEvent']) {
  3007. Zone[zoneSymbol('unhandledPromiseRejectionHandler')] =
  3008. findPromiseRejectionHandler('unhandledrejection');
  3009. Zone[zoneSymbol('rejectionHandledHandler')] =
  3010. findPromiseRejectionHandler('rejectionhandled');
  3011. }
  3012. });
  3013. /**
  3014. * @license
  3015. * Copyright Google Inc. All Rights Reserved.
  3016. *
  3017. * Use of this source code is governed by an MIT-style license that can be
  3018. * found in the LICENSE file at https://angular.io/license
  3019. */
  3020. Zone.__load_patch('node_util', function (global, Zone, api) {
  3021. api.patchOnProperties = patchOnProperties;
  3022. api.patchMethod = patchMethod;
  3023. api.bindArguments = bindArguments;
  3024. api.patchMacroTask = patchMacroTask;
  3025. setShouldCopySymbolProperties(true);
  3026. });
  3027. /**
  3028. * @license
  3029. * Copyright Google Inc. All Rights Reserved.
  3030. *
  3031. * Use of this source code is governed by an MIT-style license that can be
  3032. * found in the LICENSE file at https://angular.io/license
  3033. */
  3034. Zone.__load_patch('EventEmitter', function (global) {
  3035. // For EventEmitter
  3036. var EE_ADD_LISTENER = 'addListener';
  3037. var EE_PREPEND_LISTENER = 'prependListener';
  3038. var EE_REMOVE_LISTENER = 'removeListener';
  3039. var EE_REMOVE_ALL_LISTENER = 'removeAllListeners';
  3040. var EE_LISTENERS = 'listeners';
  3041. var EE_ON = 'on';
  3042. var compareTaskCallbackVsDelegate = function (task, delegate) {
  3043. // same callback, same capture, same event name, just return
  3044. return task.callback === delegate || task.callback.listener === delegate;
  3045. };
  3046. var eventNameToString = function (eventName) {
  3047. if (typeof eventName === 'string') {
  3048. return eventName;
  3049. }
  3050. if (!eventName) {
  3051. return '';
  3052. }
  3053. return eventName.toString().replace('(', '_').replace(')', '_');
  3054. };
  3055. function patchEventEmitterMethods(obj) {
  3056. var result = patchEventTarget(global, [obj], {
  3057. useG: false,
  3058. add: EE_ADD_LISTENER,
  3059. rm: EE_REMOVE_LISTENER,
  3060. prepend: EE_PREPEND_LISTENER,
  3061. rmAll: EE_REMOVE_ALL_LISTENER,
  3062. listeners: EE_LISTENERS,
  3063. chkDup: false,
  3064. rt: true,
  3065. diff: compareTaskCallbackVsDelegate,
  3066. eventNameToString: eventNameToString
  3067. });
  3068. if (result && result[0]) {
  3069. obj[EE_ON] = obj[EE_ADD_LISTENER];
  3070. }
  3071. }
  3072. // EventEmitter
  3073. var events;
  3074. try {
  3075. events = require('events');
  3076. }
  3077. catch (err) {
  3078. }
  3079. if (events && events.EventEmitter) {
  3080. patchEventEmitterMethods(events.EventEmitter.prototype);
  3081. }
  3082. });
  3083. /**
  3084. * @license
  3085. * Copyright Google Inc. All Rights Reserved.
  3086. *
  3087. * Use of this source code is governed by an MIT-style license that can be
  3088. * found in the LICENSE file at https://angular.io/license
  3089. */
  3090. Zone.__load_patch('fs', function () {
  3091. var fs;
  3092. try {
  3093. fs = require('fs');
  3094. }
  3095. catch (err) {
  3096. }
  3097. // watch, watchFile, unwatchFile has been patched
  3098. // because EventEmitter has been patched
  3099. var TO_PATCH_MACROTASK_METHODS = [
  3100. 'access', 'appendFile', 'chmod', 'chown', 'close', 'exists', 'fchmod',
  3101. 'fchown', 'fdatasync', 'fstat', 'fsync', 'ftruncate', 'futimes', 'lchmod',
  3102. 'lchown', 'link', 'lstat', 'mkdir', 'mkdtemp', 'open', 'read',
  3103. 'readdir', 'readFile', 'readlink', 'realpath', 'rename', 'rmdir', 'stat',
  3104. 'symlink', 'truncate', 'unlink', 'utimes', 'write', 'writeFile',
  3105. ];
  3106. if (fs) {
  3107. TO_PATCH_MACROTASK_METHODS.filter(function (name) { return !!fs[name] && typeof fs[name] === 'function'; })
  3108. .forEach(function (name) {
  3109. patchMacroTask(fs, name, function (self, args) {
  3110. return {
  3111. name: 'fs.' + name,
  3112. args: args,
  3113. cbIdx: args.length > 0 ? args.length - 1 : -1,
  3114. target: self
  3115. };
  3116. });
  3117. });
  3118. }
  3119. });
  3120. /**
  3121. * @license
  3122. * Copyright Google Inc. All Rights Reserved.
  3123. *
  3124. * Use of this source code is governed by an MIT-style license that can be
  3125. * found in the LICENSE file at https://angular.io/license
  3126. */
  3127. var set = 'set';
  3128. var clear = 'clear';
  3129. Zone.__load_patch('node_timers', function (global, Zone) {
  3130. // Timers
  3131. var globalUseTimeoutFromTimer = false;
  3132. try {
  3133. var timers = require('timers');
  3134. var globalEqualTimersTimeout = global.setTimeout === timers.setTimeout;
  3135. if (!globalEqualTimersTimeout && !isMix) {
  3136. // 1. if isMix, then we are in mix environment such as Electron
  3137. // we should only patch timers.setTimeout because global.setTimeout
  3138. // have been patched
  3139. // 2. if global.setTimeout not equal timers.setTimeout, check
  3140. // whether global.setTimeout use timers.setTimeout or not
  3141. var originSetTimeout_1 = timers.setTimeout;
  3142. timers.setTimeout = function () {
  3143. globalUseTimeoutFromTimer = true;
  3144. return originSetTimeout_1.apply(this, arguments);
  3145. };
  3146. var detectTimeout = global.setTimeout(function () { }, 100);
  3147. clearTimeout(detectTimeout);
  3148. timers.setTimeout = originSetTimeout_1;
  3149. }
  3150. patchTimer(timers, set, clear, 'Timeout');
  3151. patchTimer(timers, set, clear, 'Interval');
  3152. patchTimer(timers, set, clear, 'Immediate');
  3153. }
  3154. catch (error) {
  3155. // timers module not exists, for example, when we using nativeScript
  3156. // timers is not available
  3157. }
  3158. if (isMix) {
  3159. // if we are in mix environment, such as Electron,
  3160. // the global.setTimeout has already been patched,
  3161. // so we just patch timers.setTimeout
  3162. return;
  3163. }
  3164. if (!globalUseTimeoutFromTimer) {
  3165. // 1. global setTimeout equals timers setTimeout
  3166. // 2. or global don't use timers setTimeout(maybe some other library patch setTimeout)
  3167. // 3. or load timers module error happens, we should patch global setTimeout
  3168. patchTimer(global, set, clear, 'Timeout');
  3169. patchTimer(global, set, clear, 'Interval');
  3170. patchTimer(global, set, clear, 'Immediate');
  3171. }
  3172. else {
  3173. // global use timers setTimeout, but not equals
  3174. // this happens when use nodejs v0.10.x, global setTimeout will
  3175. // use a lazy load version of timers setTimeout
  3176. // we should not double patch timer's setTimeout
  3177. // so we only store the __symbol__ for consistency
  3178. global[Zone.__symbol__('setTimeout')] = global.setTimeout;
  3179. global[Zone.__symbol__('setInterval')] = global.setInterval;
  3180. global[Zone.__symbol__('setImmediate')] = global.setImmediate;
  3181. }
  3182. });
  3183. // patch process related methods
  3184. Zone.__load_patch('nextTick', function () {
  3185. // patch nextTick as microTask
  3186. patchMicroTask(process, 'nextTick', function (self, args) {
  3187. return {
  3188. name: 'process.nextTick',
  3189. args: args,
  3190. cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1,
  3191. target: process
  3192. };
  3193. });
  3194. });
  3195. Zone.__load_patch('handleUnhandledPromiseRejection', function (global, Zone, api) {
  3196. Zone[api.symbol('unhandledPromiseRejectionHandler')] =
  3197. findProcessPromiseRejectionHandler('unhandledRejection');
  3198. Zone[api.symbol('rejectionHandledHandler')] =
  3199. findProcessPromiseRejectionHandler('rejectionHandled');
  3200. // handle unhandled promise rejection
  3201. function findProcessPromiseRejectionHandler(evtName) {
  3202. return function (e) {
  3203. var eventTasks = findEventTasks(process, evtName);
  3204. eventTasks.forEach(function (eventTask) {
  3205. // process has added unhandledrejection event listener
  3206. // trigger the event listener
  3207. if (evtName === 'unhandledRejection') {
  3208. eventTask.invoke(e.rejection, e.promise);
  3209. }
  3210. else if (evtName === 'rejectionHandled') {
  3211. eventTask.invoke(e.promise);
  3212. }
  3213. });
  3214. };
  3215. }
  3216. });
  3217. // Crypto
  3218. Zone.__load_patch('crypto', function () {
  3219. var crypto;
  3220. try {
  3221. crypto = require('crypto');
  3222. }
  3223. catch (err) {
  3224. }
  3225. // use the generic patchMacroTask to patch crypto
  3226. if (crypto) {
  3227. var methodNames = ['randomBytes', 'pbkdf2'];
  3228. methodNames.forEach(function (name) {
  3229. patchMacroTask(crypto, name, function (self, args) {
  3230. return {
  3231. name: 'crypto.' + name,
  3232. args: args,
  3233. cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ?
  3234. args.length - 1 :
  3235. -1,
  3236. target: crypto
  3237. };
  3238. });
  3239. });
  3240. }
  3241. });
  3242. Zone.__load_patch('console', function (global, Zone) {
  3243. var consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace'];
  3244. consoleMethods.forEach(function (m) {
  3245. var originalMethod = console[Zone.__symbol__(m)] = console[m];
  3246. if (originalMethod) {
  3247. console[m] = function () {
  3248. var args = ArraySlice.call(arguments);
  3249. if (Zone.current === Zone.root) {
  3250. return originalMethod.apply(this, args);
  3251. }
  3252. else {
  3253. return Zone.root.run(originalMethod, this, args);
  3254. }
  3255. };
  3256. }
  3257. });
  3258. });
  3259. /**
  3260. * @license
  3261. * Copyright Google Inc. All Rights Reserved.
  3262. *
  3263. * Use of this source code is governed by an MIT-style license that can be
  3264. * found in the LICENSE file at https://angular.io/license
  3265. */
  3266. })));