a zip code crypto-currency system good for red ONLY

zone-mix.js 136KB

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