amf-debug.js 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596
  1. var $jscomp = $jscomp || {};
  2. $jscomp.scope = {};
  3. $jscomp.ASSUME_ES5 = false;
  4. $jscomp.ASSUME_NO_NATIVE_MAP = false;
  5. $jscomp.ASSUME_NO_NATIVE_SET = false;
  6. $jscomp.defineProperty = $jscomp.ASSUME_ES5 || typeof Object.defineProperties == 'function' ? Object.defineProperty : function(target, property, descriptor) {
  7. descriptor = descriptor;
  8. if (target == Array.prototype || target == Object.prototype) {
  9. return;
  10. }
  11. target[property] = descriptor.value;
  12. };
  13. $jscomp.getGlobal = function(maybeGlobal) {
  14. return typeof window != 'undefined' && window === maybeGlobal ? maybeGlobal : typeof global != 'undefined' && global != null ? global : maybeGlobal;
  15. };
  16. $jscomp.global = $jscomp.getGlobal(this);
  17. $jscomp.polyfill = function(target, polyfill, fromLang, toLang) {
  18. if (!polyfill) {
  19. return;
  20. }
  21. var obj = $jscomp.global;
  22. var split = target.split('.');
  23. for (var i = 0; i < split.length - 1; i++) {
  24. var key = split[i];
  25. if (!(key in obj)) {
  26. obj[key] = {};
  27. }
  28. obj = obj[key];
  29. }
  30. var property = split[split.length - 1];
  31. var orig = obj[property];
  32. var impl = polyfill(orig);
  33. if (impl == orig || impl == null) {
  34. return;
  35. }
  36. $jscomp.defineProperty(obj, property, {configurable:true, writable:true, value:impl});
  37. };
  38. $jscomp.polyfill('Array.prototype.copyWithin', function(orig) {
  39. if (orig) {
  40. return orig;
  41. }
  42. var polyfill = function(target, start, opt_end) {
  43. var len = this.length;
  44. target = Number(target);
  45. start = Number(start);
  46. opt_end = Number(opt_end != null ? opt_end : len);
  47. if (target < start) {
  48. opt_end = Math.min(opt_end, len);
  49. while (start < opt_end) {
  50. if (start in this) {
  51. this[target++] = this[start++];
  52. } else {
  53. delete this[target++];
  54. start++;
  55. }
  56. }
  57. } else {
  58. opt_end = Math.min(opt_end, len + start - target);
  59. target += opt_end - start;
  60. while (opt_end > start) {
  61. if (--opt_end in this) {
  62. this[--target] = this[opt_end];
  63. } else {
  64. delete this[target];
  65. }
  66. }
  67. }
  68. return this;
  69. };
  70. return polyfill;
  71. }, 'es6', 'es3');
  72. $jscomp.SYMBOL_PREFIX = 'jscomp_symbol_';
  73. $jscomp.initSymbol = function() {
  74. $jscomp.initSymbol = function() {
  75. };
  76. if (!$jscomp.global['Symbol']) {
  77. $jscomp.global['Symbol'] = $jscomp.Symbol;
  78. }
  79. };
  80. $jscomp.Symbol = function() {
  81. var counter = 0;
  82. function Symbol(opt_description) {
  83. return $jscomp.SYMBOL_PREFIX + (opt_description || '') + counter++;
  84. }
  85. return Symbol;
  86. }();
  87. $jscomp.initSymbolIterator = function() {
  88. $jscomp.initSymbol();
  89. var symbolIterator = $jscomp.global['Symbol'].iterator;
  90. if (!symbolIterator) {
  91. symbolIterator = $jscomp.global['Symbol'].iterator = $jscomp.global['Symbol']('iterator');
  92. }
  93. if (typeof Array.prototype[symbolIterator] != 'function') {
  94. $jscomp.defineProperty(Array.prototype, symbolIterator, {configurable:true, writable:true, value:function() {
  95. return $jscomp.arrayIterator(this);
  96. }});
  97. }
  98. $jscomp.initSymbolIterator = function() {
  99. };
  100. };
  101. $jscomp.arrayIterator = function(array) {
  102. var index = 0;
  103. return $jscomp.iteratorPrototype(function() {
  104. if (index < array.length) {
  105. return {done:false, value:array[index++]};
  106. } else {
  107. return {done:true};
  108. }
  109. });
  110. };
  111. $jscomp.iteratorPrototype = function(next) {
  112. $jscomp.initSymbolIterator();
  113. var iterator = {next:next};
  114. iterator[$jscomp.global['Symbol'].iterator] = function() {
  115. return this;
  116. };
  117. return iterator;
  118. };
  119. $jscomp.iteratorFromArray = function(array, transform) {
  120. $jscomp.initSymbolIterator();
  121. if (array instanceof String) {
  122. array = array + '';
  123. }
  124. var i = 0;
  125. var iter = {next:function() {
  126. if (i < array.length) {
  127. var index = i++;
  128. return {value:transform(index, array[index]), done:false};
  129. }
  130. iter.next = function() {
  131. return {done:true, value:void 0};
  132. };
  133. return iter.next();
  134. }};
  135. iter[Symbol.iterator] = function() {
  136. return iter;
  137. };
  138. return iter;
  139. };
  140. $jscomp.polyfill('Array.prototype.entries', function(orig) {
  141. if (orig) {
  142. return orig;
  143. }
  144. var polyfill = function() {
  145. return $jscomp.iteratorFromArray(this, function(i, v) {
  146. return [i, v];
  147. });
  148. };
  149. return polyfill;
  150. }, 'es6', 'es3');
  151. $jscomp.polyfill('Array.prototype.fill', function(orig) {
  152. if (orig) {
  153. return orig;
  154. }
  155. var polyfill = function(value, opt_start, opt_end) {
  156. var length = this.length || 0;
  157. if (opt_start < 0) {
  158. opt_start = Math.max(0, length + opt_start);
  159. }
  160. if (opt_end == null || opt_end > length) {
  161. opt_end = length;
  162. }
  163. opt_end = Number(opt_end);
  164. if (opt_end < 0) {
  165. opt_end = Math.max(0, length + opt_end);
  166. }
  167. for (var i = Number(opt_start || 0); i < opt_end; i++) {
  168. this[i] = value;
  169. }
  170. return this;
  171. };
  172. return polyfill;
  173. }, 'es6', 'es3');
  174. $jscomp.findInternal = function(array, callback, thisArg) {
  175. if (array instanceof String) {
  176. array = String(array);
  177. }
  178. var len = array.length;
  179. for (var i = 0; i < len; i++) {
  180. var value = array[i];
  181. if (callback.call(thisArg, value, i, array)) {
  182. return {i:i, v:value};
  183. }
  184. }
  185. return {i:-1, v:void 0};
  186. };
  187. $jscomp.polyfill('Array.prototype.find', function(orig) {
  188. if (orig) {
  189. return orig;
  190. }
  191. var polyfill = function(callback, opt_thisArg) {
  192. return $jscomp.findInternal(this, callback, opt_thisArg).v;
  193. };
  194. return polyfill;
  195. }, 'es6', 'es3');
  196. $jscomp.polyfill('Array.prototype.findIndex', function(orig) {
  197. if (orig) {
  198. return orig;
  199. }
  200. var polyfill = function(callback, opt_thisArg) {
  201. return $jscomp.findInternal(this, callback, opt_thisArg).i;
  202. };
  203. return polyfill;
  204. }, 'es6', 'es3');
  205. $jscomp.polyfill('Array.from', function(orig) {
  206. if (orig) {
  207. return orig;
  208. }
  209. var polyfill = function(arrayLike, opt_mapFn, opt_thisArg) {
  210. $jscomp.initSymbolIterator();
  211. opt_mapFn = opt_mapFn != null ? opt_mapFn : function(x) {
  212. return x;
  213. };
  214. var result = [];
  215. var iteratorFunction = arrayLike[Symbol.iterator];
  216. if (typeof iteratorFunction == 'function') {
  217. arrayLike = iteratorFunction.call(arrayLike);
  218. var next;
  219. var k = 0;
  220. while (!(next = arrayLike.next()).done) {
  221. result.push(opt_mapFn.call(opt_thisArg, next.value, k++));
  222. }
  223. } else {
  224. var len = arrayLike.length;
  225. for (var i = 0; i < len; i++) {
  226. result.push(opt_mapFn.call(opt_thisArg, arrayLike[i], i));
  227. }
  228. }
  229. return result;
  230. };
  231. return polyfill;
  232. }, 'es6', 'es3');
  233. $jscomp.polyfill('Object.is', function(orig) {
  234. if (orig) {
  235. return orig;
  236. }
  237. var polyfill = function(left, right) {
  238. if (left === right) {
  239. return left !== 0 || 1 / left === 1 / right;
  240. } else {
  241. return left !== left && right !== right;
  242. }
  243. };
  244. return polyfill;
  245. }, 'es6', 'es3');
  246. $jscomp.polyfill('Array.prototype.includes', function(orig) {
  247. if (orig) {
  248. return orig;
  249. }
  250. var includes = function(searchElement, opt_fromIndex) {
  251. var array = this;
  252. if (array instanceof String) {
  253. array = String(array);
  254. }
  255. var len = array.length;
  256. var i = opt_fromIndex || 0;
  257. if (i < 0) {
  258. i = Math.max(i + len, 0);
  259. }
  260. for (; i < len; i++) {
  261. var element = array[i];
  262. if (element === searchElement || Object.is(element, searchElement)) {
  263. return true;
  264. }
  265. }
  266. return false;
  267. };
  268. return includes;
  269. }, 'es7', 'es3');
  270. $jscomp.polyfill('Array.prototype.keys', function(orig) {
  271. if (orig) {
  272. return orig;
  273. }
  274. var polyfill = function() {
  275. return $jscomp.iteratorFromArray(this, function(i) {
  276. return i;
  277. });
  278. };
  279. return polyfill;
  280. }, 'es6', 'es3');
  281. $jscomp.polyfill('Array.of', function(orig) {
  282. if (orig) {
  283. return orig;
  284. }
  285. var polyfill = function(var_args) {
  286. return Array.from(arguments);
  287. };
  288. return polyfill;
  289. }, 'es6', 'es3');
  290. $jscomp.polyfill('Array.prototype.values', function(orig) {
  291. if (orig) {
  292. return orig;
  293. }
  294. var polyfill = function() {
  295. return $jscomp.iteratorFromArray(this, function(k, v) {
  296. return v;
  297. });
  298. };
  299. return polyfill;
  300. }, 'es8', 'es3');
  301. $jscomp.makeIterator = function(iterable) {
  302. $jscomp.initSymbolIterator();
  303. var iteratorFunction = iterable[Symbol.iterator];
  304. return iteratorFunction ? iteratorFunction.call(iterable) : $jscomp.arrayIterator(iterable);
  305. };
  306. $jscomp.FORCE_POLYFILL_PROMISE = false;
  307. $jscomp.polyfill('Promise', function(NativePromise) {
  308. if (NativePromise && !$jscomp.FORCE_POLYFILL_PROMISE) {
  309. return NativePromise;
  310. }
  311. function AsyncExecutor() {
  312. this.batch_ = null;
  313. }
  314. AsyncExecutor.prototype.asyncExecute = function(f) {
  315. if (this.batch_ == null) {
  316. this.batch_ = [];
  317. this.asyncExecuteBatch_();
  318. }
  319. this.batch_.push(f);
  320. return this;
  321. };
  322. AsyncExecutor.prototype.asyncExecuteBatch_ = function() {
  323. var self = this;
  324. this.asyncExecuteFunction(function() {
  325. self.executeBatch_();
  326. });
  327. };
  328. var nativeSetTimeout = $jscomp.global['setTimeout'];
  329. AsyncExecutor.prototype.asyncExecuteFunction = function(f) {
  330. nativeSetTimeout(f, 0);
  331. };
  332. AsyncExecutor.prototype.executeBatch_ = function() {
  333. while (this.batch_ && this.batch_.length) {
  334. var executingBatch = this.batch_;
  335. this.batch_ = [];
  336. for (var i = 0; i < executingBatch.length; ++i) {
  337. var f = executingBatch[i];
  338. executingBatch[i] = null;
  339. try {
  340. f();
  341. } catch (error) {
  342. this.asyncThrow_(error);
  343. }
  344. }
  345. }
  346. this.batch_ = null;
  347. };
  348. AsyncExecutor.prototype.asyncThrow_ = function(exception) {
  349. this.asyncExecuteFunction(function() {
  350. throw exception;
  351. });
  352. };
  353. var PromiseState = {PENDING:0, FULFILLED:1, REJECTED:2};
  354. var PolyfillPromise = function(executor) {
  355. this.state_ = PromiseState.PENDING;
  356. this.result_ = undefined;
  357. this.onSettledCallbacks_ = [];
  358. var resolveAndReject = this.createResolveAndReject_();
  359. try {
  360. executor(resolveAndReject.resolve, resolveAndReject.reject);
  361. } catch (e) {
  362. resolveAndReject.reject(e);
  363. }
  364. };
  365. PolyfillPromise.prototype.createResolveAndReject_ = function() {
  366. var thisPromise = this;
  367. var alreadyCalled = false;
  368. function firstCallWins(method) {
  369. return function(x) {
  370. if (!alreadyCalled) {
  371. alreadyCalled = true;
  372. method.call(thisPromise, x);
  373. }
  374. };
  375. }
  376. return {resolve:firstCallWins(this.resolveTo_), reject:firstCallWins(this.reject_)};
  377. };
  378. PolyfillPromise.prototype.resolveTo_ = function(value) {
  379. if (value === this) {
  380. this.reject_(new TypeError('A Promise cannot resolve to itself'));
  381. } else {
  382. if (value instanceof PolyfillPromise) {
  383. this.settleSameAsPromise_(value);
  384. } else {
  385. if (isObject(value)) {
  386. this.resolveToNonPromiseObj_(value);
  387. } else {
  388. this.fulfill_(value);
  389. }
  390. }
  391. }
  392. };
  393. PolyfillPromise.prototype.resolveToNonPromiseObj_ = function(obj) {
  394. var thenMethod = undefined;
  395. try {
  396. thenMethod = obj.then;
  397. } catch (error) {
  398. this.reject_(error);
  399. return;
  400. }
  401. if (typeof thenMethod == 'function') {
  402. this.settleSameAsThenable_(thenMethod, obj);
  403. } else {
  404. this.fulfill_(obj);
  405. }
  406. };
  407. function isObject(value) {
  408. switch(typeof value) {
  409. case 'object':
  410. return value != null;
  411. case 'function':
  412. return true;
  413. default:
  414. return false;
  415. }
  416. }
  417. PolyfillPromise.prototype.reject_ = function(reason) {
  418. this.settle_(PromiseState.REJECTED, reason);
  419. };
  420. PolyfillPromise.prototype.fulfill_ = function(value) {
  421. this.settle_(PromiseState.FULFILLED, value);
  422. };
  423. PolyfillPromise.prototype.settle_ = function(settledState, valueOrReason) {
  424. if (this.state_ != PromiseState.PENDING) {
  425. throw new Error('Cannot settle(' + settledState + ', ' + valueOrReason + '): Promise already settled in state' + this.state_);
  426. }
  427. this.state_ = settledState;
  428. this.result_ = valueOrReason;
  429. this.executeOnSettledCallbacks_();
  430. };
  431. PolyfillPromise.prototype.executeOnSettledCallbacks_ = function() {
  432. if (this.onSettledCallbacks_ != null) {
  433. for (var i = 0; i < this.onSettledCallbacks_.length; ++i) {
  434. asyncExecutor.asyncExecute(this.onSettledCallbacks_[i]);
  435. }
  436. this.onSettledCallbacks_ = null;
  437. }
  438. };
  439. var asyncExecutor = new AsyncExecutor;
  440. PolyfillPromise.prototype.settleSameAsPromise_ = function(promise) {
  441. var methods = this.createResolveAndReject_();
  442. promise.callWhenSettled_(methods.resolve, methods.reject);
  443. };
  444. PolyfillPromise.prototype.settleSameAsThenable_ = function(thenMethod, thenable) {
  445. var methods = this.createResolveAndReject_();
  446. try {
  447. thenMethod.call(thenable, methods.resolve, methods.reject);
  448. } catch (error) {
  449. methods.reject(error);
  450. }
  451. };
  452. PolyfillPromise.prototype.then = function(onFulfilled, onRejected) {
  453. var resolveChild;
  454. var rejectChild;
  455. var childPromise = new PolyfillPromise(function(resolve, reject) {
  456. resolveChild = resolve;
  457. rejectChild = reject;
  458. });
  459. function createCallback(paramF, defaultF) {
  460. if (typeof paramF == 'function') {
  461. return function(x) {
  462. try {
  463. resolveChild(paramF(x));
  464. } catch (error) {
  465. rejectChild(error);
  466. }
  467. };
  468. } else {
  469. return defaultF;
  470. }
  471. }
  472. this.callWhenSettled_(createCallback(onFulfilled, resolveChild), createCallback(onRejected, rejectChild));
  473. return childPromise;
  474. };
  475. PolyfillPromise.prototype['catch'] = function(onRejected) {
  476. return this.then(undefined, onRejected);
  477. };
  478. PolyfillPromise.prototype.callWhenSettled_ = function(onFulfilled, onRejected) {
  479. var thisPromise = this;
  480. function callback() {
  481. switch(thisPromise.state_) {
  482. case PromiseState.FULFILLED:
  483. onFulfilled(thisPromise.result_);
  484. break;
  485. case PromiseState.REJECTED:
  486. onRejected(thisPromise.result_);
  487. break;
  488. default:
  489. throw new Error('Unexpected state: ' + thisPromise.state_);
  490. }
  491. }
  492. if (this.onSettledCallbacks_ == null) {
  493. asyncExecutor.asyncExecute(callback);
  494. } else {
  495. this.onSettledCallbacks_.push(callback);
  496. }
  497. };
  498. function resolvingPromise(opt_value) {
  499. if (opt_value instanceof PolyfillPromise) {
  500. return opt_value;
  501. } else {
  502. return new PolyfillPromise(function(resolve, reject) {
  503. resolve(opt_value);
  504. });
  505. }
  506. }
  507. PolyfillPromise['resolve'] = resolvingPromise;
  508. PolyfillPromise['reject'] = function(opt_reason) {
  509. return new PolyfillPromise(function(resolve, reject) {
  510. reject(opt_reason);
  511. });
  512. };
  513. PolyfillPromise['race'] = function(thenablesOrValues) {
  514. return new PolyfillPromise(function(resolve, reject) {
  515. var iterator = $jscomp.makeIterator(thenablesOrValues);
  516. for (var iterRec = iterator.next(); !iterRec.done; iterRec = iterator.next()) {
  517. resolvingPromise(iterRec.value).callWhenSettled_(resolve, reject);
  518. }
  519. });
  520. };
  521. PolyfillPromise['all'] = function(thenablesOrValues) {
  522. var iterator = $jscomp.makeIterator(thenablesOrValues);
  523. var iterRec = iterator.next();
  524. if (iterRec.done) {
  525. return resolvingPromise([]);
  526. } else {
  527. return new PolyfillPromise(function(resolveAll, rejectAll) {
  528. var resultsArray = [];
  529. var unresolvedCount = 0;
  530. function onFulfilled(i) {
  531. return function(ithResult) {
  532. resultsArray[i] = ithResult;
  533. unresolvedCount--;
  534. if (unresolvedCount == 0) {
  535. resolveAll(resultsArray);
  536. }
  537. };
  538. }
  539. do {
  540. resultsArray.push(undefined);
  541. unresolvedCount++;
  542. resolvingPromise(iterRec.value).callWhenSettled_(onFulfilled(resultsArray.length - 1), rejectAll);
  543. iterRec = iterator.next();
  544. } while (!iterRec.done);
  545. });
  546. }
  547. };
  548. return PolyfillPromise;
  549. }, 'es6', 'es3');
  550. $jscomp.polyfill('Promise.prototype.finally', function(orig) {
  551. if (orig) {
  552. return orig;
  553. }
  554. var polyfill = function(onFinally) {
  555. return this.then(function(value) {
  556. var promise = Promise.resolve(onFinally());
  557. return promise.then(function() {
  558. return value;
  559. });
  560. }, function(reason) {
  561. var promise = Promise.resolve(onFinally());
  562. return promise.then(function() {
  563. throw reason;
  564. });
  565. });
  566. };
  567. return polyfill;
  568. }, 'es9', 'es3');
  569. $jscomp.underscoreProtoCanBeSet = function() {
  570. var x = {a:true};
  571. var y = {};
  572. try {
  573. y.__proto__ = x;
  574. return y.a;
  575. } catch (e) {
  576. }
  577. return false;
  578. };
  579. $jscomp.setPrototypeOf = typeof Object.setPrototypeOf == 'function' ? Object.setPrototypeOf : $jscomp.underscoreProtoCanBeSet() ? function(target, proto) {
  580. target.__proto__ = proto;
  581. if (target.__proto__ !== proto) {
  582. throw new TypeError(target + ' is not extensible');
  583. }
  584. return target;
  585. } : null;
  586. $jscomp.generator = {};
  587. $jscomp.generator.ensureIteratorResultIsObject_ = function(result) {
  588. if (result instanceof Object) {
  589. return;
  590. }
  591. throw new TypeError('Iterator result ' + result + ' is not an object');
  592. };
  593. $jscomp.generator.Context = function() {
  594. this.isRunning_ = false;
  595. this.yieldAllIterator_ = null;
  596. this.yieldResult = undefined;
  597. this.nextAddress = 1;
  598. this.catchAddress_ = 0;
  599. this.finallyAddress_ = 0;
  600. this.abruptCompletion_ = null;
  601. this.finallyContexts_ = null;
  602. };
  603. $jscomp.generator.Context.prototype.start_ = function() {
  604. if (this.isRunning_) {
  605. throw new TypeError('Generator is already running');
  606. }
  607. this.isRunning_ = true;
  608. };
  609. $jscomp.generator.Context.prototype.stop_ = function() {
  610. this.isRunning_ = false;
  611. };
  612. $jscomp.generator.Context.prototype.jumpToErrorHandler_ = function() {
  613. this.nextAddress = this.catchAddress_ || this.finallyAddress_;
  614. };
  615. $jscomp.generator.Context.prototype.next_ = function(value) {
  616. this.yieldResult = value;
  617. };
  618. $jscomp.generator.Context.prototype.throw_ = function(e) {
  619. this.abruptCompletion_ = {exception:e, isException:true};
  620. this.jumpToErrorHandler_();
  621. };
  622. $jscomp.generator.Context.prototype['return'] = function(value) {
  623. this.abruptCompletion_ = {'return':value};
  624. this.nextAddress = this.finallyAddress_;
  625. };
  626. $jscomp.generator.Context.prototype.jumpThroughFinallyBlocks = function(nextAddress) {
  627. this.abruptCompletion_ = {jumpTo:nextAddress};
  628. this.nextAddress = this.finallyAddress_;
  629. };
  630. $jscomp.generator.Context.prototype.yield = function(value, resumeAddress) {
  631. this.nextAddress = resumeAddress;
  632. return {value:value};
  633. };
  634. $jscomp.generator.Context.prototype.yieldAll = function(iterable, resumeAddress) {
  635. var iterator = $jscomp.makeIterator(iterable);
  636. var result = iterator.next();
  637. $jscomp.generator.ensureIteratorResultIsObject_(result);
  638. if (result.done) {
  639. this.yieldResult = result.value;
  640. this.nextAddress = resumeAddress;
  641. return;
  642. }
  643. this.yieldAllIterator_ = iterator;
  644. return this.yield(result.value, resumeAddress);
  645. };
  646. $jscomp.generator.Context.prototype.jumpTo = function(nextAddress) {
  647. this.nextAddress = nextAddress;
  648. };
  649. $jscomp.generator.Context.prototype.jumpToEnd = function() {
  650. this.nextAddress = 0;
  651. };
  652. $jscomp.generator.Context.prototype.setCatchFinallyBlocks = function(catchAddress, finallyAddress) {
  653. this.catchAddress_ = catchAddress;
  654. if (finallyAddress != undefined) {
  655. this.finallyAddress_ = finallyAddress;
  656. }
  657. };
  658. $jscomp.generator.Context.prototype.setFinallyBlock = function(finallyAddress) {
  659. this.catchAddress_ = 0;
  660. this.finallyAddress_ = finallyAddress || 0;
  661. };
  662. $jscomp.generator.Context.prototype.leaveTryBlock = function(nextAddress, catchAddress) {
  663. this.nextAddress = nextAddress;
  664. this.catchAddress_ = catchAddress || 0;
  665. };
  666. $jscomp.generator.Context.prototype.enterCatchBlock = function(nextCatchBlockAddress) {
  667. this.catchAddress_ = nextCatchBlockAddress || 0;
  668. var exception = this.abruptCompletion_.exception;
  669. this.abruptCompletion_ = null;
  670. return exception;
  671. };
  672. $jscomp.generator.Context.prototype.enterFinallyBlock = function(nextCatchAddress, nextFinallyAddress, finallyDepth) {
  673. if (!finallyDepth) {
  674. this.finallyContexts_ = [this.abruptCompletion_];
  675. } else {
  676. this.finallyContexts_[finallyDepth] = this.abruptCompletion_;
  677. }
  678. this.catchAddress_ = nextCatchAddress || 0;
  679. this.finallyAddress_ = nextFinallyAddress || 0;
  680. };
  681. $jscomp.generator.Context.prototype.leaveFinallyBlock = function(nextAddress, finallyDepth) {
  682. var preservedContext = this.finallyContexts_.splice(finallyDepth || 0)[0];
  683. var abruptCompletion = this.abruptCompletion_ = this.abruptCompletion_ || preservedContext;
  684. if (abruptCompletion) {
  685. if (abruptCompletion.isException) {
  686. return this.jumpToErrorHandler_();
  687. }
  688. if (abruptCompletion.jumpTo != undefined && this.finallyAddress_ < abruptCompletion.jumpTo) {
  689. this.nextAddress = abruptCompletion.jumpTo;
  690. this.abruptCompletion_ = null;
  691. } else {
  692. this.nextAddress = this.finallyAddress_;
  693. }
  694. } else {
  695. this.nextAddress = nextAddress;
  696. }
  697. };
  698. $jscomp.generator.Context.prototype.forIn = function(object) {
  699. return new $jscomp.generator.Context.PropertyIterator(object);
  700. };
  701. $jscomp.generator.Context.PropertyIterator = function(object) {
  702. this.object_ = object;
  703. this.properties_ = [];
  704. for (var property in object) {
  705. this.properties_.push(property);
  706. }
  707. this.properties_.reverse();
  708. };
  709. $jscomp.generator.Context.PropertyIterator.prototype.getNext = function() {
  710. while (this.properties_.length > 0) {
  711. var property = this.properties_.pop();
  712. if (property in this.object_) {
  713. return property;
  714. }
  715. }
  716. return null;
  717. };
  718. $jscomp.generator.Engine_ = function(program) {
  719. this.context_ = new $jscomp.generator.Context;
  720. this.program_ = program;
  721. };
  722. $jscomp.generator.Engine_.prototype.next_ = function(value) {
  723. this.context_.start_();
  724. if (this.context_.yieldAllIterator_) {
  725. return this.yieldAllStep_(this.context_.yieldAllIterator_.next, value, this.context_.next_);
  726. }
  727. this.context_.next_(value);
  728. return this.nextStep_();
  729. };
  730. $jscomp.generator.Engine_.prototype.return_ = function(value) {
  731. this.context_.start_();
  732. var yieldAllIterator = this.context_.yieldAllIterator_;
  733. if (yieldAllIterator) {
  734. var returnFunction = 'return' in yieldAllIterator ? yieldAllIterator['return'] : function(v) {
  735. return {value:v, done:true};
  736. };
  737. return this.yieldAllStep_(returnFunction, value, this.context_['return']);
  738. }
  739. this.context_['return'](value);
  740. return this.nextStep_();
  741. };
  742. $jscomp.generator.Engine_.prototype.throw_ = function(exception) {
  743. this.context_.start_();
  744. if (this.context_.yieldAllIterator_) {
  745. return this.yieldAllStep_(this.context_.yieldAllIterator_['throw'], exception, this.context_.next_);
  746. }
  747. this.context_.throw_(exception);
  748. return this.nextStep_();
  749. };
  750. $jscomp.generator.Engine_.prototype.yieldAllStep_ = function(action, value, nextAction) {
  751. try {
  752. var result = action.call(this.context_.yieldAllIterator_, value);
  753. $jscomp.generator.ensureIteratorResultIsObject_(result);
  754. if (!result.done) {
  755. this.context_.stop_();
  756. return result;
  757. }
  758. var resultValue = result.value;
  759. } catch (e) {
  760. this.context_.yieldAllIterator_ = null;
  761. this.context_.throw_(e);
  762. return this.nextStep_();
  763. }
  764. this.context_.yieldAllIterator_ = null;
  765. nextAction.call(this.context_, resultValue);
  766. return this.nextStep_();
  767. };
  768. $jscomp.generator.Engine_.prototype.nextStep_ = function() {
  769. while (this.context_.nextAddress) {
  770. try {
  771. var yieldValue = this.program_(this.context_);
  772. if (yieldValue) {
  773. this.context_.stop_();
  774. return {value:yieldValue.value, done:false};
  775. }
  776. } catch (e) {
  777. this.context_.yieldResult = undefined;
  778. this.context_.throw_(e);
  779. }
  780. }
  781. this.context_.stop_();
  782. if (this.context_.abruptCompletion_) {
  783. var abruptCompletion = this.context_.abruptCompletion_;
  784. this.context_.abruptCompletion_ = null;
  785. if (abruptCompletion.isException) {
  786. throw abruptCompletion.exception;
  787. }
  788. return {value:abruptCompletion['return'], done:true};
  789. }
  790. return {value:undefined, done:true};
  791. };
  792. $jscomp.generator.Generator_ = function(engine) {
  793. this.next = function(opt_value) {
  794. return engine.next_(opt_value);
  795. };
  796. this['throw'] = function(exception) {
  797. return engine.throw_(exception);
  798. };
  799. this['return'] = function(value) {
  800. return engine.return_(value);
  801. };
  802. $jscomp.initSymbolIterator();
  803. this[Symbol.iterator] = function() {
  804. return this;
  805. };
  806. };
  807. $jscomp.generator.createGenerator = function(generator, program) {
  808. var result = new $jscomp.generator.Generator_(new $jscomp.generator.Engine_(program));
  809. if ($jscomp.setPrototypeOf) {
  810. $jscomp.setPrototypeOf(result, generator.prototype);
  811. }
  812. return result;
  813. };
  814. $jscomp.asyncExecutePromiseGenerator = function(generator) {
  815. function passValueToGenerator(value) {
  816. return generator.next(value);
  817. }
  818. function passErrorToGenerator(error) {
  819. return generator['throw'](error);
  820. }
  821. return new Promise(function(resolve, reject) {
  822. function handleGeneratorRecord(genRec) {
  823. if (genRec.done) {
  824. resolve(genRec.value);
  825. } else {
  826. Promise.resolve(genRec.value).then(passValueToGenerator, passErrorToGenerator).then(handleGeneratorRecord, reject);
  827. }
  828. }
  829. handleGeneratorRecord(generator.next());
  830. });
  831. };
  832. $jscomp.asyncExecutePromiseGeneratorFunction = function(generatorFunction) {
  833. return $jscomp.asyncExecutePromiseGenerator(generatorFunction());
  834. };
  835. $jscomp.asyncExecutePromiseGeneratorProgram = function(program) {
  836. return $jscomp.asyncExecutePromiseGenerator(new $jscomp.generator.Generator_(new $jscomp.generator.Engine_(program)));
  837. };
  838. $jscomp.checkEs6ConformanceViaProxy = function() {
  839. try {
  840. var proxied = {};
  841. var proxy = Object.create(new $jscomp.global['Proxy'](proxied, {'get':function(target, key, receiver) {
  842. return target == proxied && key == 'q' && receiver == proxy;
  843. }}));
  844. return proxy['q'] === true;
  845. } catch (err) {
  846. return false;
  847. }
  848. };
  849. $jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS = false;
  850. $jscomp.ES6_CONFORMANCE = $jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS && $jscomp.checkEs6ConformanceViaProxy();
  851. $jscomp.owns = function(obj, prop) {
  852. return Object.prototype.hasOwnProperty.call(obj, prop);
  853. };
  854. $jscomp.polyfill('WeakMap', function(NativeWeakMap) {
  855. function isConformant() {
  856. if (!NativeWeakMap || !Object.seal) {
  857. return false;
  858. }
  859. try {
  860. var x = Object.seal({});
  861. var y = Object.seal({});
  862. var map = new NativeWeakMap([[x, 2], [y, 3]]);
  863. if (map.get(x) != 2 || map.get(y) != 3) {
  864. return false;
  865. }
  866. map['delete'](x);
  867. map.set(y, 4);
  868. return !map.has(x) && map.get(y) == 4;
  869. } catch (err) {
  870. return false;
  871. }
  872. }
  873. if ($jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS) {
  874. if (NativeWeakMap && $jscomp.ES6_CONFORMANCE) {
  875. return NativeWeakMap;
  876. }
  877. } else {
  878. if (isConformant()) {
  879. return NativeWeakMap;
  880. }
  881. }
  882. var prop = '$jscomp_hidden_' + Math.random();
  883. function insert(target) {
  884. if (!$jscomp.owns(target, prop)) {
  885. var obj = {};
  886. $jscomp.defineProperty(target, prop, {value:obj});
  887. }
  888. }
  889. function patch(name) {
  890. var prev = Object[name];
  891. if (prev) {
  892. Object[name] = function(target) {
  893. insert(target);
  894. return prev(target);
  895. };
  896. }
  897. }
  898. patch('freeze');
  899. patch('preventExtensions');
  900. patch('seal');
  901. var index = 0;
  902. var PolyfillWeakMap = function(opt_iterable) {
  903. this.id_ = (index += Math.random() + 1).toString();
  904. if (opt_iterable) {
  905. $jscomp.initSymbol();
  906. $jscomp.initSymbolIterator();
  907. var iter = $jscomp.makeIterator(opt_iterable);
  908. var entry;
  909. while (!(entry = iter.next()).done) {
  910. var item = entry.value;
  911. this.set(item[0], item[1]);
  912. }
  913. }
  914. };
  915. PolyfillWeakMap.prototype.set = function(key, value) {
  916. insert(key);
  917. if (!$jscomp.owns(key, prop)) {
  918. throw new Error('WeakMap key fail: ' + key);
  919. }
  920. key[prop][this.id_] = value;
  921. return this;
  922. };
  923. PolyfillWeakMap.prototype.get = function(key) {
  924. return $jscomp.owns(key, prop) ? key[prop][this.id_] : undefined;
  925. };
  926. PolyfillWeakMap.prototype.has = function(key) {
  927. return $jscomp.owns(key, prop) && $jscomp.owns(key[prop], this.id_);
  928. };
  929. PolyfillWeakMap.prototype['delete'] = function(key) {
  930. if (!$jscomp.owns(key, prop) || !$jscomp.owns(key[prop], this.id_)) {
  931. return false;
  932. }
  933. return delete key[prop][this.id_];
  934. };
  935. return PolyfillWeakMap;
  936. }, 'es6', 'es3');
  937. $jscomp.MapEntry = function() {
  938. this.previous;
  939. this.next;
  940. this.head;
  941. this.key;
  942. this.value;
  943. };
  944. $jscomp.polyfill('Map', function(NativeMap) {
  945. function isConformant() {
  946. if ($jscomp.ASSUME_NO_NATIVE_MAP || !NativeMap || typeof NativeMap != 'function' || !NativeMap.prototype.entries || typeof Object.seal != 'function') {
  947. return false;
  948. }
  949. try {
  950. NativeMap = NativeMap;
  951. var key = Object.seal({x:4});
  952. var map = new NativeMap($jscomp.makeIterator([[key, 's']]));
  953. if (map.get(key) != 's' || map.size != 1 || map.get({x:4}) || map.set({x:4}, 't') != map || map.size != 2) {
  954. return false;
  955. }
  956. var iter = map.entries();
  957. var item = iter.next();
  958. if (item.done || item.value[0] != key || item.value[1] != 's') {
  959. return false;
  960. }
  961. item = iter.next();
  962. if (item.done || item.value[0].x != 4 || item.value[1] != 't' || !iter.next().done) {
  963. return false;
  964. }
  965. return true;
  966. } catch (err) {
  967. return false;
  968. }
  969. }
  970. if ($jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS) {
  971. if (NativeMap && $jscomp.ES6_CONFORMANCE) {
  972. return NativeMap;
  973. }
  974. } else {
  975. if (isConformant()) {
  976. return NativeMap;
  977. }
  978. }
  979. $jscomp.initSymbol();
  980. $jscomp.initSymbolIterator();
  981. var idMap = new WeakMap;
  982. var PolyfillMap = function(opt_iterable) {
  983. this.data_ = {};
  984. this.head_ = createHead();
  985. this.size = 0;
  986. if (opt_iterable) {
  987. var iter = $jscomp.makeIterator(opt_iterable);
  988. var entry;
  989. while (!(entry = iter.next()).done) {
  990. var item = entry.value;
  991. this.set(item[0], item[1]);
  992. }
  993. }
  994. };
  995. PolyfillMap.prototype.set = function(key, value) {
  996. key = key === 0 ? 0 : key;
  997. var r = maybeGetEntry(this, key);
  998. if (!r.list) {
  999. r.list = this.data_[r.id] = [];
  1000. }
  1001. if (!r.entry) {
  1002. r.entry = {next:this.head_, previous:this.head_.previous, head:this.head_, key:key, value:value};
  1003. r.list.push(r.entry);
  1004. this.head_.previous.next = r.entry;
  1005. this.head_.previous = r.entry;
  1006. this.size++;
  1007. } else {
  1008. r.entry.value = value;
  1009. }
  1010. return this;
  1011. };
  1012. PolyfillMap.prototype['delete'] = function(key) {
  1013. var r = maybeGetEntry(this, key);
  1014. if (r.entry && r.list) {
  1015. r.list.splice(r.index, 1);
  1016. if (!r.list.length) {
  1017. delete this.data_[r.id];
  1018. }
  1019. r.entry.previous.next = r.entry.next;
  1020. r.entry.next.previous = r.entry.previous;
  1021. r.entry.head = null;
  1022. this.size--;
  1023. return true;
  1024. }
  1025. return false;
  1026. };
  1027. PolyfillMap.prototype.clear = function() {
  1028. this.data_ = {};
  1029. this.head_ = this.head_.previous = createHead();
  1030. this.size = 0;
  1031. };
  1032. PolyfillMap.prototype.has = function(key) {
  1033. return !!maybeGetEntry(this, key).entry;
  1034. };
  1035. PolyfillMap.prototype.get = function(key) {
  1036. var entry = maybeGetEntry(this, key).entry;
  1037. return entry && entry.value;
  1038. };
  1039. PolyfillMap.prototype.entries = function() {
  1040. return makeIterator(this, function(entry) {
  1041. return [entry.key, entry.value];
  1042. });
  1043. };
  1044. PolyfillMap.prototype.keys = function() {
  1045. return makeIterator(this, function(entry) {
  1046. return entry.key;
  1047. });
  1048. };
  1049. PolyfillMap.prototype.values = function() {
  1050. return makeIterator(this, function(entry) {
  1051. return entry.value;
  1052. });
  1053. };
  1054. PolyfillMap.prototype.forEach = function(callback, opt_thisArg) {
  1055. var iter = this.entries();
  1056. var item;
  1057. while (!(item = iter.next()).done) {
  1058. var entry = item.value;
  1059. callback.call(opt_thisArg, entry[1], entry[0], this);
  1060. }
  1061. };
  1062. PolyfillMap.prototype[Symbol.iterator] = PolyfillMap.prototype.entries;
  1063. var maybeGetEntry = function(map, key) {
  1064. var id = getId(key);
  1065. var list = map.data_[id];
  1066. if (list && $jscomp.owns(map.data_, id)) {
  1067. for (var index = 0; index < list.length; index++) {
  1068. var entry = list[index];
  1069. if (key !== key && entry.key !== entry.key || key === entry.key) {
  1070. return {id:id, list:list, index:index, entry:entry};
  1071. }
  1072. }
  1073. }
  1074. return {id:id, list:list, index:-1, entry:undefined};
  1075. };
  1076. var makeIterator = function(map, func) {
  1077. var entry = map.head_;
  1078. return $jscomp.iteratorPrototype(function() {
  1079. if (entry) {
  1080. while (entry.head != map.head_) {
  1081. entry = entry.previous;
  1082. }
  1083. while (entry.next != entry.head) {
  1084. entry = entry.next;
  1085. return {done:false, value:func(entry)};
  1086. }
  1087. entry = null;
  1088. }
  1089. return {done:true, value:void 0};
  1090. });
  1091. };
  1092. var createHead = function() {
  1093. var head = {};
  1094. head.previous = head.next = head.head = head;
  1095. return head;
  1096. };
  1097. var mapIndex = 0;
  1098. var getId = function(obj) {
  1099. var type = obj && typeof obj;
  1100. if (type == 'object' || type == 'function') {
  1101. obj = obj;
  1102. if (!idMap.has(obj)) {
  1103. var id = '' + ++mapIndex;
  1104. idMap.set(obj, id);
  1105. return id;
  1106. }
  1107. return idMap.get(obj);
  1108. }
  1109. return 'p_' + obj;
  1110. };
  1111. return PolyfillMap;
  1112. }, 'es6', 'es3');
  1113. $jscomp.polyfill('Math.acosh', function(orig) {
  1114. if (orig) {
  1115. return orig;
  1116. }
  1117. var polyfill = function(x) {
  1118. x = Number(x);
  1119. return Math.log(x + Math.sqrt(x * x - 1));
  1120. };
  1121. return polyfill;
  1122. }, 'es6', 'es3');
  1123. $jscomp.polyfill('Math.asinh', function(orig) {
  1124. if (orig) {
  1125. return orig;
  1126. }
  1127. var polyfill = function(x) {
  1128. x = Number(x);
  1129. if (x === 0) {
  1130. return x;
  1131. }
  1132. var y = Math.log(Math.abs(x) + Math.sqrt(x * x + 1));
  1133. return x < 0 ? -y : y;
  1134. };
  1135. return polyfill;
  1136. }, 'es6', 'es3');
  1137. $jscomp.polyfill('Math.log1p', function(orig) {
  1138. if (orig) {
  1139. return orig;
  1140. }
  1141. var polyfill = function(x) {
  1142. x = Number(x);
  1143. if (x < 0.25 && x > -0.25) {
  1144. var y = x;
  1145. var d = 1;
  1146. var z = x;
  1147. var zPrev = 0;
  1148. var s = 1;
  1149. while (zPrev != z) {
  1150. y *= x;
  1151. s *= -1;
  1152. z = (zPrev = z) + s * y / ++d;
  1153. }
  1154. return z;
  1155. }
  1156. return Math.log(1 + x);
  1157. };
  1158. return polyfill;
  1159. }, 'es6', 'es3');
  1160. $jscomp.polyfill('Math.atanh', function(orig) {
  1161. if (orig) {
  1162. return orig;
  1163. }
  1164. var log1p = Math.log1p;
  1165. var polyfill = function(x) {
  1166. x = Number(x);
  1167. return (log1p(x) - log1p(-x)) / 2;
  1168. };
  1169. return polyfill;
  1170. }, 'es6', 'es3');
  1171. $jscomp.polyfill('Math.cbrt', function(orig) {
  1172. if (orig) {
  1173. return orig;
  1174. }
  1175. var polyfill = function(x) {
  1176. if (x === 0) {
  1177. return x;
  1178. }
  1179. x = Number(x);
  1180. var y = Math.pow(Math.abs(x), 1 / 3);
  1181. return x < 0 ? -y : y;
  1182. };
  1183. return polyfill;
  1184. }, 'es6', 'es3');
  1185. $jscomp.polyfill('Math.clz32', function(orig) {
  1186. if (orig) {
  1187. return orig;
  1188. }
  1189. var polyfill = function(x) {
  1190. x = Number(x) >>> 0;
  1191. if (x === 0) {
  1192. return 32;
  1193. }
  1194. var result = 0;
  1195. if ((x & 4294901760) === 0) {
  1196. x <<= 16;
  1197. result += 16;
  1198. }
  1199. if ((x & 4278190080) === 0) {
  1200. x <<= 8;
  1201. result += 8;
  1202. }
  1203. if ((x & 4026531840) === 0) {
  1204. x <<= 4;
  1205. result += 4;
  1206. }
  1207. if ((x & 3221225472) === 0) {
  1208. x <<= 2;
  1209. result += 2;
  1210. }
  1211. if ((x & 2147483648) === 0) {
  1212. result++;
  1213. }
  1214. return result;
  1215. };
  1216. return polyfill;
  1217. }, 'es6', 'es3');
  1218. $jscomp.polyfill('Math.cosh', function(orig) {
  1219. if (orig) {
  1220. return orig;
  1221. }
  1222. var exp = Math.exp;
  1223. var polyfill = function(x) {
  1224. x = Number(x);
  1225. return (exp(x) + exp(-x)) / 2;
  1226. };
  1227. return polyfill;
  1228. }, 'es6', 'es3');
  1229. $jscomp.polyfill('Math.expm1', function(orig) {
  1230. if (orig) {
  1231. return orig;
  1232. }
  1233. var polyfill = function(x) {
  1234. x = Number(x);
  1235. if (x < .25 && x > -.25) {
  1236. var y = x;
  1237. var d = 1;
  1238. var z = x;
  1239. var zPrev = 0;
  1240. while (zPrev != z) {
  1241. y *= x / ++d;
  1242. z = (zPrev = z) + y;
  1243. }
  1244. return z;
  1245. }
  1246. return Math.exp(x) - 1;
  1247. };
  1248. return polyfill;
  1249. }, 'es6', 'es3');
  1250. $jscomp.polyfill('Math.hypot', function(orig) {
  1251. if (orig) {
  1252. return orig;
  1253. }
  1254. var polyfill = function(x, y, var_args) {
  1255. x = Number(x);
  1256. y = Number(y);
  1257. var i, z, sum;
  1258. var max = Math.max(Math.abs(x), Math.abs(y));
  1259. for (i = 2; i < arguments.length; i++) {
  1260. max = Math.max(max, Math.abs(arguments[i]));
  1261. }
  1262. if (max > 1e100 || max < 1e-100) {
  1263. if (!max) {
  1264. return max;
  1265. }
  1266. x = x / max;
  1267. y = y / max;
  1268. sum = x * x + y * y;
  1269. for (i = 2; i < arguments.length; i++) {
  1270. z = Number(arguments[i]) / max;
  1271. sum += z * z;
  1272. }
  1273. return Math.sqrt(sum) * max;
  1274. } else {
  1275. sum = x * x + y * y;
  1276. for (i = 2; i < arguments.length; i++) {
  1277. z = Number(arguments[i]);
  1278. sum += z * z;
  1279. }
  1280. return Math.sqrt(sum);
  1281. }
  1282. };
  1283. return polyfill;
  1284. }, 'es6', 'es3');
  1285. $jscomp.polyfill('Math.imul', function(orig) {
  1286. if (orig) {
  1287. return orig;
  1288. }
  1289. var polyfill = function(a, b) {
  1290. a = Number(a);
  1291. b = Number(b);
  1292. var ah = a >>> 16 & 65535;
  1293. var al = a & 65535;
  1294. var bh = b >>> 16 & 65535;
  1295. var bl = b & 65535;
  1296. var lh = ah * bl + al * bh << 16 >>> 0;
  1297. return al * bl + lh | 0;
  1298. };
  1299. return polyfill;
  1300. }, 'es6', 'es3');
  1301. $jscomp.polyfill('Math.log10', function(orig) {
  1302. if (orig) {
  1303. return orig;
  1304. }
  1305. var polyfill = function(x) {
  1306. return Math.log(x) / Math.LN10;
  1307. };
  1308. return polyfill;
  1309. }, 'es6', 'es3');
  1310. $jscomp.polyfill('Math.log2', function(orig) {
  1311. if (orig) {
  1312. return orig;
  1313. }
  1314. var polyfill = function(x) {
  1315. return Math.log(x) / Math.LN2;
  1316. };
  1317. return polyfill;
  1318. }, 'es6', 'es3');
  1319. $jscomp.polyfill('Math.sign', function(orig) {
  1320. if (orig) {
  1321. return orig;
  1322. }
  1323. var polyfill = function(x) {
  1324. x = Number(x);
  1325. return x === 0 || isNaN(x) ? x : x > 0 ? 1 : -1;
  1326. };
  1327. return polyfill;
  1328. }, 'es6', 'es3');
  1329. $jscomp.polyfill('Math.sinh', function(orig) {
  1330. if (orig) {
  1331. return orig;
  1332. }
  1333. var exp = Math.exp;
  1334. var polyfill = function(x) {
  1335. x = Number(x);
  1336. if (x === 0) {
  1337. return x;
  1338. }
  1339. return (exp(x) - exp(-x)) / 2;
  1340. };
  1341. return polyfill;
  1342. }, 'es6', 'es3');
  1343. $jscomp.polyfill('Math.tanh', function(orig) {
  1344. if (orig) {
  1345. return orig;
  1346. }
  1347. var polyfill = function(x) {
  1348. x = Number(x);
  1349. if (x === 0) {
  1350. return x;
  1351. }
  1352. var y = Math.exp(-2 * Math.abs(x));
  1353. var z = (1 - y) / (1 + y);
  1354. return x < 0 ? -z : z;
  1355. };
  1356. return polyfill;
  1357. }, 'es6', 'es3');
  1358. $jscomp.polyfill('Math.trunc', function(orig) {
  1359. if (orig) {
  1360. return orig;
  1361. }
  1362. var polyfill = function(x) {
  1363. x = Number(x);
  1364. if (isNaN(x) || x === Infinity || x === -Infinity || x === 0) {
  1365. return x;
  1366. }
  1367. var y = Math.floor(Math.abs(x));
  1368. return x < 0 ? -y : y;
  1369. };
  1370. return polyfill;
  1371. }, 'es6', 'es3');
  1372. $jscomp.polyfill('Number.EPSILON', function(orig) {
  1373. return Math.pow(2, -52);
  1374. }, 'es6', 'es3');
  1375. $jscomp.polyfill('Number.MAX_SAFE_INTEGER', function() {
  1376. return 9007199254740991;
  1377. }, 'es6', 'es3');
  1378. $jscomp.polyfill('Number.MIN_SAFE_INTEGER', function() {
  1379. return -9007199254740991;
  1380. }, 'es6', 'es3');
  1381. $jscomp.polyfill('Number.isFinite', function(orig) {
  1382. if (orig) {
  1383. return orig;
  1384. }
  1385. var polyfill = function(x) {
  1386. if (typeof x !== 'number') {
  1387. return false;
  1388. }
  1389. return !isNaN(x) && x !== Infinity && x !== -Infinity;
  1390. };
  1391. return polyfill;
  1392. }, 'es6', 'es3');
  1393. $jscomp.polyfill('Number.isInteger', function(orig) {
  1394. if (orig) {
  1395. return orig;
  1396. }
  1397. var polyfill = function(x) {
  1398. if (!Number.isFinite(x)) {
  1399. return false;
  1400. }
  1401. return x === Math.floor(x);
  1402. };
  1403. return polyfill;
  1404. }, 'es6', 'es3');
  1405. $jscomp.polyfill('Number.isNaN', function(orig) {
  1406. if (orig) {
  1407. return orig;
  1408. }
  1409. var polyfill = function(x) {
  1410. return typeof x === 'number' && isNaN(x);
  1411. };
  1412. return polyfill;
  1413. }, 'es6', 'es3');
  1414. $jscomp.polyfill('Number.isSafeInteger', function(orig) {
  1415. if (orig) {
  1416. return orig;
  1417. }
  1418. var polyfill = function(x) {
  1419. return Number.isInteger(x) && Math.abs(x) <= Number.MAX_SAFE_INTEGER;
  1420. };
  1421. return polyfill;
  1422. }, 'es6', 'es3');
  1423. $jscomp.polyfill('Number.parseFloat', function(orig) {
  1424. return orig || parseFloat;
  1425. }, 'es6', 'es3');
  1426. $jscomp.polyfill('Number.parseInt', function(orig) {
  1427. return orig || parseInt;
  1428. }, 'es6', 'es3');
  1429. $jscomp.assign = typeof Object.assign == 'function' ? Object.assign : function(target, var_args) {
  1430. for (var i = 1; i < arguments.length; i++) {
  1431. var source = arguments[i];
  1432. if (!source) {
  1433. continue;
  1434. }
  1435. for (var key in source) {
  1436. if ($jscomp.owns(source, key)) {
  1437. target[key] = source[key];
  1438. }
  1439. }
  1440. }
  1441. return target;
  1442. };
  1443. $jscomp.polyfill('Object.assign', function(orig) {
  1444. return orig || $jscomp.assign;
  1445. }, 'es6', 'es3');
  1446. $jscomp.polyfill('Object.entries', function(orig) {
  1447. if (orig) {
  1448. return orig;
  1449. }
  1450. var entries = function(obj) {
  1451. var result = [];
  1452. for (var key in obj) {
  1453. if ($jscomp.owns(obj, key)) {
  1454. result.push([key, obj[key]]);
  1455. }
  1456. }
  1457. return result;
  1458. };
  1459. return entries;
  1460. }, 'es8', 'es3');
  1461. $jscomp.polyfill('Object.getOwnPropertySymbols', function(orig) {
  1462. if (orig) {
  1463. return orig;
  1464. }
  1465. return function() {
  1466. return [];
  1467. };
  1468. }, 'es6', 'es5');
  1469. $jscomp.polyfill('Reflect.ownKeys', function(orig) {
  1470. if (orig) {
  1471. return orig;
  1472. }
  1473. var symbolPrefix = 'jscomp_symbol_';
  1474. function isSymbol(key) {
  1475. return key.substring(0, symbolPrefix.length) == symbolPrefix;
  1476. }
  1477. var polyfill = function(target) {
  1478. var keys = [];
  1479. var names = Object.getOwnPropertyNames(target);
  1480. var symbols = Object.getOwnPropertySymbols(target);
  1481. for (var i = 0; i < names.length; i++) {
  1482. (isSymbol(names[i]) ? symbols : keys).push(names[i]);
  1483. }
  1484. return keys.concat(symbols);
  1485. };
  1486. return polyfill;
  1487. }, 'es6', 'es5');
  1488. $jscomp.polyfill('Object.getOwnPropertyDescriptors', function(orig) {
  1489. if (orig) {
  1490. return orig;
  1491. }
  1492. var getOwnPropertyDescriptors = function(obj) {
  1493. var result = {};
  1494. var keys = Reflect.ownKeys(obj);
  1495. for (var i = 0; i < keys.length; i++) {
  1496. result[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  1497. }
  1498. return result;
  1499. };
  1500. return getOwnPropertyDescriptors;
  1501. }, 'es8', 'es5');
  1502. $jscomp.polyfill('Object.setPrototypeOf', function(orig) {
  1503. return orig || $jscomp.setPrototypeOf;
  1504. }, 'es6', 'es5');
  1505. $jscomp.polyfill('Object.values', function(orig) {
  1506. if (orig) {
  1507. return orig;
  1508. }
  1509. var values = function(obj) {
  1510. var result = [];
  1511. for (var key in obj) {
  1512. if ($jscomp.owns(obj, key)) {
  1513. result.push(obj[key]);
  1514. }
  1515. }
  1516. return result;
  1517. };
  1518. return values;
  1519. }, 'es8', 'es3');
  1520. $jscomp.polyfill('Reflect.apply', function(orig) {
  1521. if (orig) {
  1522. return orig;
  1523. }
  1524. var apply = Function.prototype.apply;
  1525. var polyfill = function(target, thisArg, argList) {
  1526. return apply.call(target, thisArg, argList);
  1527. };
  1528. return polyfill;
  1529. }, 'es6', 'es3');
  1530. $jscomp.objectCreate = $jscomp.ASSUME_ES5 || typeof Object.create == 'function' ? Object.create : function(prototype) {
  1531. var ctor = function() {
  1532. };
  1533. ctor.prototype = prototype;
  1534. return new ctor;
  1535. };
  1536. $jscomp.construct = function() {
  1537. function reflectConstructWorks() {
  1538. function Base() {
  1539. }
  1540. function Derived() {
  1541. }
  1542. new Base;
  1543. Reflect.construct(Base, [], Derived);
  1544. return new Base instanceof Base;
  1545. }
  1546. if (typeof Reflect != 'undefined' && Reflect.construct) {
  1547. if (reflectConstructWorks()) {
  1548. return Reflect.construct;
  1549. }
  1550. var brokenConstruct = Reflect.construct;
  1551. var patchedConstruct = function(target, argList, opt_newTarget) {
  1552. var out = brokenConstruct(target, argList);
  1553. if (opt_newTarget) {
  1554. Reflect.setPrototypeOf(out, opt_newTarget.prototype);
  1555. }
  1556. return out;
  1557. };
  1558. return patchedConstruct;
  1559. }
  1560. function construct(target, argList, opt_newTarget) {
  1561. if (opt_newTarget === undefined) {
  1562. opt_newTarget = target;
  1563. }
  1564. var proto = opt_newTarget.prototype || Object.prototype;
  1565. var obj = $jscomp.objectCreate(proto);
  1566. var apply = Function.prototype.apply;
  1567. var out = apply.call(target, obj, argList);
  1568. return out || obj;
  1569. }
  1570. return construct;
  1571. }();
  1572. $jscomp.polyfill('Reflect.construct', function(orig) {
  1573. return $jscomp.construct;
  1574. }, 'es6', 'es3');
  1575. $jscomp.polyfill('Reflect.defineProperty', function(orig) {
  1576. if (orig) {
  1577. return orig;
  1578. }
  1579. var polyfill = function(target, propertyKey, attributes) {
  1580. try {
  1581. Object.defineProperty(target, propertyKey, attributes);
  1582. var desc = Object.getOwnPropertyDescriptor(target, propertyKey);
  1583. if (!desc) {
  1584. return false;
  1585. }
  1586. return desc.configurable === (attributes.configurable || false) && desc.enumerable === (attributes.enumerable || false) && ('value' in desc ? desc.value === attributes.value && desc.writable === (attributes.writable || false) : desc.get === attributes.get && desc.set === attributes.set);
  1587. } catch (err) {
  1588. return false;
  1589. }
  1590. };
  1591. return polyfill;
  1592. }, 'es6', 'es5');
  1593. $jscomp.polyfill('Reflect.deleteProperty', function(orig) {
  1594. if (orig) {
  1595. return orig;
  1596. }
  1597. var polyfill = function(target, propertyKey) {
  1598. if (!$jscomp.owns(target, propertyKey)) {
  1599. return true;
  1600. }
  1601. try {
  1602. return delete target[propertyKey];
  1603. } catch (err) {
  1604. return false;
  1605. }
  1606. };
  1607. return polyfill;
  1608. }, 'es6', 'es3');
  1609. $jscomp.polyfill('Reflect.getOwnPropertyDescriptor', function(orig) {
  1610. return orig || Object.getOwnPropertyDescriptor;
  1611. }, 'es6', 'es5');
  1612. $jscomp.polyfill('Reflect.getPrototypeOf', function(orig) {
  1613. return orig || Object.getPrototypeOf;
  1614. }, 'es6', 'es5');
  1615. $jscomp.findDescriptor = function(target, propertyKey) {
  1616. var obj = target;
  1617. while (obj) {
  1618. var property = Reflect.getOwnPropertyDescriptor(obj, propertyKey);
  1619. if (property) {
  1620. return property;
  1621. }
  1622. obj = Reflect.getPrototypeOf(obj);
  1623. }
  1624. return undefined;
  1625. };
  1626. $jscomp.polyfill('Reflect.get', function(orig) {
  1627. if (orig) {
  1628. return orig;
  1629. }
  1630. var polyfill = function(target, propertyKey, opt_receiver) {
  1631. if (arguments.length <= 2) {
  1632. return target[propertyKey];
  1633. }
  1634. var property = $jscomp.findDescriptor(target, propertyKey);
  1635. if (property) {
  1636. return property.get ? property.get.call(opt_receiver) : property.value;
  1637. }
  1638. return undefined;
  1639. };
  1640. return polyfill;
  1641. }, 'es6', 'es5');
  1642. $jscomp.polyfill('Reflect.has', function(orig) {
  1643. if (orig) {
  1644. return orig;
  1645. }
  1646. var polyfill = function(target, propertyKey) {
  1647. return propertyKey in target;
  1648. };
  1649. return polyfill;
  1650. }, 'es6', 'es3');
  1651. $jscomp.polyfill('Reflect.isExtensible', function(orig) {
  1652. if (orig) {
  1653. return orig;
  1654. }
  1655. if ($jscomp.ASSUME_ES5 || typeof Object.isExtensible == 'function') {
  1656. return Object.isExtensible;
  1657. }
  1658. return function() {
  1659. return true;
  1660. };
  1661. }, 'es6', 'es3');
  1662. $jscomp.polyfill('Reflect.preventExtensions', function(orig) {
  1663. if (orig) {
  1664. return orig;
  1665. }
  1666. if (!($jscomp.ASSUME_ES5 || typeof Object.preventExtensions == 'function')) {
  1667. return function() {
  1668. return false;
  1669. };
  1670. }
  1671. var polyfill = function(target) {
  1672. Object.preventExtensions(target);
  1673. return !Object.isExtensible(target);
  1674. };
  1675. return polyfill;
  1676. }, 'es6', 'es3');
  1677. $jscomp.polyfill('Reflect.set', function(orig) {
  1678. if (orig) {
  1679. return orig;
  1680. }
  1681. var polyfill = function(target, propertyKey, value, opt_receiver) {
  1682. var property = $jscomp.findDescriptor(target, propertyKey);
  1683. if (!property) {
  1684. if (Reflect.isExtensible(target)) {
  1685. target[propertyKey] = value;
  1686. return true;
  1687. }
  1688. return false;
  1689. }
  1690. if (property.set) {
  1691. property.set.call(arguments.length > 3 ? opt_receiver : target, value);
  1692. return true;
  1693. } else {
  1694. if (property.writable && !Object.isFrozen(target)) {
  1695. target[propertyKey] = value;
  1696. return true;
  1697. }
  1698. }
  1699. return false;
  1700. };
  1701. return polyfill;
  1702. }, 'es6', 'es5');
  1703. $jscomp.polyfill('Reflect.setPrototypeOf', function(orig) {
  1704. if (orig) {
  1705. return orig;
  1706. } else {
  1707. if ($jscomp.setPrototypeOf) {
  1708. var setPrototypeOf = $jscomp.setPrototypeOf;
  1709. var polyfill = function(target, proto) {
  1710. try {
  1711. setPrototypeOf(target, proto);
  1712. return true;
  1713. } catch (e) {
  1714. return false;
  1715. }
  1716. };
  1717. return polyfill;
  1718. } else {
  1719. return null;
  1720. }
  1721. }
  1722. }, 'es6', 'es5');
  1723. $jscomp.polyfill('Set', function(NativeSet) {
  1724. function isConformant() {
  1725. if ($jscomp.ASSUME_NO_NATIVE_SET || !NativeSet || typeof NativeSet != 'function' || !NativeSet.prototype.entries || typeof Object.seal != 'function') {
  1726. return false;
  1727. }
  1728. try {
  1729. NativeSet = NativeSet;
  1730. var value = Object.seal({x:4});
  1731. var set = new NativeSet($jscomp.makeIterator([value]));
  1732. if (!set.has(value) || set.size != 1 || set.add(value) != set || set.size != 1 || set.add({x:4}) != set || set.size != 2) {
  1733. return false;
  1734. }
  1735. var iter = set.entries();
  1736. var item = iter.next();
  1737. if (item.done || item.value[0] != value || item.value[1] != value) {
  1738. return false;
  1739. }
  1740. item = iter.next();
  1741. if (item.done || item.value[0] == value || item.value[0].x != 4 || item.value[1] != item.value[0]) {
  1742. return false;
  1743. }
  1744. return iter.next().done;
  1745. } catch (err) {
  1746. return false;
  1747. }
  1748. }
  1749. if ($jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS) {
  1750. if (NativeSet && $jscomp.ES6_CONFORMANCE) {
  1751. return NativeSet;
  1752. }
  1753. } else {
  1754. if (isConformant()) {
  1755. return NativeSet;
  1756. }
  1757. }
  1758. $jscomp.initSymbol();
  1759. $jscomp.initSymbolIterator();
  1760. var PolyfillSet = function(opt_iterable) {
  1761. this.map_ = new Map;
  1762. if (opt_iterable) {
  1763. var iter = $jscomp.makeIterator(opt_iterable);
  1764. var entry;
  1765. while (!(entry = iter.next()).done) {
  1766. var item = entry.value;
  1767. this.add(item);
  1768. }
  1769. }
  1770. this.size = this.map_.size;
  1771. };
  1772. PolyfillSet.prototype.add = function(value) {
  1773. value = value === 0 ? 0 : value;
  1774. this.map_.set(value, value);
  1775. this.size = this.map_.size;
  1776. return this;
  1777. };
  1778. PolyfillSet.prototype['delete'] = function(value) {
  1779. var result = this.map_['delete'](value);
  1780. this.size = this.map_.size;
  1781. return result;
  1782. };
  1783. PolyfillSet.prototype.clear = function() {
  1784. this.map_.clear();
  1785. this.size = 0;
  1786. };
  1787. PolyfillSet.prototype.has = function(value) {
  1788. return this.map_.has(value);
  1789. };
  1790. PolyfillSet.prototype.entries = function() {
  1791. return this.map_.entries();
  1792. };
  1793. PolyfillSet.prototype.values = function() {
  1794. return this.map_.values();
  1795. };
  1796. PolyfillSet.prototype.keys = PolyfillSet.prototype.values;
  1797. PolyfillSet.prototype[Symbol.iterator] = PolyfillSet.prototype.values;
  1798. PolyfillSet.prototype.forEach = function(callback, opt_thisArg) {
  1799. var set = this;
  1800. this.map_.forEach(function(value) {
  1801. return callback.call(opt_thisArg, value, value, set);
  1802. });
  1803. };
  1804. return PolyfillSet;
  1805. }, 'es6', 'es3');
  1806. $jscomp.checkStringArgs = function(thisArg, arg, func) {
  1807. if (thisArg == null) {
  1808. throw new TypeError("The 'this' value for String.prototype." + func + ' must not be null or undefined');
  1809. }
  1810. if (arg instanceof RegExp) {
  1811. throw new TypeError('First argument to String.prototype.' + func + ' must not be a regular expression');
  1812. }
  1813. return thisArg + '';
  1814. };
  1815. $jscomp.polyfill('String.prototype.codePointAt', function(orig) {
  1816. if (orig) {
  1817. return orig;
  1818. }
  1819. var polyfill = function(position) {
  1820. var string = $jscomp.checkStringArgs(this, null, 'codePointAt');
  1821. var size = string.length;
  1822. position = Number(position) || 0;
  1823. if (!(position >= 0 && position < size)) {
  1824. return void 0;
  1825. }
  1826. position = position | 0;
  1827. var first = string.charCodeAt(position);
  1828. if (first < 55296 || first > 56319 || position + 1 === size) {
  1829. return first;
  1830. }
  1831. var second = string.charCodeAt(position + 1);
  1832. if (second < 56320 || second > 57343) {
  1833. return first;
  1834. }
  1835. return (first - 55296) * 1024 + second + 9216;
  1836. };
  1837. return polyfill;
  1838. }, 'es6', 'es3');
  1839. $jscomp.polyfill('String.prototype.endsWith', function(orig) {
  1840. if (orig) {
  1841. return orig;
  1842. }
  1843. var polyfill = function(searchString, opt_position) {
  1844. var string = $jscomp.checkStringArgs(this, searchString, 'endsWith');
  1845. searchString = searchString + '';
  1846. if (opt_position === void 0) {
  1847. opt_position = string.length;
  1848. }
  1849. var i = Math.max(0, Math.min(opt_position | 0, string.length));
  1850. var j = searchString.length;
  1851. while (j > 0 && i > 0) {
  1852. if (string[--i] != searchString[--j]) {
  1853. return false;
  1854. }
  1855. }
  1856. return j <= 0;
  1857. };
  1858. return polyfill;
  1859. }, 'es6', 'es3');
  1860. $jscomp.polyfill('String.fromCodePoint', function(orig) {
  1861. if (orig) {
  1862. return orig;
  1863. }
  1864. var polyfill = function(var_args) {
  1865. var result = '';
  1866. for (var i = 0; i < arguments.length; i++) {
  1867. var code = Number(arguments[i]);
  1868. if (code < 0 || code > 1114111 || code !== Math.floor(code)) {
  1869. throw new RangeError('invalid_code_point ' + code);
  1870. }
  1871. if (code <= 65535) {
  1872. result += String.fromCharCode(code);
  1873. } else {
  1874. code -= 65536;
  1875. result += String.fromCharCode(code >>> 10 & 1023 | 55296);
  1876. result += String.fromCharCode(code & 1023 | 56320);
  1877. }
  1878. }
  1879. return result;
  1880. };
  1881. return polyfill;
  1882. }, 'es6', 'es3');
  1883. $jscomp.polyfill('String.prototype.includes', function(orig) {
  1884. if (orig) {
  1885. return orig;
  1886. }
  1887. var polyfill = function(searchString, opt_position) {
  1888. var string = $jscomp.checkStringArgs(this, searchString, 'includes');
  1889. return string.indexOf(searchString, opt_position || 0) !== -1;
  1890. };
  1891. return polyfill;
  1892. }, 'es6', 'es3');
  1893. $jscomp.polyfill('String.prototype.repeat', function(orig) {
  1894. if (orig) {
  1895. return orig;
  1896. }
  1897. var polyfill = function(copies) {
  1898. var string = $jscomp.checkStringArgs(this, null, 'repeat');
  1899. if (copies < 0 || copies > 1342177279) {
  1900. throw new RangeError('Invalid count value');
  1901. }
  1902. copies = copies | 0;
  1903. var result = '';
  1904. while (copies) {
  1905. if (copies & 1) {
  1906. result += string;
  1907. }
  1908. if (copies >>>= 1) {
  1909. string += string;
  1910. }
  1911. }
  1912. return result;
  1913. };
  1914. return polyfill;
  1915. }, 'es6', 'es3');
  1916. $jscomp.stringPadding = function(padString, padLength) {
  1917. var padding = padString !== undefined ? String(padString) : ' ';
  1918. if (!(padLength > 0) || !padding) {
  1919. return '';
  1920. }
  1921. var repeats = Math.ceil(padLength / padding.length);
  1922. return padding.repeat(repeats).substring(0, padLength);
  1923. };
  1924. $jscomp.polyfill('String.prototype.padEnd', function(orig) {
  1925. if (orig) {
  1926. return orig;
  1927. }
  1928. var padEnd = function(targetLength, opt_padString) {
  1929. var string = $jscomp.checkStringArgs(this, null, 'padStart');
  1930. var padLength = targetLength - string.length;
  1931. return string + $jscomp.stringPadding(opt_padString, padLength);
  1932. };
  1933. return padEnd;
  1934. }, 'es8', 'es3');
  1935. $jscomp.polyfill('String.prototype.padStart', function(orig) {
  1936. if (orig) {
  1937. return orig;
  1938. }
  1939. var padStart = function(targetLength, opt_padString) {
  1940. var string = $jscomp.checkStringArgs(this, null, 'padStart');
  1941. var padLength = targetLength - string.length;
  1942. return $jscomp.stringPadding(opt_padString, padLength) + string;
  1943. };
  1944. return padStart;
  1945. }, 'es8', 'es3');
  1946. $jscomp.polyfill('String.prototype.startsWith', function(orig) {
  1947. if (orig) {
  1948. return orig;
  1949. }
  1950. var polyfill = function(searchString, opt_position) {
  1951. var string = $jscomp.checkStringArgs(this, searchString, 'startsWith');
  1952. searchString = searchString + '';
  1953. var strLen = string.length;
  1954. var searchLen = searchString.length;
  1955. var i = Math.max(0, Math.min(opt_position | 0, string.length));
  1956. var j = 0;
  1957. while (j < searchLen && i < strLen) {
  1958. if (string[i++] != searchString[j++]) {
  1959. return false;
  1960. }
  1961. }
  1962. return j >= searchLen;
  1963. };
  1964. return polyfill;
  1965. }, 'es6', 'es3');
  1966. $jscomp.arrayFromIterator = function(iterator) {
  1967. var i;
  1968. var arr = [];
  1969. while (!(i = iterator.next()).done) {
  1970. arr.push(i.value);
  1971. }
  1972. return arr;
  1973. };
  1974. $jscomp.arrayFromIterable = function(iterable) {
  1975. if (iterable instanceof Array) {
  1976. return iterable;
  1977. } else {
  1978. return $jscomp.arrayFromIterator($jscomp.makeIterator(iterable));
  1979. }
  1980. };
  1981. $jscomp.inherits = function(childCtor, parentCtor) {
  1982. childCtor.prototype = $jscomp.objectCreate(parentCtor.prototype);
  1983. childCtor.prototype.constructor = childCtor;
  1984. if ($jscomp.setPrototypeOf) {
  1985. var setPrototypeOf = $jscomp.setPrototypeOf;
  1986. setPrototypeOf(childCtor, parentCtor);
  1987. } else {
  1988. for (var p in parentCtor) {
  1989. if (p == 'prototype') {
  1990. continue;
  1991. }
  1992. if (Object.defineProperties) {
  1993. var descriptor = Object.getOwnPropertyDescriptor(parentCtor, p);
  1994. if (descriptor) {
  1995. Object.defineProperty(childCtor, p, descriptor);
  1996. }
  1997. } else {
  1998. childCtor[p] = parentCtor[p];
  1999. }
  2000. }
  2001. }
  2002. childCtor.superClass_ = parentCtor.prototype;
  2003. };
  2004. $jscomp.polyfill('WeakSet', function(NativeWeakSet) {
  2005. function isConformant() {
  2006. if (!NativeWeakSet || !Object.seal) {
  2007. return false;
  2008. }
  2009. try {
  2010. var x = Object.seal({});
  2011. var y = Object.seal({});
  2012. var set = new NativeWeakSet([x]);
  2013. if (!set.has(x) || set.has(y)) {
  2014. return false;
  2015. }
  2016. set['delete'](x);
  2017. set.add(y);
  2018. return !set.has(x) && set.has(y);
  2019. } catch (err) {
  2020. return false;
  2021. }
  2022. }
  2023. if ($jscomp.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS) {
  2024. if (NativeWeakSet && $jscomp.ES6_CONFORMANCE) {
  2025. return NativeWeakSet;
  2026. }
  2027. } else {
  2028. if (isConformant()) {
  2029. return NativeWeakSet;
  2030. }
  2031. }
  2032. var PolyfillWeakSet = function(opt_iterable) {
  2033. this.map_ = new WeakMap;
  2034. if (opt_iterable) {
  2035. $jscomp.initSymbol();
  2036. $jscomp.initSymbolIterator();
  2037. var iter = $jscomp.makeIterator(opt_iterable);
  2038. var entry;
  2039. while (!(entry = iter.next()).done) {
  2040. var item = entry.value;
  2041. this.add(item);
  2042. }
  2043. }
  2044. };
  2045. PolyfillWeakSet.prototype.add = function(elem) {
  2046. this.map_.set(elem, true);
  2047. return this;
  2048. };
  2049. PolyfillWeakSet.prototype.has = function(elem) {
  2050. return this.map_.has(elem);
  2051. };
  2052. PolyfillWeakSet.prototype['delete'] = function(elem) {
  2053. return this.map_['delete'](elem);
  2054. };
  2055. return PolyfillWeakSet;
  2056. }, 'es6', 'es3');
  2057. try {
  2058. if (Array.prototype.values.toString().indexOf('[native code]') == -1) {
  2059. delete Array.prototype.values;
  2060. }
  2061. } catch (e) {
  2062. }
  2063. Ext.define('Ext.data.amf.Encoder', {alias:'data.amf.Encoder', config:{format:3}, bytes:[], constructor:function(config) {
  2064. this.initConfig(config);
  2065. this.clear();
  2066. }, clear:function() {
  2067. this.bytes = [];
  2068. }, applyFormat:function(protocol_version) {
  2069. var funcs = {0:{writeUndefined:this.write0Undefined, writeNull:this.write0Null, writeBoolean:this.write0Boolean, writeNumber:this.write0Number, writeString:this.write0String, writeXml:this.write0Xml, writeDate:this.write0Date, writeArray:this.write0Array, writeGenericObject:this.write0GenericObject}, 3:{writeUndefined:this.write3Undefined, writeNull:this.write3Null, writeBoolean:this.write3Boolean, writeNumber:this.write3Number, writeString:this.write3String, writeXml:this.write3Xml, writeDate:this.write3Date,
  2070. writeArray:this.write3Array, writeGenericObject:this.write3GenericObject}}[protocol_version];
  2071. if (funcs) {
  2072. Ext.apply(this, funcs);
  2073. return protocol_version;
  2074. } else {
  2075. Ext.raise('Unsupported AMF format: ' + protocol_version + ". Only '3' (AMF3) is supported at this point.");
  2076. return;
  2077. }
  2078. }, writeObject:function(item) {
  2079. var t = typeof item;
  2080. if (t === 'undefined') {
  2081. this.writeUndefined();
  2082. } else {
  2083. if (item === null) {
  2084. this.writeNull();
  2085. } else {
  2086. if (Ext.isBoolean(item)) {
  2087. this.writeBoolean(item);
  2088. } else {
  2089. if (Ext.isString(item)) {
  2090. this.writeString(item);
  2091. } else {
  2092. if (t === 'number' || item instanceof Number) {
  2093. this.writeNumber(item);
  2094. } else {
  2095. if (t === 'object') {
  2096. if (item instanceof Date) {
  2097. this.writeDate(item);
  2098. } else {
  2099. if (Ext.isArray(item)) {
  2100. this.writeArray(item);
  2101. } else {
  2102. if (this.isXmlDocument(item)) {
  2103. this.writeXml(item);
  2104. } else {
  2105. this.writeGenericObject(item);
  2106. }
  2107. }
  2108. }
  2109. } else {
  2110. Ext.log.warn('AMF Encoder: Unknown item type ' + t + " can't be written to stream: " + item);
  2111. }
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }, write3Undefined:function() {
  2118. this.writeByte(0);
  2119. }, write0Undefined:function() {
  2120. this.writeByte(6);
  2121. }, write3Null:function() {
  2122. this.writeByte(1);
  2123. }, write0Null:function() {
  2124. this.writeByte(5);
  2125. }, write3Boolean:function(item) {
  2126. if (typeof item !== 'boolean') {
  2127. Ext.log.warn('Encoder: writeBoolean argument is not a boolean. Coercing.');
  2128. }
  2129. if (item) {
  2130. this.writeByte(3);
  2131. } else {
  2132. this.writeByte(2);
  2133. }
  2134. }, write0Boolean:function(item) {
  2135. if (typeof item !== 'boolean') {
  2136. Ext.log.warn('Encoder: writeBoolean argument is not a boolean. Coercing.');
  2137. }
  2138. this.writeByte(1);
  2139. if (item) {
  2140. this.writeByte(1);
  2141. } else {
  2142. this.writeByte(0);
  2143. }
  2144. }, encode29Int:function(item) {
  2145. var data = [], num = item, nibble, i;
  2146. if (num === 0) {
  2147. return [0];
  2148. }
  2149. if (num > 2097151) {
  2150. nibble = num & 255;
  2151. data.unshift(nibble);
  2152. num = num >> 8;
  2153. }
  2154. while (num > 0) {
  2155. nibble = num & 127;
  2156. data.unshift(nibble);
  2157. num = num >> 7;
  2158. }
  2159. for (i = 0; i < data.length - 1; i++) {
  2160. data[i] = data[i] | 128;
  2161. }
  2162. return data;
  2163. }, write3Number:function(item) {
  2164. var data, maxInt = 536870911, minSignedInt = -268435455;
  2165. if (typeof item !== 'number' && !(item instanceof Number)) {
  2166. Ext.log.warn("Encoder: writeNumber argument is not numeric. Can't coerce.");
  2167. }
  2168. if (item instanceof Number) {
  2169. item = item.valueOf();
  2170. }
  2171. if (item % 1 === 0 && item >= minSignedInt && item <= maxInt) {
  2172. item = item & maxInt;
  2173. data = this.encode29Int(item);
  2174. data.unshift(4);
  2175. this.writeBytes(data);
  2176. } else {
  2177. data = this.encodeDouble(item);
  2178. data.unshift(5);
  2179. this.writeBytes(data);
  2180. }
  2181. }, write0Number:function(item) {
  2182. var data;
  2183. if (typeof item !== 'number' && !(item instanceof Number)) {
  2184. Ext.log.warn("Encoder: writeNumber argument is not numeric. Can't coerce.");
  2185. }
  2186. if (item instanceof Number) {
  2187. item = item.valueOf();
  2188. }
  2189. data = this.encodeDouble(item);
  2190. data.unshift(0);
  2191. this.writeBytes(data);
  2192. }, encodeUtf8Char:function(c) {
  2193. var data = [], val, b, i, marker;
  2194. if (c > 1114111) {
  2195. Ext.raise('UTF 8 char out of bounds');
  2196. }
  2197. if (c <= 127) {
  2198. data.push(c);
  2199. } else {
  2200. if (c <= 2047) {
  2201. b = 2;
  2202. } else {
  2203. if (c <= 65535) {
  2204. b = 3;
  2205. } else {
  2206. b = 4;
  2207. }
  2208. }
  2209. marker = 128;
  2210. for (i = 1; i < b; i++) {
  2211. val = c & 63 | 128;
  2212. data.unshift(val);
  2213. c = c >> 6;
  2214. marker = marker >> 1 | 128;
  2215. }
  2216. val = c | marker;
  2217. data.unshift(val);
  2218. }
  2219. return data;
  2220. }, encodeUtf8String:function(str) {
  2221. var utf8Data = [], data, i;
  2222. for (i = 0; i < str.length; i++) {
  2223. data = this.encodeUtf8Char(str.charCodeAt(i));
  2224. Ext.Array.push(utf8Data, data);
  2225. }
  2226. return utf8Data;
  2227. }, encode3Utf8StringLen:function(utf8Data) {
  2228. var len = utf8Data.length, data = [];
  2229. if (len <= 268435455) {
  2230. len = len << 1;
  2231. len = len | 1;
  2232. data = this.encode29Int(len);
  2233. } else {
  2234. Ext.raise('UTF8 encoded string too long to serialize to AMF: ' + len);
  2235. }
  2236. return data;
  2237. }, write3String:function(item) {
  2238. var utf8Data, lenData;
  2239. if (!Ext.isString(item)) {
  2240. Ext.log.warn('Encoder: writString argument is not a string.');
  2241. }
  2242. if (item === '') {
  2243. this.writeByte(6);
  2244. this.writeByte(1);
  2245. } else {
  2246. utf8Data = this.encodeUtf8String(item);
  2247. lenData = this.encode3Utf8StringLen(utf8Data);
  2248. this.writeByte(6);
  2249. this.writeBytes(lenData);
  2250. this.writeBytes(utf8Data);
  2251. }
  2252. }, encodeXInt:function(value, byte_count) {
  2253. var data = [], i;
  2254. for (i = 0; i < byte_count; i++) {
  2255. data.unshift(value & 255);
  2256. value = value >> 8;
  2257. }
  2258. return data;
  2259. }, write0String:function(item) {
  2260. var utf8Data, lenData, encoding;
  2261. if (!Ext.isString(item)) {
  2262. Ext.log.warn('Encoder: writString argument is not a string.');
  2263. }
  2264. if (item === '') {
  2265. this.writeByte(2);
  2266. this.writeBytes([0, 0]);
  2267. } else {
  2268. utf8Data = this.encodeUtf8String(item);
  2269. if (utf8Data.length <= 65535) {
  2270. encoding = 2;
  2271. lenData = this.encodeXInt(utf8Data.length, 2);
  2272. } else {
  2273. encoding = 12;
  2274. lenData = this.encodeXInt(utf8Data.length, 4);
  2275. }
  2276. this.writeByte(encoding);
  2277. this.writeBytes(lenData);
  2278. this.writeBytes(utf8Data);
  2279. }
  2280. }, write3XmlWithType:function(xml, amfType) {
  2281. var xmlStr, utf8Data, lenData;
  2282. if (amfType !== 7 && amfType !== 11) {
  2283. Ext.raise('write XML with unknown AMF3 code: ' + amfType);
  2284. }
  2285. if (!this.isXmlDocument(xml)) {
  2286. Ext.log.warn('Encoder: write3XmlWithType argument is not an xml document.');
  2287. }
  2288. xmlStr = this.convertXmlToString(xml);
  2289. if (xmlStr === '') {
  2290. this.writeByte(amfType);
  2291. this.writeByte(1);
  2292. } else {
  2293. utf8Data = this.encodeUtf8String(xmlStr);
  2294. lenData = this.encode3Utf8StringLen(utf8Data);
  2295. this.writeByte(amfType);
  2296. this.writeBytes(lenData);
  2297. this.writeBytes(utf8Data);
  2298. }
  2299. }, write3XmlDocument:function(xml) {
  2300. this.write3XmlWithType(xml, 7);
  2301. }, write3Xml:function(xml) {
  2302. this.write3XmlWithType(xml, 11);
  2303. }, write0Xml:function(xml) {
  2304. var xmlStr, utf8Data, lenData;
  2305. if (!this.isXmlDocument(xml)) {
  2306. Ext.log.warn('Encoder: write0Xml argument is not an xml document.');
  2307. }
  2308. xmlStr = this.convertXmlToString(xml);
  2309. this.writeByte(15);
  2310. utf8Data = this.encodeUtf8String(xmlStr);
  2311. lenData = this.encodeXInt(utf8Data.length, 4);
  2312. this.writeBytes(lenData);
  2313. this.writeBytes(utf8Data);
  2314. }, write3Date:function(date) {
  2315. if (!(date instanceof Date)) {
  2316. Ext.raise('Serializing a non-date object as date: ' + date);
  2317. }
  2318. this.writeByte(8);
  2319. this.writeBytes(this.encode29Int(1));
  2320. this.writeBytes(this.encodeDouble(new Number(date)));
  2321. }, write0Date:function(date) {
  2322. if (!(date instanceof Date)) {
  2323. Ext.raise('Serializing a non-date object as date: ' + date);
  2324. }
  2325. this.writeByte(11);
  2326. this.writeBytes(this.encodeDouble(new Number(date)));
  2327. this.writeBytes([0, 0]);
  2328. }, write3Array:function(arr) {
  2329. var len;
  2330. if (!Ext.isArray(arr)) {
  2331. Ext.raise('Serializing a non-array object as array: ' + arr);
  2332. }
  2333. if (arr.length > 268435455) {
  2334. Ext.raise('Array size too long to encode in AMF3: ' + arr.length);
  2335. }
  2336. this.writeByte(9);
  2337. len = arr.length;
  2338. len = len << 1;
  2339. len = len | 1;
  2340. this.writeBytes(this.encode29Int(len));
  2341. this.writeByte(1);
  2342. Ext.each(arr, function(x) {
  2343. this.writeObject(x);
  2344. }, this);
  2345. }, write0ObjectProperty:function(key, value) {
  2346. var utf8Data, lenData;
  2347. if (!(key instanceof String) && typeof key !== 'string') {
  2348. key = key + '';
  2349. }
  2350. utf8Data = this.encodeUtf8String(key);
  2351. lenData = this.encodeXInt(utf8Data.length, 2);
  2352. this.writeBytes(lenData);
  2353. this.writeBytes(utf8Data);
  2354. this.writeObject(value);
  2355. }, write0Array:function(arr) {
  2356. var key, total;
  2357. if (!Ext.isArray(arr)) {
  2358. Ext.raise('Serializing a non-array object as array: ' + arr);
  2359. }
  2360. this.writeByte(8);
  2361. total = 0;
  2362. for (key in arr) {
  2363. total++;
  2364. }
  2365. this.writeBytes(this.encodeXInt(total, 4));
  2366. for (key in arr) {
  2367. Ext.Array.push(this.write0ObjectProperty(key, arr[key]));
  2368. }
  2369. this.writeBytes([0, 0, 9]);
  2370. }, write0StrictArray:function(arr) {
  2371. var len;
  2372. if (!Ext.isArray(arr)) {
  2373. Ext.raise('Serializing a non-array object as array: ' + arr);
  2374. }
  2375. this.writeByte(10);
  2376. len = arr.length;
  2377. this.writeBytes(this.encodeXInt(len, 4));
  2378. Ext.each(arr, function(x) {
  2379. this.writeObject(x);
  2380. }, this);
  2381. }, write3ByteArray:function(arr) {
  2382. var len;
  2383. if (!Ext.isArray(arr)) {
  2384. Ext.raise('Serializing a non-array object as array: ' + arr);
  2385. }
  2386. if (arr.length > 268435455) {
  2387. Ext.raise('Array size too long to encode in AMF3: ' + arr.length);
  2388. }
  2389. this.writeByte(12);
  2390. len = arr.length;
  2391. len = len << 1;
  2392. len = len | 1;
  2393. this.writeBytes(this.encode29Int(len));
  2394. this.writeBytes(arr);
  2395. }, write3GenericObject:function(obj) {
  2396. var name, newName, nameData, oType;
  2397. if (!Ext.isObject(obj)) {
  2398. Ext.raise('Serializing a non-object object: ' + obj);
  2399. }
  2400. this.writeByte(10);
  2401. oType = 11;
  2402. this.writeByte(oType);
  2403. this.writeByte(1);
  2404. for (name in obj) {
  2405. newName = (new String(name)).valueOf();
  2406. if (newName === '') {
  2407. Ext.raise("Can't encode non-string field name: " + name);
  2408. }
  2409. nameData = this.encodeUtf8String(name);
  2410. this.writeBytes(this.encode3Utf8StringLen(name));
  2411. this.writeBytes(nameData);
  2412. this.writeObject(obj[name]);
  2413. }
  2414. this.writeByte(1);
  2415. }, write0GenericObject:function(obj) {
  2416. var typed, amfType, key;
  2417. if (!Ext.isObject(obj)) {
  2418. Ext.raise('Serializing a non-object object: ' + obj);
  2419. }
  2420. typed = !!obj.$flexType;
  2421. amfType = typed ? 16 : 3;
  2422. this.writeByte(amfType);
  2423. if (typed) {
  2424. this.write0ShortUtf8String(obj.$flexType);
  2425. }
  2426. for (key in obj) {
  2427. if (key !== '$flexType') {
  2428. Ext.Array.push(this.write0ObjectProperty(key, obj[key]));
  2429. }
  2430. }
  2431. this.writeBytes([0, 0, 9]);
  2432. }, writeByte:function(b) {
  2433. if (b < 0 || b > 255) {
  2434. Ext.Error.raise('ERROR: Value being written outside byte range: ' + b);
  2435. }
  2436. Ext.Array.push(this.bytes, b);
  2437. }, writeBytes:function(b) {
  2438. var i;
  2439. if (!Ext.isArray(b)) {
  2440. Ext.raise('Decoder: writeBytes parameter is not an array: ' + b);
  2441. }
  2442. for (i = 0; i < b.length; i++) {
  2443. if (b[i] < 0 || b[i] > 255 || !Ext.isNumber(b[i])) {
  2444. Ext.raise('ERROR: Value ' + i + ' being written outside byte range: ' + b[i]);
  2445. }
  2446. }
  2447. Ext.Array.push(this.bytes, b);
  2448. }, convertXmlToString:function(xml) {
  2449. var str;
  2450. if (window.XMLSerializer) {
  2451. str = (new window.XMLSerializer).serializeToString(xml);
  2452. } else {
  2453. str = xml.xml;
  2454. }
  2455. return str;
  2456. }, isXmlDocument:function(item) {
  2457. if (window.DOMParser) {
  2458. if (Ext.isDefined(item.doctype)) {
  2459. return true;
  2460. }
  2461. }
  2462. if (Ext.isString(item.xml)) {
  2463. return true;
  2464. }
  2465. return false;
  2466. }, encodeDouble:function(num) {
  2467. var ebits = 11, fbits = 52, bias = (1 << ebits - 1) - 1, s, e, f, ln, i, bits, str, data = [], K_INFINITY = [127, 240, 0, 0, 0, 0, 0, 0], K_NINFINITY = [255, 240, 0, 0, 0, 0, 0, 0], K_NAN = [255, 248, 0, 0, 0, 0, 0, 0];
  2468. if (isNaN(num)) {
  2469. data = K_NAN;
  2470. } else {
  2471. if (num === Infinity) {
  2472. data = K_INFINITY;
  2473. } else {
  2474. if (num === -Infinity) {
  2475. data = K_NINFINITY;
  2476. } else {
  2477. if (num === 0) {
  2478. e = 0;
  2479. f = 0;
  2480. s = 1 / num === -Infinity ? 1 : 0;
  2481. } else {
  2482. s = num < 0;
  2483. num = Math.abs(num);
  2484. if (num >= Math.pow(2, 1 - bias)) {
  2485. ln = Math.min(Math.floor(Math.log(num) / Math.LN2), bias);
  2486. e = ln + bias;
  2487. f = Math.round(num * Math.pow(2, fbits - ln) - Math.pow(2, fbits));
  2488. } else {
  2489. e = 0;
  2490. f = Math.round(num / Math.pow(2, 1 - bias - fbits));
  2491. }
  2492. }
  2493. bits = [];
  2494. for (i = fbits; i; i -= 1) {
  2495. bits.push(f % 2 ? 1 : 0);
  2496. f = Math.floor(f / 2);
  2497. }
  2498. for (i = ebits; i; i -= 1) {
  2499. bits.push(e % 2 ? 1 : 0);
  2500. e = Math.floor(e / 2);
  2501. }
  2502. bits.push(s ? 1 : 0);
  2503. bits.reverse();
  2504. str = bits.join('');
  2505. data = [];
  2506. while (str.length) {
  2507. data.push(parseInt(str.substring(0, 8), 2));
  2508. str = str.substring(8);
  2509. }
  2510. }
  2511. }
  2512. }
  2513. return data;
  2514. }, write0ShortUtf8String:function(str) {
  2515. var utf8Data = this.encodeUtf8String(str), lenData;
  2516. lenData = this.encodeXInt(utf8Data.length, 2);
  2517. this.writeBytes(lenData);
  2518. this.writeBytes(utf8Data);
  2519. }, writeAmfPacket:function(headers, messages) {
  2520. var i;
  2521. if (this.config.format !== 0) {
  2522. Ext.raise('Trying to write a packet on an AMF3 Encoder. Only AMF0 is supported!');
  2523. }
  2524. if (!Ext.isArray(headers)) {
  2525. Ext.raise('headers is not an array: ' + headers);
  2526. }
  2527. if (!Ext.isArray(messages)) {
  2528. Ext.raise('messages is not an array: ' + messages);
  2529. }
  2530. this.writeBytes([0, 0]);
  2531. this.writeBytes(this.encodeXInt(headers.length, 2));
  2532. for (i in headers) {
  2533. if (!Ext.isString(headers[i].name)) {
  2534. Ext.raise('targetURI is not a string: ' + headers[i].targetUri);
  2535. }
  2536. this.writeAmfHeader(headers[i].name, headers[i].mustUnderstand, headers[i].value);
  2537. }
  2538. this.writeBytes(this.encodeXInt(messages.length, 2));
  2539. for (i in messages) {
  2540. this.writeAmfMessage(messages[i].targetUri, messages[i].responseUri, messages[i].body);
  2541. }
  2542. }, writeAmfHeader:function(headerName, mustUnderstand, value) {
  2543. var mu;
  2544. if (this.config.format !== 0) {
  2545. Ext.raise('Trying to write a header on an AMF3 Encoder. Only AMF0 is supported!');
  2546. }
  2547. if (typeof mustUnderstand !== 'boolean' && !Ext.isBoolean(mustUnderstand)) {
  2548. Ext.raise('mustUnderstand is not a boolean value: ' + mustUnderstand);
  2549. }
  2550. this.write0ShortUtf8String(headerName);
  2551. mu = mustUnderstand ? 1 : 0;
  2552. this.writeByte(mu);
  2553. this.writeBytes(this.encodeXInt(-1, 4));
  2554. this.writeObject(value);
  2555. }, writeAmfMessage:function(targetUri, responseUri, body) {
  2556. if (this.config.format !== 0) {
  2557. Ext.raise('Trying to write a message on an AMF3 Encoder. Only AMF0 is supported!');
  2558. }
  2559. if (!Ext.isString(targetUri)) {
  2560. Ext.raise('targetURI is not a string: ' + targetUri);
  2561. }
  2562. if (!Ext.isString(responseUri)) {
  2563. Ext.raise('targetURI is not a string: ' + responseUri);
  2564. }
  2565. if (!Ext.isArray(body)) {
  2566. Ext.raise('body is not an array: ' + typeof body);
  2567. }
  2568. this.write0ShortUtf8String(targetUri);
  2569. this.write0ShortUtf8String(responseUri);
  2570. this.writeBytes(this.encodeXInt(-1, 4));
  2571. this.write0StrictArray(body);
  2572. }});
  2573. Ext.define('Ext.data.amf.Packet', function() {
  2574. var twoPowN52 = Math.pow(2, -52), twoPow8 = Math.pow(2, 8), pos = 0, bytes, strings, objects, traits;
  2575. return {typeMap:{0:{0:'readDouble', 1:'readBoolean', 2:'readAmf0String', 3:'readAmf0Object', 5:'readNull', 6:'readUndefined', 7:'readReference', 8:'readEcmaArray', 10:'readStrictArray', 11:'readAmf0Date', 12:'readLongString', 13:'readUnsupported', 15:'readAmf0Xml', 16:'readTypedObject'}, 3:{0:'readUndefined', 1:'readNull', 2:'readFalse', 3:'readTrue', 4:'readUInt29', 5:'readDouble', 6:'readAmf3String', 7:'readAmf3Xml', 8:'readAmf3Date', 9:'readAmf3Array', 10:'readAmf3Object', 11:'readAmf3Xml',
  2576. 12:'readByteArray'}}, decode:function(byteArray) {
  2577. var me = this, headers = me.headers = [], messages = me.messages = [], headerCount, messageCount;
  2578. pos = 0;
  2579. bytes = me.bytes = byteArray;
  2580. strings = me.strings = [];
  2581. objects = me.objects = [];
  2582. traits = me.traits = [];
  2583. me.version = me.readUInt(2);
  2584. for (headerCount = me.readUInt(2); headerCount--;) {
  2585. headers.push({name:me.readAmf0String(), mustUnderstand:me.readBoolean(), byteLength:me.readUInt(4), value:me.readValue()});
  2586. strings = me.strings = [];
  2587. objects = me.objects = [];
  2588. traits = me.traits = [];
  2589. }
  2590. for (messageCount = me.readUInt(2); messageCount--;) {
  2591. messages.push({targetURI:me.readAmf0String(), responseURI:me.readAmf0String(), byteLength:me.readUInt(4), body:me.readValue()});
  2592. strings = me.strings = [];
  2593. objects = me.objects = [];
  2594. traits = me.traits = [];
  2595. }
  2596. pos = 0;
  2597. bytes = strings = objects = traits = me.bytes = me.strings = me.objects = me.traits = null;
  2598. return me;
  2599. }, decodeValue:function(byteArray) {
  2600. var me = this;
  2601. bytes = me.bytes = byteArray;
  2602. pos = 0;
  2603. me.version = 3;
  2604. strings = me.strings = [];
  2605. objects = me.objects = [];
  2606. traits = me.traits = [];
  2607. return me.readValue();
  2608. }, parseXml:function(xml) {
  2609. var doc;
  2610. if (window.DOMParser) {
  2611. doc = (new DOMParser).parseFromString(xml, 'text/xml');
  2612. } else {
  2613. doc = new ActiveXObject('Microsoft.XMLDOM');
  2614. doc.loadXML(xml);
  2615. }
  2616. return doc;
  2617. }, readAmf0Date:function() {
  2618. var date = new Date(this.readDouble());
  2619. pos += 2;
  2620. return date;
  2621. }, readAmf0Object:function(obj) {
  2622. var me = this, key;
  2623. obj = obj || {};
  2624. objects.push(obj);
  2625. while ((key = me.readAmf0String()) || bytes[pos] !== 9) {
  2626. obj[key] = me.readValue();
  2627. }
  2628. pos++;
  2629. return obj;
  2630. }, readAmf0String:function() {
  2631. return this.readUtf8(this.readUInt(2));
  2632. }, readAmf0Xml:function() {
  2633. return this.parseXml(this.readLongString());
  2634. }, readAmf3Array:function() {
  2635. var me = this, header = me.readUInt29(), count, key, array, i;
  2636. if (header & 1) {
  2637. count = header >> 1;
  2638. key = me.readAmf3String();
  2639. if (key) {
  2640. array = {};
  2641. objects.push(array);
  2642. do {
  2643. array[key] = me.readValue();
  2644. } while (key = me.readAmf3String());
  2645. for (i = 0; i < count; i++) {
  2646. array[i] = me.readValue();
  2647. }
  2648. } else {
  2649. array = [];
  2650. objects.push(array);
  2651. for (i = 0; i < count; i++) {
  2652. array.push(me.readValue());
  2653. }
  2654. }
  2655. } else {
  2656. array = objects[header >> 1];
  2657. }
  2658. return array;
  2659. }, readAmf3Date:function() {
  2660. var me = this, header = me.readUInt29(), date;
  2661. if (header & 1) {
  2662. date = new Date(me.readDouble());
  2663. objects.push(date);
  2664. } else {
  2665. date = objects[header >> 1];
  2666. }
  2667. return date;
  2668. }, readAmf3Object:function() {
  2669. var me = this, header = me.readUInt29(), members = [], headerLast3Bits, memberCount, className, dynamic, objectTraits, obj, key, klass, i;
  2670. if (header & 1) {
  2671. headerLast3Bits = header & 7;
  2672. if (headerLast3Bits === 3) {
  2673. className = me.readAmf3String();
  2674. dynamic = !!(header & 8);
  2675. memberCount = header >> 4;
  2676. for (i = 0; i < memberCount; i++) {
  2677. members.push(me.readAmf3String());
  2678. }
  2679. objectTraits = {className:className, dynamic:dynamic, members:members};
  2680. traits.push(objectTraits);
  2681. } else {
  2682. if ((header & 3) === 1) {
  2683. objectTraits = traits[header >> 2];
  2684. className = objectTraits.className;
  2685. dynamic = objectTraits.dynamic;
  2686. members = objectTraits.members;
  2687. memberCount = members.length;
  2688. } else {
  2689. if (headerLast3Bits === 7) {
  2690. }
  2691. }
  2692. }
  2693. if (className) {
  2694. klass = Ext.ClassManager.getByAlias('amf.' + className);
  2695. obj = klass ? new klass : {$className:className};
  2696. } else {
  2697. obj = {};
  2698. }
  2699. objects.push(obj);
  2700. for (i = 0; i < memberCount; i++) {
  2701. obj[members[i]] = me.readValue();
  2702. }
  2703. if (dynamic) {
  2704. while (key = me.readAmf3String()) {
  2705. obj[key] = me.readValue();
  2706. }
  2707. }
  2708. if (!klass && this.converters[className]) {
  2709. obj = this.converters[className](obj);
  2710. }
  2711. } else {
  2712. obj = objects[header >> 1];
  2713. }
  2714. return obj;
  2715. }, readAmf3String:function() {
  2716. var me = this, header = me.readUInt29(), value;
  2717. if (header & 1) {
  2718. value = me.readUtf8(header >> 1);
  2719. if (value) {
  2720. strings.push(value);
  2721. }
  2722. return value;
  2723. } else {
  2724. return strings[header >> 1];
  2725. }
  2726. }, readAmf3Xml:function() {
  2727. var me = this, header = me.readUInt29(), doc;
  2728. if (header & 1) {
  2729. doc = me.parseXml(me.readUtf8(header >> 1));
  2730. objects.push(doc);
  2731. } else {
  2732. doc = objects[header >> 1];
  2733. }
  2734. return doc;
  2735. }, readBoolean:function() {
  2736. return !!bytes[pos++];
  2737. }, readByteArray:function() {
  2738. var header = this.readUInt29(), byteArray, end;
  2739. if (header & 1) {
  2740. end = pos + (header >> 1);
  2741. byteArray = Array.prototype.slice.call(bytes, pos, end);
  2742. objects.push(byteArray);
  2743. pos = end;
  2744. } else {
  2745. byteArray = objects[header >> 1];
  2746. }
  2747. return byteArray;
  2748. }, readDouble:function() {
  2749. var byte1 = bytes[pos++], byte2 = bytes[pos++], sign = byte1 >> 7 ? -1 : 1, exponent = (byte1 & 127) << 4 | byte2 >> 4, significand = byte2 & 15, hiddenBit = exponent ? 1 : 0, i = 6;
  2750. while (i--) {
  2751. significand = significand * twoPow8 + bytes[pos++];
  2752. }
  2753. if (!exponent) {
  2754. if (!significand) {
  2755. return 0;
  2756. }
  2757. exponent = 1;
  2758. }
  2759. if (exponent === 2047) {
  2760. return significand ? NaN : Infinity * sign;
  2761. }
  2762. return sign * Math.pow(2, exponent - 1023) * (hiddenBit + twoPowN52 * significand);
  2763. }, readEcmaArray:function() {
  2764. pos += 4;
  2765. return this.readAmf0Object();
  2766. }, readFalse:function() {
  2767. return false;
  2768. }, readLongString:function() {
  2769. return this.readUtf8(this.readUInt(4));
  2770. }, readNull:function() {
  2771. return null;
  2772. }, readReference:function() {
  2773. return objects[this.readUInt(2)];
  2774. }, readStrictArray:function() {
  2775. var me = this, len = me.readUInt(4), arr = [];
  2776. objects.push(arr);
  2777. while (len--) {
  2778. arr.push(me.readValue());
  2779. }
  2780. return arr;
  2781. }, readTrue:Ext.returnTrue, readTypedObject:function() {
  2782. var me = this, className = me.readAmf0String(), klass, instance, modified;
  2783. klass = Ext.ClassManager.getByAlias('amf.' + className);
  2784. instance = klass ? new klass : {$className:className};
  2785. modified = me.readAmf0Object(instance);
  2786. if (!klass && this.converters[className]) {
  2787. modified = this.converters[className](instance);
  2788. }
  2789. return modified;
  2790. }, readUInt:function(byteCount) {
  2791. var i = 1, result;
  2792. result = bytes[pos++];
  2793. for (; i < byteCount; ++i) {
  2794. result = result << 8 | bytes[pos++];
  2795. }
  2796. return result;
  2797. }, readUInt29:function() {
  2798. var value = bytes[pos++], nextByte;
  2799. if (value & 128) {
  2800. nextByte = bytes[pos++];
  2801. value = (value & 127) << 7 | nextByte & 127;
  2802. if (nextByte & 128) {
  2803. nextByte = bytes[pos++];
  2804. value = value << 7 | nextByte & 127;
  2805. if (nextByte & 128) {
  2806. nextByte = bytes[pos++];
  2807. value = value << 8 | nextByte;
  2808. }
  2809. }
  2810. }
  2811. return value;
  2812. }, readUndefined:Ext.emptyFn, readUnsupported:Ext.emptyFn, readUtf8:function(byteLength) {
  2813. var end = pos + byteLength, chars = [], charCount = 0, maxCharCount = 65535, charArrayCount = 1, result = [], i = 0, charArrays, byteCount, charCode;
  2814. charArrays = [chars];
  2815. while (pos < end) {
  2816. charCode = bytes[pos++];
  2817. if (charCode > 127) {
  2818. if (charCode > 239) {
  2819. byteCount = 4;
  2820. charCode = charCode & 7;
  2821. } else {
  2822. if (charCode > 223) {
  2823. byteCount = 3;
  2824. charCode = charCode & 15;
  2825. } else {
  2826. byteCount = 2;
  2827. charCode = charCode & 31;
  2828. }
  2829. }
  2830. while (--byteCount) {
  2831. charCode = charCode << 6 | bytes[pos++] & 63;
  2832. }
  2833. }
  2834. chars.push(charCode);
  2835. if (++charCount === maxCharCount) {
  2836. charArrays.push(chars = []);
  2837. charCount = 0;
  2838. charArrayCount++;
  2839. }
  2840. }
  2841. for (; i < charArrayCount; i++) {
  2842. result.push(String.fromCharCode.apply(String, charArrays[i]));
  2843. }
  2844. return result.join('');
  2845. }, readValue:function() {
  2846. var me = this, marker = bytes[pos++];
  2847. if (marker === 17) {
  2848. me.version = 3;
  2849. marker = bytes[pos++];
  2850. }
  2851. return me[me.typeMap[me.version][marker]]();
  2852. }, converters:{'flex.messaging.io.ArrayCollection':function(obj) {
  2853. return obj.source || [];
  2854. }}};
  2855. });
  2856. Ext.define('Ext.data.amf.Reader', {extend:'Ext.data.reader.Json', alias:'reader.amf', requires:['Ext.data.amf.Packet'], messageIndex:0, responseType:'arraybuffer', read:function(response) {
  2857. var me = this, bytes = response.responseBytes, packet, messages, resultSet;
  2858. if (!bytes) {
  2859. throw 'AMF Reader cannot process the response because it does not contain ' + "binary data. Make sure the Proxy's 'binary' config is true.";
  2860. }
  2861. packet = new Ext.data.amf.Packet;
  2862. packet.decode(bytes);
  2863. messages = packet.messages;
  2864. if (messages.length) {
  2865. resultSet = me.readRecords(messages[me.messageIndex].body);
  2866. } else {
  2867. resultSet = me.nullResultSet;
  2868. if (packet.invalid) {
  2869. resultSet.success = false;
  2870. }
  2871. }
  2872. return resultSet;
  2873. }});
  2874. Ext.define('Ext.data.amf.Proxy', {extend:'Ext.data.proxy.Ajax', alias:'proxy.amf', requires:['Ext.data.amf.Reader'], binary:true, reader:'amf'});
  2875. Ext.define('Ext.data.amf.RemotingMessage', {alias:'data.amf.remotingmessage', config:{$flexType:'flex.messaging.messages.RemotingMessage', body:[], clientId:'', destination:'', headers:[], messageId:'', operation:'', source:'', timestamp:[], timeToLive:[]}, constructor:function(config) {
  2876. this.initConfig(config);
  2877. }, encodeMessage:function() {
  2878. var encoder = Ext.create('Ext.data.amf.XmlEncoder'), cleanObj;
  2879. cleanObj = Ext.copyTo({}, this, '$flexType,body,clientId,destination,headers,messageId,operation,source,timestamp,timeToLive', true);
  2880. encoder.writeObject(cleanObj);
  2881. return encoder.body;
  2882. }});
  2883. Ext.define('Ext.data.amf.XmlDecoder', {alias:'data.amf.xmldecoder', statics:{readXml:function(xml) {
  2884. var doc;
  2885. if (window.DOMParser) {
  2886. doc = (new DOMParser).parseFromString(xml, 'text/xml');
  2887. } else {
  2888. doc = new ActiveXObject('Microsoft.XMLDOM');
  2889. doc.loadXML(xml);
  2890. }
  2891. return doc;
  2892. }, readByteArray:function(node) {
  2893. var bytes = [], c, i, str;
  2894. str = node.firstChild.nodeValue;
  2895. for (i = 0; i < str.length; i = i + 2) {
  2896. c = str.substr(i, 2);
  2897. bytes.push(parseInt(c, 16));
  2898. }
  2899. return bytes;
  2900. }, readAMF3Value:function(bytes) {
  2901. var packet = Ext.create('Ext.data.amf.Packet');
  2902. return packet.decodeValue(bytes);
  2903. }, decodeTidFromFlexUID:function(messageId) {
  2904. var str = messageId.substr(0, 8);
  2905. return parseInt(str, 16);
  2906. }}, constructor:function(config) {
  2907. this.initConfig(config);
  2908. this.clear();
  2909. }, clear:function() {
  2910. this.objectReferences = [];
  2911. this.traitsReferences = [];
  2912. this.stringReferences = [];
  2913. }, readAmfxMessage:function(xml) {
  2914. var doc, amfx, body, resp = {}, i;
  2915. this.clear();
  2916. doc = Ext.data.amf.XmlDecoder.readXml(xml);
  2917. amfx = doc.getElementsByTagName('amfx')[0];
  2918. if (!amfx) {
  2919. Ext.warn.log('No AMFX tag in message');
  2920. }
  2921. if (amfx.getAttribute('ver') != '3') {
  2922. Ext.raise('Unsupported AMFX version: ' + amfx.getAttribute('ver'));
  2923. }
  2924. body = amfx.getElementsByTagName('body')[0];
  2925. resp.targetURI = body.getAttribute('targetURI');
  2926. resp.responseURI = body.getAttribute('responseURI');
  2927. for (i = 0; i < body.childNodes.length; i++) {
  2928. if (body.childNodes.item(i).nodeType != 1) {
  2929. continue;
  2930. }
  2931. resp.message = this.readValue(body.childNodes.item(i));
  2932. break;
  2933. }
  2934. return resp;
  2935. }, readValue:function(node) {
  2936. var val;
  2937. if (typeof node.normalize === 'function') {
  2938. node.normalize();
  2939. }
  2940. if (node.tagName == 'null') {
  2941. return null;
  2942. } else {
  2943. if (node.tagName == 'true') {
  2944. return true;
  2945. } else {
  2946. if (node.tagName == 'false') {
  2947. return false;
  2948. } else {
  2949. if (node.tagName == 'string') {
  2950. return this.readString(node);
  2951. } else {
  2952. if (node.tagName == 'int') {
  2953. return parseInt(node.firstChild.nodeValue);
  2954. } else {
  2955. if (node.tagName == 'double') {
  2956. return parseFloat(node.firstChild.nodeValue);
  2957. } else {
  2958. if (node.tagName == 'date') {
  2959. val = new Date(parseFloat(node.firstChild.nodeValue));
  2960. this.objectReferences.push(val);
  2961. return val;
  2962. } else {
  2963. if (node.tagName == 'dictionary') {
  2964. return this.readDictionary(node);
  2965. } else {
  2966. if (node.tagName == 'array') {
  2967. return this.readArray(node);
  2968. } else {
  2969. if (node.tagName == 'ref') {
  2970. return this.readObjectRef(node);
  2971. } else {
  2972. if (node.tagName == 'object') {
  2973. return this.readObject(node);
  2974. } else {
  2975. if (node.tagName == 'xml') {
  2976. return Ext.data.amf.XmlDecoder.readXml(node.firstChild.nodeValue);
  2977. } else {
  2978. if (node.tagName == 'bytearray') {
  2979. return Ext.data.amf.XmlDecoder.readAMF3Value(Ext.data.amf.XmlDecoder.readByteArray(node));
  2980. }
  2981. }
  2982. }
  2983. }
  2984. }
  2985. }
  2986. }
  2987. }
  2988. }
  2989. }
  2990. }
  2991. }
  2992. }
  2993. Ext.raise('Unknown tag type: ' + node.tagName);
  2994. return null;
  2995. }, readString:function(node) {
  2996. var val;
  2997. if (node.getAttributeNode('id')) {
  2998. return this.stringReferences[parseInt(node.getAttribute('id'))];
  2999. }
  3000. val = (node.firstChild ? node.firstChild.nodeValue : '') || '';
  3001. this.stringReferences.push(val);
  3002. return val;
  3003. }, readTraits:function(node) {
  3004. var traits = [], i, rawtraits;
  3005. if (node === null) {
  3006. return null;
  3007. }
  3008. if (node.getAttribute('externalizable') == 'true') {
  3009. return null;
  3010. }
  3011. if (node.getAttributeNode('id')) {
  3012. return this.traitsReferences[parseInt(node.getAttributeNode('id').value)];
  3013. }
  3014. rawtraits = node.childNodes;
  3015. for (i = 0; i < rawtraits.length; i++) {
  3016. if (rawtraits.item(i).nodeType != 1) {
  3017. continue;
  3018. }
  3019. traits.push(this.readValue(rawtraits.item(i)));
  3020. }
  3021. this.traitsReferences.push(traits);
  3022. return traits;
  3023. }, readObjectRef:function(node) {
  3024. var id = parseInt(node.getAttribute('id'));
  3025. return this.objectReferences[id];
  3026. }, readObject:function(node) {
  3027. var obj, traits = [], traitsNode, i, j, n, key, val, klass = null, className;
  3028. className = node.getAttribute('type');
  3029. if (className) {
  3030. klass = Ext.ClassManager.getByAlias('amfx.' + className);
  3031. }
  3032. obj = klass ? new klass : className ? {$className:className} : {};
  3033. if (!klass && this.converters[className]) {
  3034. obj = this.converters[className](this, node);
  3035. return obj;
  3036. }
  3037. traitsNode = node.getElementsByTagName('traits')[0];
  3038. traits = this.readTraits(traitsNode);
  3039. if (traits === null) {
  3040. Ext.raise('No support for externalizable object: ' + className);
  3041. }
  3042. this.objectReferences.push(obj);
  3043. j = 0;
  3044. for (i = 0; i < node.childNodes.length; i++) {
  3045. n = node.childNodes.item(i);
  3046. if (n.nodeType != 1) {
  3047. continue;
  3048. }
  3049. if (n.tagName == 'traits') {
  3050. continue;
  3051. }
  3052. key = traits[j];
  3053. val = this.readValue(n);
  3054. j = j + 1;
  3055. obj[key] = val;
  3056. if (j > traits.length) {
  3057. Ext.raise('Too many items for object, not enough traits: ' + className);
  3058. }
  3059. }
  3060. return obj;
  3061. }, readArray:function(node) {
  3062. var arr = [], n, i, j, l, name, val, len, childnodes, cn;
  3063. this.objectReferences.push(arr);
  3064. len = parseInt(node.getAttributeNode('length').value);
  3065. i = 0;
  3066. for (l = 0; l < node.childNodes.length; l++) {
  3067. n = node.childNodes.item(l);
  3068. if (n.nodeType != 1) {
  3069. continue;
  3070. }
  3071. if (n.tagName == 'item') {
  3072. name = n.getAttributeNode('name').value;
  3073. childnodes = n.childNodes;
  3074. for (j = 0; j < childnodes.length; j++) {
  3075. cn = childnodes.item(j);
  3076. if (cn.nodeType != 1) {
  3077. continue;
  3078. }
  3079. val = this.readValue(cn);
  3080. break;
  3081. }
  3082. arr[name] = val;
  3083. } else {
  3084. arr[i] = this.readValue(n);
  3085. i++;
  3086. if (i > len) {
  3087. Ext.raise('Array has more items than declared length: ' + i + ' \x3e ' + len);
  3088. }
  3089. }
  3090. }
  3091. if (i < len) {
  3092. Ext.raise('Array has less items than declared length: ' + i + ' \x3c ' + len);
  3093. }
  3094. return arr;
  3095. }, readDictionary:function(node) {
  3096. var dict = {}, key, val, i, j, n, len;
  3097. len = parseInt(node.getAttribute('length'));
  3098. this.objectReferences.push(dict);
  3099. key = null;
  3100. val = null;
  3101. j = 0;
  3102. for (i = 0; i < node.childNodes.length; i++) {
  3103. n = node.childNodes.item(i);
  3104. if (n.nodeType != 1) {
  3105. continue;
  3106. }
  3107. if (!key) {
  3108. key = this.readValue(n);
  3109. continue;
  3110. }
  3111. val = this.readValue(n);
  3112. j = j + 1;
  3113. dict[key] = val;
  3114. key = null;
  3115. val = null;
  3116. }
  3117. if (j != len) {
  3118. Ext.raise('Incorrect number of dictionary values: ' + j + ' !\x3d ' + len);
  3119. }
  3120. return dict;
  3121. }, convertObjectWithSourceField:function(node) {
  3122. var i, n, val;
  3123. for (i = 0; i < node.childNodes.length; i++) {
  3124. n = node.childNodes.item(i);
  3125. if (n.tagName == 'bytearray') {
  3126. val = this.readValue(n);
  3127. this.objectReferences.push(val);
  3128. return val;
  3129. }
  3130. }
  3131. return null;
  3132. }, converters:{'flex.messaging.io.ArrayCollection':function(decoder, node) {
  3133. return decoder.convertObjectWithSourceField(node);
  3134. }, 'mx.collections.ArrayList':function(decoder, node) {
  3135. return decoder.convertObjectWithSourceField(node);
  3136. }, 'mx.collections.ArrayCollection':function(decoder, node) {
  3137. return decoder.convertObjectWithSourceField(node);
  3138. }}});
  3139. Ext.define('Ext.data.amf.XmlEncoder', {alias:'data.amf.xmlencoder', body:'', statics:{generateFlexUID:function(id) {
  3140. var uid = '', i, j, t;
  3141. if (id === undefined) {
  3142. id = Ext.Number.randomInt(0, 4.294967295E9);
  3143. }
  3144. t = (id + 4.294967296E9).toString(16).toUpperCase();
  3145. uid = t.substr(t.length - 8, 8);
  3146. for (j = 0; j < 3; j++) {
  3147. uid += '-';
  3148. for (i = 0; i < 4; i++) {
  3149. uid += Ext.Number.randomInt(0, 15).toString(16).toUpperCase();
  3150. }
  3151. }
  3152. uid += '-';
  3153. t = (new Number(new Date)).valueOf().toString(16).toUpperCase();
  3154. j = 0;
  3155. if (t.length < 8) {
  3156. for (i = 0; i < t.length - 8; i++) {
  3157. j++;
  3158. uid += '0';
  3159. }
  3160. }
  3161. uid += t.substr(-(8 - j));
  3162. for (i = 0; i < 4; i++) {
  3163. uid += Ext.Number.randomInt(0, 15).toString(16).toUpperCase();
  3164. }
  3165. return uid;
  3166. }}, constructor:function(config) {
  3167. this.initConfig(config);
  3168. this.clear();
  3169. }, clear:function() {
  3170. this.body = '';
  3171. }, encodeUndefined:function() {
  3172. return this.encodeNull();
  3173. }, writeUndefined:function() {
  3174. this.write(this.encodeUndefined());
  3175. }, encodeNull:function() {
  3176. return '\x3cnull /\x3e';
  3177. }, writeNull:function() {
  3178. this.write(this.encodeNull());
  3179. }, encodeBoolean:function(val) {
  3180. var str;
  3181. if (val) {
  3182. str = '\x3ctrue /\x3e';
  3183. } else {
  3184. str = '\x3cfalse /\x3e';
  3185. }
  3186. return str;
  3187. }, writeBoolean:function(val) {
  3188. this.write(this.encodeBoolean(val));
  3189. }, encodeString:function(str) {
  3190. var ret;
  3191. if (str === '') {
  3192. ret = '\x3cstring /\x3e';
  3193. } else {
  3194. ret = '\x3cstring\x3e' + str + '\x3c/string\x3e';
  3195. }
  3196. return ret;
  3197. }, writeString:function(str) {
  3198. this.write(this.encodeString(str));
  3199. }, encodeInt:function(num) {
  3200. return '\x3cint\x3e' + num.toString() + '\x3c/int\x3e';
  3201. }, writeInt:function(num) {
  3202. this.write(this.encodeInt(num));
  3203. }, encodeDouble:function(num) {
  3204. return '\x3cdouble\x3e' + num.toString() + '\x3c/double\x3e';
  3205. }, writeDouble:function(num) {
  3206. this.write(this.encodeDouble(num));
  3207. }, encodeNumber:function(num) {
  3208. var maxInt = 536870911, minSignedInt = -268435455;
  3209. if (typeof num !== 'number' && !(num instanceof Number)) {
  3210. Ext.log.warn("Encoder: writeNumber argument is not numeric. Can't coerce.");
  3211. }
  3212. if (num instanceof Number) {
  3213. num = num.valueOf();
  3214. }
  3215. if (num % 1 === 0 && num >= minSignedInt && num <= maxInt) {
  3216. return this.encodeInt(num);
  3217. } else {
  3218. return this.encodeDouble(num);
  3219. }
  3220. }, writeNumber:function(num) {
  3221. this.write(this.encodeNumber(num));
  3222. }, encodeDate:function(date) {
  3223. return '\x3cdate\x3e' + (new Number(date)).toString() + '\x3c/date\x3e';
  3224. }, writeDate:function(date) {
  3225. this.write(this.encodeDate(date));
  3226. }, encodeEcmaElement:function(key, value) {
  3227. var str = '\x3citem name\x3d"' + key.toString() + '"\x3e' + this.encodeObject(value) + '\x3c/item\x3e';
  3228. return str;
  3229. }, encodeArray:function(array) {
  3230. var ordinals = [], firstNonOrdinal, ecmaElements = [], i, str;
  3231. for (i in array) {
  3232. if (Ext.isNumeric(i) && i % 1 === 0) {
  3233. ordinals[i] = this.encodeObject(array[i]);
  3234. } else {
  3235. ecmaElements.push(this.encodeEcmaElement(i, array[i]));
  3236. }
  3237. }
  3238. firstNonOrdinal = ordinals.length;
  3239. for (i = 0; i < ordinals.length; i++) {
  3240. if (ordinals[i] === undefined) {
  3241. firstNonOrdinal = i;
  3242. break;
  3243. }
  3244. }
  3245. if (firstNonOrdinal < ordinals.length) {
  3246. for (i = firstNonOrdinal; i < ordinals.length; i++) {
  3247. if (ordinals[i] !== undefined) {
  3248. ecmaElements.push(this.encodeEcmaElement(i, ordinals[i]));
  3249. }
  3250. }
  3251. ordinals = ordinals.slice(0, firstNonOrdinal);
  3252. }
  3253. str = '\x3carray length\x3d"' + ordinals.length + '"';
  3254. if (ecmaElements.length > 0) {
  3255. str += ' ecma\x3d"true"';
  3256. }
  3257. str += '\x3e';
  3258. for (i = 0; i < ordinals.length; i++) {
  3259. str += ordinals[i];
  3260. }
  3261. for (i in ecmaElements) {
  3262. str += ecmaElements[i];
  3263. }
  3264. str += '\x3c/array\x3e';
  3265. return str;
  3266. }, writeArray:function(array) {
  3267. this.write(this.encodeArray(array));
  3268. }, encodeXml:function(xml) {
  3269. var str = this.convertXmlToString(xml);
  3270. return '\x3cxml\x3e\x3c![CDATA[' + str + ']]\x3e\x3c/xml\x3e';
  3271. }, writeXml:function(xml) {
  3272. this.write(this.encodeXml(xml));
  3273. }, encodeGenericObject:function(obj) {
  3274. var traits = [], values = [], flexType = null, i, str;
  3275. for (i in obj) {
  3276. if (i === '$flexType') {
  3277. flexType = obj[i];
  3278. } else {
  3279. traits.push(this.encodeString(new String(i)));
  3280. values.push(this.encodeObject(obj[i]));
  3281. }
  3282. }
  3283. if (flexType) {
  3284. str = '\x3cobject type\x3d"' + flexType + '"\x3e';
  3285. } else {
  3286. str = '\x3cobject\x3e';
  3287. }
  3288. if (traits.length > 0) {
  3289. str += '\x3ctraits\x3e';
  3290. str += traits.join('');
  3291. str += '\x3c/traits\x3e';
  3292. } else {
  3293. str += '\x3ctraits /\x3e';
  3294. }
  3295. str += values.join('');
  3296. str += '\x3c/object\x3e';
  3297. return str;
  3298. }, writeGenericObject:function(obj) {
  3299. this.write(this.encodeGenericObject(obj));
  3300. }, encodeByteArray:function(array) {
  3301. var str, i, h;
  3302. if (array.length > 0) {
  3303. str = '\x3cbytearray\x3e';
  3304. for (i = 0; i < array.length; i++) {
  3305. if (!Ext.isNumber(array[i])) {
  3306. Ext.raise('Byte array contains a non-number: ' + array[i] + ' in index: ' + i);
  3307. }
  3308. if (array[i] < 0 || array[i] > 255) {
  3309. Ext.raise('Byte array value out of bounds: ' + array[i]);
  3310. }
  3311. h = array[i].toString(16).toUpperCase();
  3312. if (array[i] < 16) {
  3313. h = '0' + h;
  3314. }
  3315. str += h;
  3316. }
  3317. str += '\x3c/bytearray\x3e';
  3318. } else {
  3319. str = '\x3cbytearray /\x3e';
  3320. }
  3321. return str;
  3322. }, writeByteArray:function(array) {
  3323. this.write(this.encodeByteArray(array));
  3324. }, encodeObject:function(item) {
  3325. var t = typeof item;
  3326. if (t === 'undefined') {
  3327. return this.encodeUndefined();
  3328. } else {
  3329. if (item === null) {
  3330. return this.encodeNull();
  3331. } else {
  3332. if (Ext.isBoolean(item)) {
  3333. return this.encodeBoolean(item);
  3334. } else {
  3335. if (Ext.isString(item)) {
  3336. return this.encodeString(item);
  3337. } else {
  3338. if (t === 'number' || item instanceof Number) {
  3339. return this.encodeNumber(item);
  3340. } else {
  3341. if (t === 'object') {
  3342. if (item instanceof Date) {
  3343. return this.encodeDate(item);
  3344. } else {
  3345. if (Ext.isArray(item)) {
  3346. return this.encodeArray(item);
  3347. } else {
  3348. if (this.isXmlDocument(item)) {
  3349. return this.encodeXml(item);
  3350. } else {
  3351. return this.encodeGenericObject(item);
  3352. }
  3353. }
  3354. }
  3355. } else {
  3356. Ext.log.warn('AMFX Encoder: Unknown item type ' + t + " can't be written to stream: " + item);
  3357. }
  3358. }
  3359. }
  3360. }
  3361. }
  3362. }
  3363. return null;
  3364. }, writeObject:function(item) {
  3365. this.write(this.encodeObject(item));
  3366. }, encodeAmfxRemotingPacket:function(message) {
  3367. var str = '\x3camfx ver\x3d"3" xmlns\x3d"http://www.macromedia.com/2005/amfx"\x3e\x3cbody\x3e' + message.encodeMessage() + '\x3c/body\x3e\x3c/amfx\x3e';
  3368. return str;
  3369. }, writeAmfxRemotingPacket:function(message) {
  3370. this.write(this.encodeAmfxRemotingPacket(message));
  3371. }, convertXmlToString:function(xml) {
  3372. var str;
  3373. if (window.XMLSerializer) {
  3374. str = (new window.XMLSerializer).serializeToString(xml);
  3375. } else {
  3376. str = xml.xml;
  3377. }
  3378. return str;
  3379. }, isXmlDocument:function(item) {
  3380. if (window.DOMParser) {
  3381. if (Ext.isDefined(item.doctype)) {
  3382. return true;
  3383. }
  3384. }
  3385. if (Ext.isString(item.xml)) {
  3386. return true;
  3387. }
  3388. return false;
  3389. }, write:function(str) {
  3390. this.body += str;
  3391. }});
  3392. Ext.define('Ext.direct.AmfRemotingProvider', {alias:'direct.amfremotingprovider', extend:'Ext.direct.Provider', requires:['Ext.util.MixedCollection', 'Ext.util.DelayedTask', 'Ext.direct.Transaction', 'Ext.direct.RemotingMethod', 'Ext.data.amf.XmlEncoder', 'Ext.data.amf.XmlDecoder', 'Ext.data.amf.Encoder', 'Ext.data.amf.Packet', 'Ext.data.amf.RemotingMessage', 'Ext.direct.ExceptionEvent'], binary:false, maxRetries:1, timeout:undefined, constructor:function(config) {
  3393. var me = this;
  3394. me.callParent(arguments);
  3395. me.namespace = Ext.isString(me.namespace) ? Ext.ns(me.namespace) : me.namespace || window;
  3396. me.transactions = new Ext.util.MixedCollection;
  3397. me.callBuffer = [];
  3398. }, initAPI:function() {
  3399. var actions = this.actions, namespace = this.namespace, action, cls, methods, i, len, method;
  3400. for (action in actions) {
  3401. if (actions.hasOwnProperty(action)) {
  3402. cls = namespace[action];
  3403. if (!cls) {
  3404. cls = namespace[action] = {};
  3405. }
  3406. methods = actions[action];
  3407. for (i = 0, len = methods.length; i < len; ++i) {
  3408. method = new Ext.direct.RemotingMethod(methods[i]);
  3409. cls[method.name] = this.createHandler(action, method);
  3410. }
  3411. }
  3412. }
  3413. }, createHandler:function(action, method) {
  3414. var me = this, handler;
  3415. if (!method.formHandler) {
  3416. handler = function() {
  3417. me.configureRequest(action, method, Array.prototype.slice.call(arguments, 0));
  3418. };
  3419. } else {
  3420. handler = function(form, callback, scope) {
  3421. me.configureFormRequest(action, method, form, callback, scope);
  3422. };
  3423. }
  3424. handler.directCfg = {action:action, method:method};
  3425. return handler;
  3426. }, isConnected:function() {
  3427. return !!this.connected;
  3428. }, connect:function() {
  3429. var me = this;
  3430. if (me.url) {
  3431. me.clientId = Ext.data.amf.XmlEncoder.generateFlexUID();
  3432. me.initAPI();
  3433. me.connected = true;
  3434. me.fireEvent('connect', me);
  3435. me.DSId = null;
  3436. } else {
  3437. if (!me.url) {
  3438. Ext.raise('Error initializing RemotingProvider, no url configured.');
  3439. }
  3440. }
  3441. }, disconnect:function() {
  3442. var me = this;
  3443. if (me.connected) {
  3444. me.connected = false;
  3445. me.fireEvent('disconnect', me);
  3446. }
  3447. }, runCallback:function(transaction, event) {
  3448. var success = !!event.status, funcName = success ? 'success' : 'failure', callback, result;
  3449. if (transaction && transaction.callback) {
  3450. callback = transaction.callback;
  3451. result = Ext.isDefined(event.result) ? event.result : event.data;
  3452. if (Ext.isFunction(callback)) {
  3453. callback(result, event, success);
  3454. } else {
  3455. Ext.callback(callback[funcName], callback.scope, [result, event, success]);
  3456. Ext.callback(callback.callback, callback.scope, [result, event, success]);
  3457. }
  3458. }
  3459. }, onData:function(options, success, response) {
  3460. var me = this, i = 0, len, events, event, transaction, transactions;
  3461. if (success) {
  3462. events = me.createEvents(response);
  3463. for (len = events.length; i < len; ++i) {
  3464. event = events[i];
  3465. transaction = me.getTransaction(event);
  3466. me.fireEvent('data', me, event);
  3467. if (transaction) {
  3468. me.runCallback(transaction, event, true);
  3469. Ext.direct.Manager.removeTransaction(transaction);
  3470. }
  3471. }
  3472. } else {
  3473. transactions = [].concat(options.transaction);
  3474. for (len = transactions.length; i < len; ++i) {
  3475. transaction = me.getTransaction(transactions[i]);
  3476. if (transaction && transaction.retryCount < me.maxRetries) {
  3477. transaction.retry();
  3478. } else {
  3479. event = new Ext.direct.ExceptionEvent({data:null, transaction:transaction, code:Ext.direct.Manager.exceptions.TRANSPORT, message:'Unable to connect to the server.', xhr:response});
  3480. me.fireEvent('data', me, event);
  3481. if (transaction) {
  3482. me.runCallback(transaction, event, false);
  3483. Ext.direct.Manager.removeTransaction(transaction);
  3484. }
  3485. }
  3486. }
  3487. }
  3488. }, getTransaction:function(options) {
  3489. return options && options.tid ? Ext.direct.Manager.getTransaction(options.tid) : null;
  3490. }, configureRequest:function(action, method, args) {
  3491. var me = this, callData = method.getCallData(args), data = callData.data, callback = callData.callback, scope = callData.scope, transaction;
  3492. transaction = new Ext.direct.Transaction({provider:me, args:args, action:action, method:method.name, data:data, callback:scope && Ext.isFunction(callback) ? callback.bind(scope) : callback});
  3493. if (me.fireEvent('beforecall', me, transaction, method) !== false) {
  3494. Ext.direct.Manager.addTransaction(transaction);
  3495. me.queueTransaction(transaction);
  3496. me.fireEvent('call', me, transaction, method);
  3497. }
  3498. }, getCallData:function(transaction) {
  3499. if (this.binary) {
  3500. return {targetUri:transaction.action + '.' + transaction.method, responseUri:'/' + transaction.id, body:transaction.data || []};
  3501. } else {
  3502. return new Ext.data.amf.RemotingMessage({body:transaction.data || [], clientId:this.clientId, destination:transaction.action, headers:{DSEndpoint:this.endpoint, DSId:this.DSId || 'nil'}, messageId:Ext.data.amf.XmlEncoder.generateFlexUID(transaction.id), operation:transaction.method, timestamp:0, timeToLive:0});
  3503. }
  3504. }, sendRequest:function(data) {
  3505. var me = this, request = {url:me.url, callback:me.onData, scope:me, transaction:data, timeout:me.timeout}, i = 0, len, encoder, amfMessages = [], amfHeaders = [];
  3506. if (Ext.isArray(data)) {
  3507. if (!me.binary) {
  3508. Ext.raise('Mutltiple messages in the same call are not supported in AMFX');
  3509. }
  3510. for (len = data.length; i < len; ++i) {
  3511. amfMessages.push(me.getCallData(data[i]));
  3512. }
  3513. } else {
  3514. amfMessages.push(me.getCallData(data));
  3515. }
  3516. if (me.binary) {
  3517. encoder = new Ext.data.amf.Encoder({format:0});
  3518. encoder.writeAmfPacket(amfHeaders, amfMessages);
  3519. request.binaryData = encoder.bytes;
  3520. request.binary = true;
  3521. request.headers = {'Content-Type':'application/x-amf'};
  3522. } else {
  3523. encoder = new Ext.data.amf.XmlEncoder;
  3524. encoder.writeAmfxRemotingPacket(amfMessages[0]);
  3525. request.xmlData = encoder.body;
  3526. }
  3527. Ext.Ajax.request(request);
  3528. }, queueTransaction:function(transaction) {
  3529. var me = this, enableBuffer = false;
  3530. if (transaction.form) {
  3531. me.sendFormRequest(transaction);
  3532. return;
  3533. }
  3534. me.callBuffer.push(transaction);
  3535. if (enableBuffer) {
  3536. if (!me.callTask) {
  3537. me.callTask = new Ext.util.DelayedTask(me.combineAndSend, me);
  3538. }
  3539. me.callTask.delay(Ext.isNumber(enableBuffer) ? enableBuffer : 10);
  3540. } else {
  3541. me.combineAndSend();
  3542. }
  3543. }, combineAndSend:function() {
  3544. var buffer = this.callBuffer, len = buffer.length;
  3545. if (len > 0) {
  3546. this.sendRequest(len === 1 ? buffer[0] : buffer);
  3547. this.callBuffer = [];
  3548. }
  3549. }, configureFormRequest:function(action, method, form, callback, scope) {
  3550. Ext.raise('Form requests are not supported for AmfRemoting');
  3551. }, sendFormRequest:function(transaction) {
  3552. Ext.raise('Form requests are not supported for AmfRemoting');
  3553. }, createEvents:function(response) {
  3554. var data = null, events = [], event, i = 0, decoder;
  3555. try {
  3556. if (this.binary) {
  3557. decoder = new Ext.data.amf.Packet;
  3558. data = decoder.decode(response.responseBytes);
  3559. } else {
  3560. decoder = new Ext.data.amf.XmlDecoder;
  3561. data = decoder.readAmfxMessage(response.responseText);
  3562. }
  3563. } catch (e$0) {
  3564. event = new Ext.direct.ExceptionEvent({data:e$0, xhr:response, code:Ext.direct.Manager.exceptions.PARSE, message:'Error parsing AMF response: \n\n ' + data});
  3565. return [event];
  3566. }
  3567. if (this.binary) {
  3568. for (i = 0; i < data.messages.length; i++) {
  3569. events.push(this.createEvent(data.messages[i]));
  3570. }
  3571. } else {
  3572. events.push(this.createEvent(data));
  3573. }
  3574. return events;
  3575. }, createEvent:function(response) {
  3576. var status = response.targetURI.split('/'), tid, event, data, statusIndex, me = this;
  3577. if (me.binary) {
  3578. tid = status[1];
  3579. statusIndex = 2;
  3580. } else {
  3581. tid = Ext.data.amf.XmlDecoder.decodeTidFromFlexUID(response.message.correlationId);
  3582. statusIndex = 1;
  3583. }
  3584. if (status[statusIndex] === 'onStatus') {
  3585. data = {tid:tid, data:me.binary ? response.body : response.message};
  3586. event = Ext.create('direct.exception', data);
  3587. } else {
  3588. if (status[statusIndex] === 'onResult') {
  3589. data = {tid:tid, data:me.binary ? response.body : response.message.body};
  3590. event = Ext.create('direct.rpc', data);
  3591. } else {
  3592. Ext.raise('Unknown AMF return status: ' + status[statusIndex]);
  3593. }
  3594. }
  3595. return event;
  3596. }});