worker-xml.js 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889
  1. "no use strict";
  2. !(function(window) {
  3. if (typeof window.window != "undefined" && window.document)
  4. return;
  5. if (window.require && window.define)
  6. return;
  7. if (!window.console) {
  8. window.console = function() {
  9. var msgs = Array.prototype.slice.call(arguments, 0);
  10. postMessage({type: "log", data: msgs});
  11. };
  12. window.console.error =
  13. window.console.warn =
  14. window.console.log =
  15. window.console.trace = window.console;
  16. }
  17. window.window = window;
  18. window.ace = window;
  19. window.onerror = function(message, file, line, col, err) {
  20. postMessage({type: "error", data: {
  21. message: message,
  22. data: err.data,
  23. file: file,
  24. line: line,
  25. col: col,
  26. stack: err.stack
  27. }});
  28. };
  29. window.normalizeModule = function(parentId, moduleName) {
  30. // normalize plugin requires
  31. if (moduleName.indexOf("!") !== -1) {
  32. var chunks = moduleName.split("!");
  33. return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
  34. }
  35. // normalize relative requires
  36. if (moduleName.charAt(0) == ".") {
  37. var base = parentId.split("/").slice(0, -1).join("/");
  38. moduleName = (base ? base + "/" : "") + moduleName;
  39. while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
  40. var previous = moduleName;
  41. moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  42. }
  43. }
  44. return moduleName;
  45. };
  46. window.require = function require(parentId, id) {
  47. if (!id) {
  48. id = parentId;
  49. parentId = null;
  50. }
  51. if (!id.charAt)
  52. throw new Error("worker.js require() accepts only (parentId, id) as arguments");
  53. id = window.normalizeModule(parentId, id);
  54. var module = window.require.modules[id];
  55. if (module) {
  56. if (!module.initialized) {
  57. module.initialized = true;
  58. module.exports = module.factory().exports;
  59. }
  60. return module.exports;
  61. }
  62. if (!window.require.tlns)
  63. return console.log("unable to load " + id);
  64. var path = resolveModuleId(id, window.require.tlns);
  65. if (path.slice(-3) != ".js") path += ".js";
  66. window.require.id = id;
  67. window.require.modules[id] = {}; // prevent infinite loop on broken modules
  68. importScripts(path);
  69. return window.require(parentId, id);
  70. };
  71. function resolveModuleId(id, paths) {
  72. var testPath = id, tail = "";
  73. while (testPath) {
  74. var alias = paths[testPath];
  75. if (typeof alias == "string") {
  76. return alias + tail;
  77. } else if (alias) {
  78. return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
  79. } else if (alias === false) {
  80. return "";
  81. }
  82. var i = testPath.lastIndexOf("/");
  83. if (i === -1) break;
  84. tail = testPath.substr(i) + tail;
  85. testPath = testPath.slice(0, i);
  86. }
  87. return id;
  88. }
  89. window.require.modules = {};
  90. window.require.tlns = {};
  91. window.define = function(id, deps, factory) {
  92. if (arguments.length == 2) {
  93. factory = deps;
  94. if (typeof id != "string") {
  95. deps = id;
  96. id = window.require.id;
  97. }
  98. } else if (arguments.length == 1) {
  99. factory = id;
  100. deps = [];
  101. id = window.require.id;
  102. }
  103. if (typeof factory != "function") {
  104. window.require.modules[id] = {
  105. exports: factory,
  106. initialized: true
  107. };
  108. return;
  109. }
  110. if (!deps.length)
  111. // If there is no dependencies, we inject "require", "exports" and
  112. // "module" as dependencies, to provide CommonJS compatibility.
  113. deps = ["require", "exports", "module"];
  114. var req = function(childId) {
  115. return window.require(id, childId);
  116. };
  117. window.require.modules[id] = {
  118. exports: {},
  119. factory: function() {
  120. var module = this;
  121. var returnExports = factory.apply(this, deps.slice(0, factory.length).map(function(dep) {
  122. switch (dep) {
  123. // Because "require", "exports" and "module" aren't actual
  124. // dependencies, we must handle them seperately.
  125. case "require": return req;
  126. case "exports": return module.exports;
  127. case "module": return module;
  128. // But for all other dependencies, we can just go ahead and
  129. // require them.
  130. default: return req(dep);
  131. }
  132. }));
  133. if (returnExports)
  134. module.exports = returnExports;
  135. return module;
  136. }
  137. };
  138. };
  139. window.define.amd = {};
  140. require.tlns = {};
  141. window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
  142. for (var i in topLevelNamespaces)
  143. require.tlns[i] = topLevelNamespaces[i];
  144. };
  145. window.initSender = function initSender() {
  146. var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
  147. var oop = window.require("ace/lib/oop");
  148. var Sender = function() {};
  149. (function() {
  150. oop.implement(this, EventEmitter);
  151. this.callback = function(data, callbackId) {
  152. postMessage({
  153. type: "call",
  154. id: callbackId,
  155. data: data
  156. });
  157. };
  158. this.emit = function(name, data) {
  159. postMessage({
  160. type: "event",
  161. name: name,
  162. data: data
  163. });
  164. };
  165. }).call(Sender.prototype);
  166. return new Sender();
  167. };
  168. var main = window.main = null;
  169. var sender = window.sender = null;
  170. window.onmessage = function(e) {
  171. var msg = e.data;
  172. if (msg.event && sender) {
  173. sender._signal(msg.event, msg.data);
  174. }
  175. else if (msg.command) {
  176. if (main[msg.command])
  177. main[msg.command].apply(main, msg.args);
  178. else if (window[msg.command])
  179. window[msg.command].apply(window, msg.args);
  180. else
  181. throw new Error("Unknown command:" + msg.command);
  182. }
  183. else if (msg.init) {
  184. window.initBaseUrls(msg.tlns);
  185. require("ace/lib/es5-shim");
  186. sender = window.sender = window.initSender();
  187. var clazz = require(msg.module)[msg.classname];
  188. main = window.main = new clazz(sender);
  189. }
  190. };
  191. })(this);
  192. ace.define("ace/lib/oop",[], function(require, exports, module) {
  193. "use strict";
  194. exports.inherits = function(ctor, superCtor) {
  195. ctor.super_ = superCtor;
  196. ctor.prototype = Object.create(superCtor.prototype, {
  197. constructor: {
  198. value: ctor,
  199. enumerable: false,
  200. writable: true,
  201. configurable: true
  202. }
  203. });
  204. };
  205. exports.mixin = function(obj, mixin) {
  206. for (var key in mixin) {
  207. obj[key] = mixin[key];
  208. }
  209. return obj;
  210. };
  211. exports.implement = function(proto, mixin) {
  212. exports.mixin(proto, mixin);
  213. };
  214. });
  215. ace.define("ace/lib/lang",[], function(require, exports, module) {
  216. "use strict";
  217. exports.last = function(a) {
  218. return a[a.length - 1];
  219. };
  220. exports.stringReverse = function(string) {
  221. return string.split("").reverse().join("");
  222. };
  223. exports.stringRepeat = function (string, count) {
  224. var result = '';
  225. while (count > 0) {
  226. if (count & 1)
  227. result += string;
  228. if (count >>= 1)
  229. string += string;
  230. }
  231. return result;
  232. };
  233. var trimBeginRegexp = /^\s\s*/;
  234. var trimEndRegexp = /\s\s*$/;
  235. exports.stringTrimLeft = function (string) {
  236. return string.replace(trimBeginRegexp, '');
  237. };
  238. exports.stringTrimRight = function (string) {
  239. return string.replace(trimEndRegexp, '');
  240. };
  241. exports.copyObject = function(obj) {
  242. var copy = {};
  243. for (var key in obj) {
  244. copy[key] = obj[key];
  245. }
  246. return copy;
  247. };
  248. exports.copyArray = function(array){
  249. var copy = [];
  250. for (var i=0, l=array.length; i<l; i++) {
  251. if (array[i] && typeof array[i] == "object")
  252. copy[i] = this.copyObject(array[i]);
  253. else
  254. copy[i] = array[i];
  255. }
  256. return copy;
  257. };
  258. exports.deepCopy = function deepCopy(obj) {
  259. if (typeof obj !== "object" || !obj)
  260. return obj;
  261. var copy;
  262. if (Array.isArray(obj)) {
  263. copy = [];
  264. for (var key = 0; key < obj.length; key++) {
  265. copy[key] = deepCopy(obj[key]);
  266. }
  267. return copy;
  268. }
  269. if (Object.prototype.toString.call(obj) !== "[object Object]")
  270. return obj;
  271. copy = {};
  272. for (var key in obj)
  273. copy[key] = deepCopy(obj[key]);
  274. return copy;
  275. };
  276. exports.arrayToMap = function(arr) {
  277. var map = {};
  278. for (var i=0; i<arr.length; i++) {
  279. map[arr[i]] = 1;
  280. }
  281. return map;
  282. };
  283. exports.createMap = function(props) {
  284. var map = Object.create(null);
  285. for (var i in props) {
  286. map[i] = props[i];
  287. }
  288. return map;
  289. };
  290. exports.arrayRemove = function(array, value) {
  291. for (var i = 0; i <= array.length; i++) {
  292. if (value === array[i]) {
  293. array.splice(i, 1);
  294. }
  295. }
  296. };
  297. exports.escapeRegExp = function(str) {
  298. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  299. };
  300. exports.escapeHTML = function(str) {
  301. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  302. };
  303. exports.getMatchOffsets = function(string, regExp) {
  304. var matches = [];
  305. string.replace(regExp, function(str) {
  306. matches.push({
  307. offset: arguments[arguments.length-2],
  308. length: str.length
  309. });
  310. });
  311. return matches;
  312. };
  313. exports.deferredCall = function(fcn) {
  314. var timer = null;
  315. var callback = function() {
  316. timer = null;
  317. fcn();
  318. };
  319. var deferred = function(timeout) {
  320. deferred.cancel();
  321. timer = setTimeout(callback, timeout || 0);
  322. return deferred;
  323. };
  324. deferred.schedule = deferred;
  325. deferred.call = function() {
  326. this.cancel();
  327. fcn();
  328. return deferred;
  329. };
  330. deferred.cancel = function() {
  331. clearTimeout(timer);
  332. timer = null;
  333. return deferred;
  334. };
  335. deferred.isPending = function() {
  336. return timer;
  337. };
  338. return deferred;
  339. };
  340. exports.delayedCall = function(fcn, defaultTimeout) {
  341. var timer = null;
  342. var callback = function() {
  343. timer = null;
  344. fcn();
  345. };
  346. var _self = function(timeout) {
  347. if (timer == null)
  348. timer = setTimeout(callback, timeout || defaultTimeout);
  349. };
  350. _self.delay = function(timeout) {
  351. timer && clearTimeout(timer);
  352. timer = setTimeout(callback, timeout || defaultTimeout);
  353. };
  354. _self.schedule = _self;
  355. _self.call = function() {
  356. this.cancel();
  357. fcn();
  358. };
  359. _self.cancel = function() {
  360. timer && clearTimeout(timer);
  361. timer = null;
  362. };
  363. _self.isPending = function() {
  364. return timer;
  365. };
  366. return _self;
  367. };
  368. });
  369. ace.define("ace/range",[], function(require, exports, module) {
  370. "use strict";
  371. var comparePoints = function(p1, p2) {
  372. return p1.row - p2.row || p1.column - p2.column;
  373. };
  374. var Range = function(startRow, startColumn, endRow, endColumn) {
  375. this.start = {
  376. row: startRow,
  377. column: startColumn
  378. };
  379. this.end = {
  380. row: endRow,
  381. column: endColumn
  382. };
  383. };
  384. (function() {
  385. this.isEqual = function(range) {
  386. return this.start.row === range.start.row &&
  387. this.end.row === range.end.row &&
  388. this.start.column === range.start.column &&
  389. this.end.column === range.end.column;
  390. };
  391. this.toString = function() {
  392. return ("Range: [" + this.start.row + "/" + this.start.column +
  393. "] -> [" + this.end.row + "/" + this.end.column + "]");
  394. };
  395. this.contains = function(row, column) {
  396. return this.compare(row, column) == 0;
  397. };
  398. this.compareRange = function(range) {
  399. var cmp,
  400. end = range.end,
  401. start = range.start;
  402. cmp = this.compare(end.row, end.column);
  403. if (cmp == 1) {
  404. cmp = this.compare(start.row, start.column);
  405. if (cmp == 1) {
  406. return 2;
  407. } else if (cmp == 0) {
  408. return 1;
  409. } else {
  410. return 0;
  411. }
  412. } else if (cmp == -1) {
  413. return -2;
  414. } else {
  415. cmp = this.compare(start.row, start.column);
  416. if (cmp == -1) {
  417. return -1;
  418. } else if (cmp == 1) {
  419. return 42;
  420. } else {
  421. return 0;
  422. }
  423. }
  424. };
  425. this.comparePoint = function(p) {
  426. return this.compare(p.row, p.column);
  427. };
  428. this.containsRange = function(range) {
  429. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  430. };
  431. this.intersects = function(range) {
  432. var cmp = this.compareRange(range);
  433. return (cmp == -1 || cmp == 0 || cmp == 1);
  434. };
  435. this.isEnd = function(row, column) {
  436. return this.end.row == row && this.end.column == column;
  437. };
  438. this.isStart = function(row, column) {
  439. return this.start.row == row && this.start.column == column;
  440. };
  441. this.setStart = function(row, column) {
  442. if (typeof row == "object") {
  443. this.start.column = row.column;
  444. this.start.row = row.row;
  445. } else {
  446. this.start.row = row;
  447. this.start.column = column;
  448. }
  449. };
  450. this.setEnd = function(row, column) {
  451. if (typeof row == "object") {
  452. this.end.column = row.column;
  453. this.end.row = row.row;
  454. } else {
  455. this.end.row = row;
  456. this.end.column = column;
  457. }
  458. };
  459. this.inside = function(row, column) {
  460. if (this.compare(row, column) == 0) {
  461. if (this.isEnd(row, column) || this.isStart(row, column)) {
  462. return false;
  463. } else {
  464. return true;
  465. }
  466. }
  467. return false;
  468. };
  469. this.insideStart = function(row, column) {
  470. if (this.compare(row, column) == 0) {
  471. if (this.isEnd(row, column)) {
  472. return false;
  473. } else {
  474. return true;
  475. }
  476. }
  477. return false;
  478. };
  479. this.insideEnd = function(row, column) {
  480. if (this.compare(row, column) == 0) {
  481. if (this.isStart(row, column)) {
  482. return false;
  483. } else {
  484. return true;
  485. }
  486. }
  487. return false;
  488. };
  489. this.compare = function(row, column) {
  490. if (!this.isMultiLine()) {
  491. if (row === this.start.row) {
  492. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  493. }
  494. }
  495. if (row < this.start.row)
  496. return -1;
  497. if (row > this.end.row)
  498. return 1;
  499. if (this.start.row === row)
  500. return column >= this.start.column ? 0 : -1;
  501. if (this.end.row === row)
  502. return column <= this.end.column ? 0 : 1;
  503. return 0;
  504. };
  505. this.compareStart = function(row, column) {
  506. if (this.start.row == row && this.start.column == column) {
  507. return -1;
  508. } else {
  509. return this.compare(row, column);
  510. }
  511. };
  512. this.compareEnd = function(row, column) {
  513. if (this.end.row == row && this.end.column == column) {
  514. return 1;
  515. } else {
  516. return this.compare(row, column);
  517. }
  518. };
  519. this.compareInside = function(row, column) {
  520. if (this.end.row == row && this.end.column == column) {
  521. return 1;
  522. } else if (this.start.row == row && this.start.column == column) {
  523. return -1;
  524. } else {
  525. return this.compare(row, column);
  526. }
  527. };
  528. this.clipRows = function(firstRow, lastRow) {
  529. if (this.end.row > lastRow)
  530. var end = {row: lastRow + 1, column: 0};
  531. else if (this.end.row < firstRow)
  532. var end = {row: firstRow, column: 0};
  533. if (this.start.row > lastRow)
  534. var start = {row: lastRow + 1, column: 0};
  535. else if (this.start.row < firstRow)
  536. var start = {row: firstRow, column: 0};
  537. return Range.fromPoints(start || this.start, end || this.end);
  538. };
  539. this.extend = function(row, column) {
  540. var cmp = this.compare(row, column);
  541. if (cmp == 0)
  542. return this;
  543. else if (cmp == -1)
  544. var start = {row: row, column: column};
  545. else
  546. var end = {row: row, column: column};
  547. return Range.fromPoints(start || this.start, end || this.end);
  548. };
  549. this.isEmpty = function() {
  550. return (this.start.row === this.end.row && this.start.column === this.end.column);
  551. };
  552. this.isMultiLine = function() {
  553. return (this.start.row !== this.end.row);
  554. };
  555. this.clone = function() {
  556. return Range.fromPoints(this.start, this.end);
  557. };
  558. this.collapseRows = function() {
  559. if (this.end.column == 0)
  560. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  561. else
  562. return new Range(this.start.row, 0, this.end.row, 0);
  563. };
  564. this.toScreenRange = function(session) {
  565. var screenPosStart = session.documentToScreenPosition(this.start);
  566. var screenPosEnd = session.documentToScreenPosition(this.end);
  567. return new Range(
  568. screenPosStart.row, screenPosStart.column,
  569. screenPosEnd.row, screenPosEnd.column
  570. );
  571. };
  572. this.moveBy = function(row, column) {
  573. this.start.row += row;
  574. this.start.column += column;
  575. this.end.row += row;
  576. this.end.column += column;
  577. };
  578. }).call(Range.prototype);
  579. Range.fromPoints = function(start, end) {
  580. return new Range(start.row, start.column, end.row, end.column);
  581. };
  582. Range.comparePoints = comparePoints;
  583. Range.comparePoints = function(p1, p2) {
  584. return p1.row - p2.row || p1.column - p2.column;
  585. };
  586. exports.Range = Range;
  587. });
  588. ace.define("ace/apply_delta",[], function(require, exports, module) {
  589. "use strict";
  590. function throwDeltaError(delta, errorText){
  591. console.log("Invalid Delta:", delta);
  592. throw "Invalid Delta: " + errorText;
  593. }
  594. function positionInDocument(docLines, position) {
  595. return position.row >= 0 && position.row < docLines.length &&
  596. position.column >= 0 && position.column <= docLines[position.row].length;
  597. }
  598. function validateDelta(docLines, delta) {
  599. if (delta.action != "insert" && delta.action != "remove")
  600. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  601. if (!(delta.lines instanceof Array))
  602. throwDeltaError(delta, "delta.lines must be an Array");
  603. if (!delta.start || !delta.end)
  604. throwDeltaError(delta, "delta.start/end must be an present");
  605. var start = delta.start;
  606. if (!positionInDocument(docLines, delta.start))
  607. throwDeltaError(delta, "delta.start must be contained in document");
  608. var end = delta.end;
  609. if (delta.action == "remove" && !positionInDocument(docLines, end))
  610. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  611. var numRangeRows = end.row - start.row;
  612. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  613. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  614. throwDeltaError(delta, "delta.range must match delta lines");
  615. }
  616. exports.applyDelta = function(docLines, delta, doNotValidate) {
  617. var row = delta.start.row;
  618. var startColumn = delta.start.column;
  619. var line = docLines[row] || "";
  620. switch (delta.action) {
  621. case "insert":
  622. var lines = delta.lines;
  623. if (lines.length === 1) {
  624. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  625. } else {
  626. var args = [row, 1].concat(delta.lines);
  627. docLines.splice.apply(docLines, args);
  628. docLines[row] = line.substring(0, startColumn) + docLines[row];
  629. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  630. }
  631. break;
  632. case "remove":
  633. var endColumn = delta.end.column;
  634. var endRow = delta.end.row;
  635. if (row === endRow) {
  636. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  637. } else {
  638. docLines.splice(
  639. row, endRow - row + 1,
  640. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  641. );
  642. }
  643. break;
  644. }
  645. };
  646. });
  647. ace.define("ace/lib/event_emitter",[], function(require, exports, module) {
  648. "use strict";
  649. var EventEmitter = {};
  650. var stopPropagation = function() { this.propagationStopped = true; };
  651. var preventDefault = function() { this.defaultPrevented = true; };
  652. EventEmitter._emit =
  653. EventEmitter._dispatchEvent = function(eventName, e) {
  654. this._eventRegistry || (this._eventRegistry = {});
  655. this._defaultHandlers || (this._defaultHandlers = {});
  656. var listeners = this._eventRegistry[eventName] || [];
  657. var defaultHandler = this._defaultHandlers[eventName];
  658. if (!listeners.length && !defaultHandler)
  659. return;
  660. if (typeof e != "object" || !e)
  661. e = {};
  662. if (!e.type)
  663. e.type = eventName;
  664. if (!e.stopPropagation)
  665. e.stopPropagation = stopPropagation;
  666. if (!e.preventDefault)
  667. e.preventDefault = preventDefault;
  668. listeners = listeners.slice();
  669. for (var i=0; i<listeners.length; i++) {
  670. listeners[i](e, this);
  671. if (e.propagationStopped)
  672. break;
  673. }
  674. if (defaultHandler && !e.defaultPrevented)
  675. return defaultHandler(e, this);
  676. };
  677. EventEmitter._signal = function(eventName, e) {
  678. var listeners = (this._eventRegistry || {})[eventName];
  679. if (!listeners)
  680. return;
  681. listeners = listeners.slice();
  682. for (var i=0; i<listeners.length; i++)
  683. listeners[i](e, this);
  684. };
  685. EventEmitter.once = function(eventName, callback) {
  686. var _self = this;
  687. this.addEventListener(eventName, function newCallback() {
  688. _self.removeEventListener(eventName, newCallback);
  689. callback.apply(null, arguments);
  690. });
  691. if (!callback) {
  692. return new Promise(function(resolve) {
  693. callback = resolve;
  694. });
  695. }
  696. };
  697. EventEmitter.setDefaultHandler = function(eventName, callback) {
  698. var handlers = this._defaultHandlers;
  699. if (!handlers)
  700. handlers = this._defaultHandlers = {_disabled_: {}};
  701. if (handlers[eventName]) {
  702. var old = handlers[eventName];
  703. var disabled = handlers._disabled_[eventName];
  704. if (!disabled)
  705. handlers._disabled_[eventName] = disabled = [];
  706. disabled.push(old);
  707. var i = disabled.indexOf(callback);
  708. if (i != -1)
  709. disabled.splice(i, 1);
  710. }
  711. handlers[eventName] = callback;
  712. };
  713. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  714. var handlers = this._defaultHandlers;
  715. if (!handlers)
  716. return;
  717. var disabled = handlers._disabled_[eventName];
  718. if (handlers[eventName] == callback) {
  719. if (disabled)
  720. this.setDefaultHandler(eventName, disabled.pop());
  721. } else if (disabled) {
  722. var i = disabled.indexOf(callback);
  723. if (i != -1)
  724. disabled.splice(i, 1);
  725. }
  726. };
  727. EventEmitter.on =
  728. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  729. this._eventRegistry = this._eventRegistry || {};
  730. var listeners = this._eventRegistry[eventName];
  731. if (!listeners)
  732. listeners = this._eventRegistry[eventName] = [];
  733. if (listeners.indexOf(callback) == -1)
  734. listeners[capturing ? "unshift" : "push"](callback);
  735. return callback;
  736. };
  737. EventEmitter.off =
  738. EventEmitter.removeListener =
  739. EventEmitter.removeEventListener = function(eventName, callback) {
  740. this._eventRegistry = this._eventRegistry || {};
  741. var listeners = this._eventRegistry[eventName];
  742. if (!listeners)
  743. return;
  744. var index = listeners.indexOf(callback);
  745. if (index !== -1)
  746. listeners.splice(index, 1);
  747. };
  748. EventEmitter.removeAllListeners = function(eventName) {
  749. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  750. };
  751. exports.EventEmitter = EventEmitter;
  752. });
  753. ace.define("ace/anchor",[], function(require, exports, module) {
  754. "use strict";
  755. var oop = require("./lib/oop");
  756. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  757. var Anchor = exports.Anchor = function(doc, row, column) {
  758. this.$onChange = this.onChange.bind(this);
  759. this.attach(doc);
  760. if (typeof column == "undefined")
  761. this.setPosition(row.row, row.column);
  762. else
  763. this.setPosition(row, column);
  764. };
  765. (function() {
  766. oop.implement(this, EventEmitter);
  767. this.getPosition = function() {
  768. return this.$clipPositionToDocument(this.row, this.column);
  769. };
  770. this.getDocument = function() {
  771. return this.document;
  772. };
  773. this.$insertRight = false;
  774. this.onChange = function(delta) {
  775. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  776. return;
  777. if (delta.start.row > this.row)
  778. return;
  779. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  780. this.setPosition(point.row, point.column, true);
  781. };
  782. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  783. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  784. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  785. }
  786. function $getTransformedPoint(delta, point, moveIfEqual) {
  787. var deltaIsInsert = delta.action == "insert";
  788. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  789. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  790. var deltaStart = delta.start;
  791. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  792. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  793. return {
  794. row: point.row,
  795. column: point.column
  796. };
  797. }
  798. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  799. return {
  800. row: point.row + deltaRowShift,
  801. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  802. };
  803. }
  804. return {
  805. row: deltaStart.row,
  806. column: deltaStart.column
  807. };
  808. }
  809. this.setPosition = function(row, column, noClip) {
  810. var pos;
  811. if (noClip) {
  812. pos = {
  813. row: row,
  814. column: column
  815. };
  816. } else {
  817. pos = this.$clipPositionToDocument(row, column);
  818. }
  819. if (this.row == pos.row && this.column == pos.column)
  820. return;
  821. var old = {
  822. row: this.row,
  823. column: this.column
  824. };
  825. this.row = pos.row;
  826. this.column = pos.column;
  827. this._signal("change", {
  828. old: old,
  829. value: pos
  830. });
  831. };
  832. this.detach = function() {
  833. this.document.removeEventListener("change", this.$onChange);
  834. };
  835. this.attach = function(doc) {
  836. this.document = doc || this.document;
  837. this.document.on("change", this.$onChange);
  838. };
  839. this.$clipPositionToDocument = function(row, column) {
  840. var pos = {};
  841. if (row >= this.document.getLength()) {
  842. pos.row = Math.max(0, this.document.getLength() - 1);
  843. pos.column = this.document.getLine(pos.row).length;
  844. }
  845. else if (row < 0) {
  846. pos.row = 0;
  847. pos.column = 0;
  848. }
  849. else {
  850. pos.row = row;
  851. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  852. }
  853. if (column < 0)
  854. pos.column = 0;
  855. return pos;
  856. };
  857. }).call(Anchor.prototype);
  858. });
  859. ace.define("ace/document",[], function(require, exports, module) {
  860. "use strict";
  861. var oop = require("./lib/oop");
  862. var applyDelta = require("./apply_delta").applyDelta;
  863. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  864. var Range = require("./range").Range;
  865. var Anchor = require("./anchor").Anchor;
  866. var Document = function(textOrLines) {
  867. this.$lines = [""];
  868. if (textOrLines.length === 0) {
  869. this.$lines = [""];
  870. } else if (Array.isArray(textOrLines)) {
  871. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  872. } else {
  873. this.insert({row: 0, column:0}, textOrLines);
  874. }
  875. };
  876. (function() {
  877. oop.implement(this, EventEmitter);
  878. this.setValue = function(text) {
  879. var len = this.getLength() - 1;
  880. this.remove(new Range(0, 0, len, this.getLine(len).length));
  881. this.insert({row: 0, column: 0}, text);
  882. };
  883. this.getValue = function() {
  884. return this.getAllLines().join(this.getNewLineCharacter());
  885. };
  886. this.createAnchor = function(row, column) {
  887. return new Anchor(this, row, column);
  888. };
  889. if ("aaa".split(/a/).length === 0) {
  890. this.$split = function(text) {
  891. return text.replace(/\r\n|\r/g, "\n").split("\n");
  892. };
  893. } else {
  894. this.$split = function(text) {
  895. return text.split(/\r\n|\r|\n/);
  896. };
  897. }
  898. this.$detectNewLine = function(text) {
  899. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  900. this.$autoNewLine = match ? match[1] : "\n";
  901. this._signal("changeNewLineMode");
  902. };
  903. this.getNewLineCharacter = function() {
  904. switch (this.$newLineMode) {
  905. case "windows":
  906. return "\r\n";
  907. case "unix":
  908. return "\n";
  909. default:
  910. return this.$autoNewLine || "\n";
  911. }
  912. };
  913. this.$autoNewLine = "";
  914. this.$newLineMode = "auto";
  915. this.setNewLineMode = function(newLineMode) {
  916. if (this.$newLineMode === newLineMode)
  917. return;
  918. this.$newLineMode = newLineMode;
  919. this._signal("changeNewLineMode");
  920. };
  921. this.getNewLineMode = function() {
  922. return this.$newLineMode;
  923. };
  924. this.isNewLine = function(text) {
  925. return (text == "\r\n" || text == "\r" || text == "\n");
  926. };
  927. this.getLine = function(row) {
  928. return this.$lines[row] || "";
  929. };
  930. this.getLines = function(firstRow, lastRow) {
  931. return this.$lines.slice(firstRow, lastRow + 1);
  932. };
  933. this.getAllLines = function() {
  934. return this.getLines(0, this.getLength());
  935. };
  936. this.getLength = function() {
  937. return this.$lines.length;
  938. };
  939. this.getTextRange = function(range) {
  940. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  941. };
  942. this.getLinesForRange = function(range) {
  943. var lines;
  944. if (range.start.row === range.end.row) {
  945. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  946. } else {
  947. lines = this.getLines(range.start.row, range.end.row);
  948. lines[0] = (lines[0] || "").substring(range.start.column);
  949. var l = lines.length - 1;
  950. if (range.end.row - range.start.row == l)
  951. lines[l] = lines[l].substring(0, range.end.column);
  952. }
  953. return lines;
  954. };
  955. this.insertLines = function(row, lines) {
  956. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  957. return this.insertFullLines(row, lines);
  958. };
  959. this.removeLines = function(firstRow, lastRow) {
  960. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  961. return this.removeFullLines(firstRow, lastRow);
  962. };
  963. this.insertNewLine = function(position) {
  964. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  965. return this.insertMergedLines(position, ["", ""]);
  966. };
  967. this.insert = function(position, text) {
  968. if (this.getLength() <= 1)
  969. this.$detectNewLine(text);
  970. return this.insertMergedLines(position, this.$split(text));
  971. };
  972. this.insertInLine = function(position, text) {
  973. var start = this.clippedPos(position.row, position.column);
  974. var end = this.pos(position.row, position.column + text.length);
  975. this.applyDelta({
  976. start: start,
  977. end: end,
  978. action: "insert",
  979. lines: [text]
  980. }, true);
  981. return this.clonePos(end);
  982. };
  983. this.clippedPos = function(row, column) {
  984. var length = this.getLength();
  985. if (row === undefined) {
  986. row = length;
  987. } else if (row < 0) {
  988. row = 0;
  989. } else if (row >= length) {
  990. row = length - 1;
  991. column = undefined;
  992. }
  993. var line = this.getLine(row);
  994. if (column == undefined)
  995. column = line.length;
  996. column = Math.min(Math.max(column, 0), line.length);
  997. return {row: row, column: column};
  998. };
  999. this.clonePos = function(pos) {
  1000. return {row: pos.row, column: pos.column};
  1001. };
  1002. this.pos = function(row, column) {
  1003. return {row: row, column: column};
  1004. };
  1005. this.$clipPosition = function(position) {
  1006. var length = this.getLength();
  1007. if (position.row >= length) {
  1008. position.row = Math.max(0, length - 1);
  1009. position.column = this.getLine(length - 1).length;
  1010. } else {
  1011. position.row = Math.max(0, position.row);
  1012. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  1013. }
  1014. return position;
  1015. };
  1016. this.insertFullLines = function(row, lines) {
  1017. row = Math.min(Math.max(row, 0), this.getLength());
  1018. var column = 0;
  1019. if (row < this.getLength()) {
  1020. lines = lines.concat([""]);
  1021. column = 0;
  1022. } else {
  1023. lines = [""].concat(lines);
  1024. row--;
  1025. column = this.$lines[row].length;
  1026. }
  1027. this.insertMergedLines({row: row, column: column}, lines);
  1028. };
  1029. this.insertMergedLines = function(position, lines) {
  1030. var start = this.clippedPos(position.row, position.column);
  1031. var end = {
  1032. row: start.row + lines.length - 1,
  1033. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  1034. };
  1035. this.applyDelta({
  1036. start: start,
  1037. end: end,
  1038. action: "insert",
  1039. lines: lines
  1040. });
  1041. return this.clonePos(end);
  1042. };
  1043. this.remove = function(range) {
  1044. var start = this.clippedPos(range.start.row, range.start.column);
  1045. var end = this.clippedPos(range.end.row, range.end.column);
  1046. this.applyDelta({
  1047. start: start,
  1048. end: end,
  1049. action: "remove",
  1050. lines: this.getLinesForRange({start: start, end: end})
  1051. });
  1052. return this.clonePos(start);
  1053. };
  1054. this.removeInLine = function(row, startColumn, endColumn) {
  1055. var start = this.clippedPos(row, startColumn);
  1056. var end = this.clippedPos(row, endColumn);
  1057. this.applyDelta({
  1058. start: start,
  1059. end: end,
  1060. action: "remove",
  1061. lines: this.getLinesForRange({start: start, end: end})
  1062. }, true);
  1063. return this.clonePos(start);
  1064. };
  1065. this.removeFullLines = function(firstRow, lastRow) {
  1066. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  1067. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  1068. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  1069. var deleteLastNewLine = lastRow < this.getLength() - 1;
  1070. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  1071. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  1072. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  1073. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  1074. var range = new Range(startRow, startCol, endRow, endCol);
  1075. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  1076. this.applyDelta({
  1077. start: range.start,
  1078. end: range.end,
  1079. action: "remove",
  1080. lines: this.getLinesForRange(range)
  1081. });
  1082. return deletedLines;
  1083. };
  1084. this.removeNewLine = function(row) {
  1085. if (row < this.getLength() - 1 && row >= 0) {
  1086. this.applyDelta({
  1087. start: this.pos(row, this.getLine(row).length),
  1088. end: this.pos(row + 1, 0),
  1089. action: "remove",
  1090. lines: ["", ""]
  1091. });
  1092. }
  1093. };
  1094. this.replace = function(range, text) {
  1095. if (!(range instanceof Range))
  1096. range = Range.fromPoints(range.start, range.end);
  1097. if (text.length === 0 && range.isEmpty())
  1098. return range.start;
  1099. if (text == this.getTextRange(range))
  1100. return range.end;
  1101. this.remove(range);
  1102. var end;
  1103. if (text) {
  1104. end = this.insert(range.start, text);
  1105. }
  1106. else {
  1107. end = range.start;
  1108. }
  1109. return end;
  1110. };
  1111. this.applyDeltas = function(deltas) {
  1112. for (var i=0; i<deltas.length; i++) {
  1113. this.applyDelta(deltas[i]);
  1114. }
  1115. };
  1116. this.revertDeltas = function(deltas) {
  1117. for (var i=deltas.length-1; i>=0; i--) {
  1118. this.revertDelta(deltas[i]);
  1119. }
  1120. };
  1121. this.applyDelta = function(delta, doNotValidate) {
  1122. var isInsert = delta.action == "insert";
  1123. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  1124. : !Range.comparePoints(delta.start, delta.end)) {
  1125. return;
  1126. }
  1127. if (isInsert && delta.lines.length > 20000) {
  1128. this.$splitAndapplyLargeDelta(delta, 20000);
  1129. }
  1130. else {
  1131. applyDelta(this.$lines, delta, doNotValidate);
  1132. this._signal("change", delta);
  1133. }
  1134. };
  1135. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  1136. var lines = delta.lines;
  1137. var l = lines.length - MAX + 1;
  1138. var row = delta.start.row;
  1139. var column = delta.start.column;
  1140. for (var from = 0, to = 0; from < l; from = to) {
  1141. to += MAX - 1;
  1142. var chunk = lines.slice(from, to);
  1143. chunk.push("");
  1144. this.applyDelta({
  1145. start: this.pos(row + from, column),
  1146. end: this.pos(row + to, column = 0),
  1147. action: delta.action,
  1148. lines: chunk
  1149. }, true);
  1150. }
  1151. delta.lines = lines.slice(from);
  1152. delta.start.row = row + from;
  1153. delta.start.column = column;
  1154. this.applyDelta(delta, true);
  1155. };
  1156. this.revertDelta = function(delta) {
  1157. this.applyDelta({
  1158. start: this.clonePos(delta.start),
  1159. end: this.clonePos(delta.end),
  1160. action: (delta.action == "insert" ? "remove" : "insert"),
  1161. lines: delta.lines.slice()
  1162. });
  1163. };
  1164. this.indexToPosition = function(index, startRow) {
  1165. var lines = this.$lines || this.getAllLines();
  1166. var newlineLength = this.getNewLineCharacter().length;
  1167. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1168. index -= lines[i].length + newlineLength;
  1169. if (index < 0)
  1170. return {row: i, column: index + lines[i].length + newlineLength};
  1171. }
  1172. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  1173. };
  1174. this.positionToIndex = function(pos, startRow) {
  1175. var lines = this.$lines || this.getAllLines();
  1176. var newlineLength = this.getNewLineCharacter().length;
  1177. var index = 0;
  1178. var row = Math.min(pos.row, lines.length);
  1179. for (var i = startRow || 0; i < row; ++i)
  1180. index += lines[i].length + newlineLength;
  1181. return index + pos.column;
  1182. };
  1183. }).call(Document.prototype);
  1184. exports.Document = Document;
  1185. });
  1186. ace.define("ace/worker/mirror",[], function(require, exports, module) {
  1187. "use strict";
  1188. var Range = require("../range").Range;
  1189. var Document = require("../document").Document;
  1190. var lang = require("../lib/lang");
  1191. var Mirror = exports.Mirror = function(sender) {
  1192. this.sender = sender;
  1193. var doc = this.doc = new Document("");
  1194. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1195. var _self = this;
  1196. sender.on("change", function(e) {
  1197. var data = e.data;
  1198. if (data[0].start) {
  1199. doc.applyDeltas(data);
  1200. } else {
  1201. for (var i = 0; i < data.length; i += 2) {
  1202. if (Array.isArray(data[i+1])) {
  1203. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1204. } else {
  1205. var d = {action: "remove", start: data[i], end: data[i+1]};
  1206. }
  1207. doc.applyDelta(d, true);
  1208. }
  1209. }
  1210. if (_self.$timeout)
  1211. return deferredUpdate.schedule(_self.$timeout);
  1212. _self.onUpdate();
  1213. });
  1214. };
  1215. (function() {
  1216. this.$timeout = 500;
  1217. this.setTimeout = function(timeout) {
  1218. this.$timeout = timeout;
  1219. };
  1220. this.setValue = function(value) {
  1221. this.doc.setValue(value);
  1222. this.deferredUpdate.schedule(this.$timeout);
  1223. };
  1224. this.getValue = function(callbackId) {
  1225. this.sender.callback(this.doc.getValue(), callbackId);
  1226. };
  1227. this.onUpdate = function() {
  1228. };
  1229. this.isPending = function() {
  1230. return this.deferredUpdate.isPending();
  1231. };
  1232. }).call(Mirror.prototype);
  1233. });
  1234. ace.define("ace/mode/xml/sax",[], function(require, exports, module) {
  1235. var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
  1236. var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\u00B7\u0300-\u036F\\ux203F-\u2040]");
  1237. var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
  1238. var S_TAG = 0;//tag name offerring
  1239. var S_ATTR = 1;//attr name offerring
  1240. var S_ATTR_S=2;//attr name end and space offer
  1241. var S_EQ = 3;//=space?
  1242. var S_V = 4;//attr value(no quot value only)
  1243. var S_E = 5;//attr value end and no space(quot end)
  1244. var S_S = 6;//(attr value end || tag end ) && (space offer)
  1245. var S_C = 7;//closed el<el />
  1246. function XMLReader(){
  1247. }
  1248. XMLReader.prototype = {
  1249. parse:function(source,defaultNSMap,entityMap){
  1250. var domBuilder = this.domBuilder;
  1251. domBuilder.startDocument();
  1252. _copy(defaultNSMap ,defaultNSMap = {})
  1253. parse(source,defaultNSMap,entityMap,
  1254. domBuilder,this.errorHandler);
  1255. domBuilder.endDocument();
  1256. }
  1257. }
  1258. function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
  1259. function fixedFromCharCode(code) {
  1260. if (code > 0xffff) {
  1261. code -= 0x10000;
  1262. var surrogate1 = 0xd800 + (code >> 10)
  1263. , surrogate2 = 0xdc00 + (code & 0x3ff);
  1264. return String.fromCharCode(surrogate1, surrogate2);
  1265. } else {
  1266. return String.fromCharCode(code);
  1267. }
  1268. }
  1269. function entityReplacer(a){
  1270. var k = a.slice(1,-1);
  1271. if(k in entityMap){
  1272. return entityMap[k];
  1273. }else if(k.charAt(0) === '#'){
  1274. return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
  1275. }else{
  1276. errorHandler.error('entity not found:'+a);
  1277. return a;
  1278. }
  1279. }
  1280. function appendText(end){//has some bugs
  1281. var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
  1282. locator&&position(start);
  1283. domBuilder.characters(xt,0,end-start);
  1284. start = end
  1285. }
  1286. function position(start,m){
  1287. while(start>=endPos && (m = linePattern.exec(source))){
  1288. startPos = m.index;
  1289. endPos = startPos + m[0].length;
  1290. locator.lineNumber++;
  1291. }
  1292. locator.columnNumber = start-startPos+1;
  1293. }
  1294. var startPos = 0;
  1295. var endPos = 0;
  1296. var linePattern = /.+(?:\r\n?|\n)|.*$/g
  1297. var locator = domBuilder.locator;
  1298. var parseStack = [{currentNSMap:defaultNSMapCopy}]
  1299. var closeMap = {};
  1300. var start = 0;
  1301. while(true){
  1302. var i = source.indexOf('<',start);
  1303. if(i<0){
  1304. if(!source.substr(start).match(/^\s*$/)){
  1305. var doc = domBuilder.document;
  1306. var text = doc.createTextNode(source.substr(start));
  1307. doc.appendChild(text);
  1308. domBuilder.currentElement = text;
  1309. }
  1310. return;
  1311. }
  1312. if(i>start){
  1313. appendText(i);
  1314. }
  1315. switch(source.charAt(i+1)){
  1316. case '/':
  1317. var end = source.indexOf('>',i+3);
  1318. var tagName = source.substring(i+2,end);
  1319. var config;
  1320. if (parseStack.length > 1) {
  1321. config = parseStack.pop();
  1322. } else {
  1323. errorHandler.fatalError("end tag name not found for: "+tagName);
  1324. break;
  1325. }
  1326. var localNSMap = config.localNSMap;
  1327. if(config.tagName != tagName){
  1328. errorHandler.fatalError("end tag name: " + tagName + " does not match the current start tagName: "+config.tagName );
  1329. }
  1330. domBuilder.endElement(config.uri,config.localName,tagName);
  1331. if(localNSMap){
  1332. for(var prefix in localNSMap){
  1333. domBuilder.endPrefixMapping(prefix) ;
  1334. }
  1335. }
  1336. end++;
  1337. break;
  1338. case '?':// <?...?>
  1339. locator&&position(i);
  1340. end = parseInstruction(source,i,domBuilder);
  1341. break;
  1342. case '!':// <!doctype,<![CDATA,<!--
  1343. locator&&position(i);
  1344. end = parseDCC(source,i,domBuilder,errorHandler);
  1345. break;
  1346. default:
  1347. try{
  1348. locator&&position(i);
  1349. var el = new ElementAttributes();
  1350. var end = parseElementStartPart(source,i,el,entityReplacer,errorHandler);
  1351. var len = el.length;
  1352. if(len && locator){
  1353. var backup = copyLocator(locator,{});
  1354. for(var i = 0;i<len;i++){
  1355. var a = el[i];
  1356. position(a.offset);
  1357. a.offset = copyLocator(locator,{});
  1358. }
  1359. copyLocator(backup,locator);
  1360. }
  1361. if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
  1362. el.closed = true;
  1363. if(!entityMap.nbsp){
  1364. errorHandler.warning('unclosed xml attribute');
  1365. }
  1366. }
  1367. appendElement(el,domBuilder,parseStack);
  1368. if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
  1369. end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
  1370. }else{
  1371. end++;
  1372. }
  1373. }catch(e){
  1374. errorHandler.error('element parse error: '+e);
  1375. end = -1;
  1376. }
  1377. }
  1378. if(end<0){
  1379. appendText(i+1);
  1380. }else{
  1381. start = end;
  1382. }
  1383. }
  1384. }
  1385. function copyLocator(f,t){
  1386. t.lineNumber = f.lineNumber;
  1387. t.columnNumber = f.columnNumber;
  1388. return t;
  1389. }
  1390. function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
  1391. var attrName;
  1392. var value;
  1393. var p = ++start;
  1394. var s = S_TAG;//status
  1395. while(true){
  1396. var c = source.charAt(p);
  1397. switch(c){
  1398. case '=':
  1399. if(s === S_ATTR){//attrName
  1400. attrName = source.slice(start,p);
  1401. s = S_EQ;
  1402. }else if(s === S_ATTR_S){
  1403. s = S_EQ;
  1404. }else{
  1405. throw new Error('attribute equal must after attrName');
  1406. }
  1407. break;
  1408. case '\'':
  1409. case '"':
  1410. if(s === S_EQ){//equal
  1411. start = p+1;
  1412. p = source.indexOf(c,start)
  1413. if(p>0){
  1414. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  1415. el.add(attrName,value,start-1);
  1416. s = S_E;
  1417. }else{
  1418. throw new Error('attribute value no end \''+c+'\' match');
  1419. }
  1420. }else if(s == S_V){
  1421. value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  1422. el.add(attrName,value,start);
  1423. errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
  1424. start = p+1;
  1425. s = S_E
  1426. }else{
  1427. throw new Error('attribute value must after "="');
  1428. }
  1429. break;
  1430. case '/':
  1431. switch(s){
  1432. case S_TAG:
  1433. el.setTagName(source.slice(start,p));
  1434. case S_E:
  1435. case S_S:
  1436. case S_C:
  1437. s = S_C;
  1438. el.closed = true;
  1439. case S_V:
  1440. case S_ATTR:
  1441. case S_ATTR_S:
  1442. break;
  1443. default:
  1444. throw new Error("attribute invalid close char('/')")
  1445. }
  1446. break;
  1447. case ''://end document
  1448. errorHandler.error('unexpected end of input');
  1449. case '>':
  1450. switch(s){
  1451. case S_TAG:
  1452. el.setTagName(source.slice(start,p));
  1453. case S_E:
  1454. case S_S:
  1455. case S_C:
  1456. break;//normal
  1457. case S_V://Compatible state
  1458. case S_ATTR:
  1459. value = source.slice(start,p);
  1460. if(value.slice(-1) === '/'){
  1461. el.closed = true;
  1462. value = value.slice(0,-1)
  1463. }
  1464. case S_ATTR_S:
  1465. if(s === S_ATTR_S){
  1466. value = attrName;
  1467. }
  1468. if(s == S_V){
  1469. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  1470. el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
  1471. }else{
  1472. errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
  1473. el.add(value,value,start)
  1474. }
  1475. break;
  1476. case S_EQ:
  1477. throw new Error('attribute value missed!!');
  1478. }
  1479. return p;
  1480. case '\u0080':
  1481. c = ' ';
  1482. default:
  1483. if(c<= ' '){//space
  1484. switch(s){
  1485. case S_TAG:
  1486. el.setTagName(source.slice(start,p));//tagName
  1487. s = S_S;
  1488. break;
  1489. case S_ATTR:
  1490. attrName = source.slice(start,p)
  1491. s = S_ATTR_S;
  1492. break;
  1493. case S_V:
  1494. var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
  1495. errorHandler.warning('attribute "'+value+'" missed quot(")!!');
  1496. el.add(attrName,value,start)
  1497. case S_E:
  1498. s = S_S;
  1499. break;
  1500. }
  1501. }else{//not space
  1502. switch(s){
  1503. case S_ATTR_S:
  1504. errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead!!')
  1505. el.add(attrName,attrName,start);
  1506. start = p;
  1507. s = S_ATTR;
  1508. break;
  1509. case S_E:
  1510. errorHandler.warning('attribute space is required"'+attrName+'"!!')
  1511. case S_S:
  1512. s = S_ATTR;
  1513. start = p;
  1514. break;
  1515. case S_EQ:
  1516. s = S_V;
  1517. start = p;
  1518. break;
  1519. case S_C:
  1520. throw new Error("elements closed character '/' and '>' must be connected to");
  1521. }
  1522. }
  1523. }
  1524. p++;
  1525. }
  1526. }
  1527. function appendElement(el,domBuilder,parseStack){
  1528. var tagName = el.tagName;
  1529. var localNSMap = null;
  1530. var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
  1531. var i = el.length;
  1532. while(i--){
  1533. var a = el[i];
  1534. var qName = a.qName;
  1535. var value = a.value;
  1536. var nsp = qName.indexOf(':');
  1537. if(nsp>0){
  1538. var prefix = a.prefix = qName.slice(0,nsp);
  1539. var localName = qName.slice(nsp+1);
  1540. var nsPrefix = prefix === 'xmlns' && localName
  1541. }else{
  1542. localName = qName;
  1543. prefix = null
  1544. nsPrefix = qName === 'xmlns' && ''
  1545. }
  1546. a.localName = localName ;
  1547. if(nsPrefix !== false){//hack!!
  1548. if(localNSMap == null){
  1549. localNSMap = {}
  1550. _copy(currentNSMap,currentNSMap={})
  1551. }
  1552. currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
  1553. a.uri = 'http://www.w3.org/2000/xmlns/'
  1554. domBuilder.startPrefixMapping(nsPrefix, value)
  1555. }
  1556. }
  1557. var i = el.length;
  1558. while(i--){
  1559. a = el[i];
  1560. var prefix = a.prefix;
  1561. if(prefix){//no prefix attribute has no namespace
  1562. if(prefix === 'xml'){
  1563. a.uri = 'http://www.w3.org/XML/1998/namespace';
  1564. }if(prefix !== 'xmlns'){
  1565. a.uri = currentNSMap[prefix]
  1566. }
  1567. }
  1568. }
  1569. var nsp = tagName.indexOf(':');
  1570. if(nsp>0){
  1571. prefix = el.prefix = tagName.slice(0,nsp);
  1572. localName = el.localName = tagName.slice(nsp+1);
  1573. }else{
  1574. prefix = null;//important!!
  1575. localName = el.localName = tagName;
  1576. }
  1577. var ns = el.uri = currentNSMap[prefix || ''];
  1578. domBuilder.startElement(ns,localName,tagName,el);
  1579. if(el.closed){
  1580. domBuilder.endElement(ns,localName,tagName);
  1581. if(localNSMap){
  1582. for(prefix in localNSMap){
  1583. domBuilder.endPrefixMapping(prefix)
  1584. }
  1585. }
  1586. }else{
  1587. el.currentNSMap = currentNSMap;
  1588. el.localNSMap = localNSMap;
  1589. parseStack.push(el);
  1590. }
  1591. }
  1592. function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
  1593. if(/^(?:script|textarea)$/i.test(tagName)){
  1594. var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
  1595. var text = source.substring(elStartEnd+1,elEndStart);
  1596. if(/[&<]/.test(text)){
  1597. if(/^script$/i.test(tagName)){
  1598. domBuilder.characters(text,0,text.length);
  1599. return elEndStart;
  1600. }//}else{//text area
  1601. text = text.replace(/&#?\w+;/g,entityReplacer);
  1602. domBuilder.characters(text,0,text.length);
  1603. return elEndStart;
  1604. }
  1605. }
  1606. return elStartEnd+1;
  1607. }
  1608. function fixSelfClosed(source,elStartEnd,tagName,closeMap){
  1609. var pos = closeMap[tagName];
  1610. if(pos == null){
  1611. pos = closeMap[tagName] = source.lastIndexOf('</'+tagName+'>')
  1612. }
  1613. return pos<elStartEnd;
  1614. }
  1615. function _copy(source,target){
  1616. for(var n in source){target[n] = source[n]}
  1617. }
  1618. function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
  1619. var next= source.charAt(start+2)
  1620. switch(next){
  1621. case '-':
  1622. if(source.charAt(start + 3) === '-'){
  1623. var end = source.indexOf('-->',start+4);
  1624. if(end>start){
  1625. domBuilder.comment(source,start+4,end-start-4);
  1626. return end+3;
  1627. }else{
  1628. errorHandler.error("Unclosed comment");
  1629. return -1;
  1630. }
  1631. }else{
  1632. return -1;
  1633. }
  1634. default:
  1635. if(source.substr(start+3,6) == 'CDATA['){
  1636. var end = source.indexOf(']]>',start+9);
  1637. domBuilder.startCDATA();
  1638. domBuilder.characters(source,start+9,end-start-9);
  1639. domBuilder.endCDATA()
  1640. return end+3;
  1641. }
  1642. var matchs = split(source,start);
  1643. var len = matchs.length;
  1644. if(len>1 && /!doctype/i.test(matchs[0][0])){
  1645. var name = matchs[1][0];
  1646. var pubid = len>3 && /^public$/i.test(matchs[2][0]) && matchs[3][0]
  1647. var sysid = len>4 && matchs[4][0];
  1648. var lastMatch = matchs[len-1]
  1649. domBuilder.startDTD(name,pubid && pubid.replace(/^(['"])(.*?)\1$/,'$2'),
  1650. sysid && sysid.replace(/^(['"])(.*?)\1$/,'$2'));
  1651. domBuilder.endDTD();
  1652. return lastMatch.index+lastMatch[0].length
  1653. }
  1654. }
  1655. return -1;
  1656. }
  1657. function parseInstruction(source,start,domBuilder){
  1658. var end = source.indexOf('?>',start);
  1659. if(end){
  1660. var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
  1661. if(match){
  1662. var len = match[0].length;
  1663. domBuilder.processingInstruction(match[1], match[2]) ;
  1664. return end+2;
  1665. }else{//error
  1666. return -1;
  1667. }
  1668. }
  1669. return -1;
  1670. }
  1671. function ElementAttributes(source){
  1672. }
  1673. ElementAttributes.prototype = {
  1674. setTagName:function(tagName){
  1675. if(!tagNamePattern.test(tagName)){
  1676. throw new Error('invalid tagName:'+tagName)
  1677. }
  1678. this.tagName = tagName
  1679. },
  1680. add:function(qName,value,offset){
  1681. if(!tagNamePattern.test(qName)){
  1682. throw new Error('invalid attribute:'+qName)
  1683. }
  1684. this[this.length++] = {qName:qName,value:value,offset:offset}
  1685. },
  1686. length:0,
  1687. getLocalName:function(i){return this[i].localName},
  1688. getOffset:function(i){return this[i].offset},
  1689. getQName:function(i){return this[i].qName},
  1690. getURI:function(i){return this[i].uri},
  1691. getValue:function(i){return this[i].value}
  1692. }
  1693. function _set_proto_(thiz,parent){
  1694. thiz.__proto__ = parent;
  1695. return thiz;
  1696. }
  1697. if(!(_set_proto_({},_set_proto_.prototype) instanceof _set_proto_)){
  1698. _set_proto_ = function(thiz,parent){
  1699. function p(){};
  1700. p.prototype = parent;
  1701. p = new p();
  1702. for(parent in thiz){
  1703. p[parent] = thiz[parent];
  1704. }
  1705. return p;
  1706. }
  1707. }
  1708. function split(source,start){
  1709. var match;
  1710. var buf = [];
  1711. var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
  1712. reg.lastIndex = start;
  1713. reg.exec(source);//skip <
  1714. while(match = reg.exec(source)){
  1715. buf.push(match);
  1716. if(match[1])return buf;
  1717. }
  1718. }
  1719. return XMLReader;
  1720. });
  1721. ace.define("ace/mode/xml/dom",[], function(require, exports, module) {
  1722. function copy(src,dest){
  1723. for(var p in src){
  1724. dest[p] = src[p];
  1725. }
  1726. }
  1727. function _extends(Class,Super){
  1728. var t = function(){};
  1729. var pt = Class.prototype;
  1730. if(Object.create){
  1731. var ppt = Object.create(Super.prototype);
  1732. pt.__proto__ = ppt;
  1733. }
  1734. if(!(pt instanceof Super)){
  1735. t.prototype = Super.prototype;
  1736. t = new t();
  1737. copy(pt,t);
  1738. Class.prototype = pt = t;
  1739. }
  1740. if(pt.constructor != Class){
  1741. if(typeof Class != 'function'){
  1742. console.error("unknown Class:"+Class);
  1743. }
  1744. pt.constructor = Class;
  1745. }
  1746. }
  1747. var htmlns = 'http://www.w3.org/1999/xhtml' ;
  1748. var NodeType = {};
  1749. var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
  1750. var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
  1751. var TEXT_NODE = NodeType.TEXT_NODE = 3;
  1752. var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
  1753. var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
  1754. var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
  1755. var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
  1756. var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
  1757. var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
  1758. var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
  1759. var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
  1760. var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
  1761. var ExceptionCode = {};
  1762. var ExceptionMessage = {};
  1763. var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]="Index size error"),1);
  1764. var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]="DOMString size error"),2);
  1765. var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]="Hierarchy request error"),3);
  1766. var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]="Wrong document"),4);
  1767. var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]="Invalid character"),5);
  1768. var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]="No data allowed"),6);
  1769. var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]="No modification allowed"),7);
  1770. var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]="Not found"),8);
  1771. var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]="Not supported"),9);
  1772. var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]="Attribute in use"),10);
  1773. var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = ((ExceptionMessage[11]="Invalid state"),11);
  1774. var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = ((ExceptionMessage[12]="Syntax error"),12);
  1775. var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((ExceptionMessage[13]="Invalid modification"),13);
  1776. var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
  1777. var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
  1778. function DOMException(code, message) {
  1779. if(message instanceof Error){
  1780. var error = message;
  1781. }else{
  1782. error = this;
  1783. Error.call(this, ExceptionMessage[code]);
  1784. this.message = ExceptionMessage[code];
  1785. if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
  1786. }
  1787. error.code = code;
  1788. if(message) this.message = this.message + ": " + message;
  1789. return error;
  1790. };
  1791. DOMException.prototype = Error.prototype;
  1792. copy(ExceptionCode,DOMException)
  1793. function NodeList() {
  1794. };
  1795. NodeList.prototype = {
  1796. length:0,
  1797. item: function(index) {
  1798. return this[index] || null;
  1799. }
  1800. };
  1801. function LiveNodeList(node,refresh){
  1802. this._node = node;
  1803. this._refresh = refresh;
  1804. _updateLiveList(this);
  1805. }
  1806. function _updateLiveList(list){
  1807. var inc = list._node._inc || list._node.ownerDocument._inc;
  1808. if(list._inc != inc){
  1809. var ls = list._refresh(list._node);
  1810. __set__(list,'length',ls.length);
  1811. copy(ls,list);
  1812. list._inc = inc;
  1813. }
  1814. }
  1815. LiveNodeList.prototype.item = function(i){
  1816. _updateLiveList(this);
  1817. return this[i];
  1818. }
  1819. _extends(LiveNodeList,NodeList);
  1820. function NamedNodeMap() {
  1821. };
  1822. function _findNodeIndex(list,node){
  1823. var i = list.length;
  1824. while(i--){
  1825. if(list[i] === node){return i}
  1826. }
  1827. }
  1828. function _addNamedNode(el,list,newAttr,oldAttr){
  1829. if(oldAttr){
  1830. list[_findNodeIndex(list,oldAttr)] = newAttr;
  1831. }else{
  1832. list[list.length++] = newAttr;
  1833. }
  1834. if(el){
  1835. newAttr.ownerElement = el;
  1836. var doc = el.ownerDocument;
  1837. if(doc){
  1838. oldAttr && _onRemoveAttribute(doc,el,oldAttr);
  1839. _onAddAttribute(doc,el,newAttr);
  1840. }
  1841. }
  1842. }
  1843. function _removeNamedNode(el,list,attr){
  1844. var i = _findNodeIndex(list,attr);
  1845. if(i>=0){
  1846. var lastIndex = list.length-1;
  1847. while(i<lastIndex){
  1848. list[i] = list[++i];
  1849. }
  1850. list.length = lastIndex;
  1851. if(el){
  1852. var doc = el.ownerDocument;
  1853. if(doc){
  1854. _onRemoveAttribute(doc,el,attr);
  1855. attr.ownerElement = null;
  1856. }
  1857. }
  1858. }else{
  1859. throw new DOMException(NOT_FOUND_ERR,new Error());
  1860. }
  1861. }
  1862. NamedNodeMap.prototype = {
  1863. length:0,
  1864. item:NodeList.prototype.item,
  1865. getNamedItem: function(key) {
  1866. var i = this.length;
  1867. while(i--){
  1868. var attr = this[i];
  1869. if(attr.nodeName == key){
  1870. return attr;
  1871. }
  1872. }
  1873. },
  1874. setNamedItem: function(attr) {
  1875. var el = attr.ownerElement;
  1876. if(el && el!=this._ownerElement){
  1877. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  1878. }
  1879. var oldAttr = this.getNamedItem(attr.nodeName);
  1880. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  1881. return oldAttr;
  1882. },
  1883. setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
  1884. var el = attr.ownerElement, oldAttr;
  1885. if(el && el!=this._ownerElement){
  1886. throw new DOMException(INUSE_ATTRIBUTE_ERR);
  1887. }
  1888. oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
  1889. _addNamedNode(this._ownerElement,this,attr,oldAttr);
  1890. return oldAttr;
  1891. },
  1892. removeNamedItem: function(key) {
  1893. var attr = this.getNamedItem(key);
  1894. _removeNamedNode(this._ownerElement,this,attr);
  1895. return attr;
  1896. },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
  1897. removeNamedItemNS:function(namespaceURI,localName){
  1898. var attr = this.getNamedItemNS(namespaceURI,localName);
  1899. _removeNamedNode(this._ownerElement,this,attr);
  1900. return attr;
  1901. },
  1902. getNamedItemNS: function(namespaceURI, localName) {
  1903. var i = this.length;
  1904. while(i--){
  1905. var node = this[i];
  1906. if(node.localName == localName && node.namespaceURI == namespaceURI){
  1907. return node;
  1908. }
  1909. }
  1910. return null;
  1911. }
  1912. };
  1913. function DOMImplementation(/* Object */ features) {
  1914. this._features = {};
  1915. if (features) {
  1916. for (var feature in features) {
  1917. this._features = features[feature];
  1918. }
  1919. }
  1920. };
  1921. DOMImplementation.prototype = {
  1922. hasFeature: function(/* string */ feature, /* string */ version) {
  1923. var versions = this._features[feature.toLowerCase()];
  1924. if (versions && (!version || version in versions)) {
  1925. return true;
  1926. } else {
  1927. return false;
  1928. }
  1929. },
  1930. createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
  1931. var doc = new Document();
  1932. doc.implementation = this;
  1933. doc.childNodes = new NodeList();
  1934. doc.doctype = doctype;
  1935. if(doctype){
  1936. doc.appendChild(doctype);
  1937. }
  1938. if(qualifiedName){
  1939. var root = doc.createElementNS(namespaceURI,qualifiedName);
  1940. doc.appendChild(root);
  1941. }
  1942. return doc;
  1943. },
  1944. createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
  1945. var node = new DocumentType();
  1946. node.name = qualifiedName;
  1947. node.nodeName = qualifiedName;
  1948. node.publicId = publicId;
  1949. node.systemId = systemId;
  1950. return node;
  1951. }
  1952. };
  1953. function Node() {
  1954. };
  1955. Node.prototype = {
  1956. firstChild : null,
  1957. lastChild : null,
  1958. previousSibling : null,
  1959. nextSibling : null,
  1960. attributes : null,
  1961. parentNode : null,
  1962. childNodes : null,
  1963. ownerDocument : null,
  1964. nodeValue : null,
  1965. namespaceURI : null,
  1966. prefix : null,
  1967. localName : null,
  1968. insertBefore:function(newChild, refChild){//raises
  1969. return _insertBefore(this,newChild,refChild);
  1970. },
  1971. replaceChild:function(newChild, oldChild){//raises
  1972. this.insertBefore(newChild,oldChild);
  1973. if(oldChild){
  1974. this.removeChild(oldChild);
  1975. }
  1976. },
  1977. removeChild:function(oldChild){
  1978. return _removeChild(this,oldChild);
  1979. },
  1980. appendChild:function(newChild){
  1981. return this.insertBefore(newChild,null);
  1982. },
  1983. hasChildNodes:function(){
  1984. return this.firstChild != null;
  1985. },
  1986. cloneNode:function(deep){
  1987. return cloneNode(this.ownerDocument||this,this,deep);
  1988. },
  1989. normalize:function(){
  1990. var child = this.firstChild;
  1991. while(child){
  1992. var next = child.nextSibling;
  1993. if(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){
  1994. this.removeChild(next);
  1995. child.appendData(next.data);
  1996. }else{
  1997. child.normalize();
  1998. child = next;
  1999. }
  2000. }
  2001. },
  2002. isSupported:function(feature, version){
  2003. return this.ownerDocument.implementation.hasFeature(feature,version);
  2004. },
  2005. hasAttributes:function(){
  2006. return this.attributes.length>0;
  2007. },
  2008. lookupPrefix:function(namespaceURI){
  2009. var el = this;
  2010. while(el){
  2011. var map = el._nsMap;
  2012. if(map){
  2013. for(var n in map){
  2014. if(map[n] == namespaceURI){
  2015. return n;
  2016. }
  2017. }
  2018. }
  2019. el = el.nodeType == 2?el.ownerDocument : el.parentNode;
  2020. }
  2021. return null;
  2022. },
  2023. lookupNamespaceURI:function(prefix){
  2024. var el = this;
  2025. while(el){
  2026. var map = el._nsMap;
  2027. if(map){
  2028. if(prefix in map){
  2029. return map[prefix] ;
  2030. }
  2031. }
  2032. el = el.nodeType == 2?el.ownerDocument : el.parentNode;
  2033. }
  2034. return null;
  2035. },
  2036. isDefaultNamespace:function(namespaceURI){
  2037. var prefix = this.lookupPrefix(namespaceURI);
  2038. return prefix == null;
  2039. }
  2040. };
  2041. function _xmlEncoder(c){
  2042. return c == '<' && '&lt;' ||
  2043. c == '>' && '&gt;' ||
  2044. c == '&' && '&amp;' ||
  2045. c == '"' && '&quot;' ||
  2046. '&#'+c.charCodeAt()+';';
  2047. }
  2048. copy(NodeType,Node);
  2049. copy(NodeType,Node.prototype);
  2050. function _visitNode(node,callback){
  2051. if(callback(node)){
  2052. return true;
  2053. }
  2054. if(node = node.firstChild){
  2055. do{
  2056. if(_visitNode(node,callback)){return true}
  2057. }while(node=node.nextSibling)
  2058. }
  2059. }
  2060. function Document(){
  2061. }
  2062. function _onAddAttribute(doc,el,newAttr){
  2063. doc && doc._inc++;
  2064. var ns = newAttr.namespaceURI ;
  2065. if(ns == 'http://www.w3.org/2000/xmlns/'){
  2066. el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value
  2067. }
  2068. }
  2069. function _onRemoveAttribute(doc,el,newAttr,remove){
  2070. doc && doc._inc++;
  2071. var ns = newAttr.namespaceURI ;
  2072. if(ns == 'http://www.w3.org/2000/xmlns/'){
  2073. delete el._nsMap[newAttr.prefix?newAttr.localName:''];
  2074. }
  2075. }
  2076. function _onUpdateChild(doc,el,newChild){
  2077. if(doc && doc._inc){
  2078. doc._inc++;
  2079. var cs = el.childNodes;
  2080. if(newChild){
  2081. cs[cs.length++] = newChild;
  2082. }else{
  2083. var child = el.firstChild;
  2084. var i = 0;
  2085. while(child){
  2086. cs[i++] = child;
  2087. child =child.nextSibling;
  2088. }
  2089. cs.length = i;
  2090. }
  2091. }
  2092. }
  2093. function _removeChild(parentNode,child){
  2094. var previous = child.previousSibling;
  2095. var next = child.nextSibling;
  2096. if(previous){
  2097. previous.nextSibling = next;
  2098. }else{
  2099. parentNode.firstChild = next
  2100. }
  2101. if(next){
  2102. next.previousSibling = previous;
  2103. }else{
  2104. parentNode.lastChild = previous;
  2105. }
  2106. _onUpdateChild(parentNode.ownerDocument,parentNode);
  2107. return child;
  2108. }
  2109. function _insertBefore(parentNode,newChild,nextChild){
  2110. var cp = newChild.parentNode;
  2111. if(cp){
  2112. cp.removeChild(newChild);//remove and update
  2113. }
  2114. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  2115. var newFirst = newChild.firstChild;
  2116. if (newFirst == null) {
  2117. return newChild;
  2118. }
  2119. var newLast = newChild.lastChild;
  2120. }else{
  2121. newFirst = newLast = newChild;
  2122. }
  2123. var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
  2124. newFirst.previousSibling = pre;
  2125. newLast.nextSibling = nextChild;
  2126. if(pre){
  2127. pre.nextSibling = newFirst;
  2128. }else{
  2129. parentNode.firstChild = newFirst;
  2130. }
  2131. if(nextChild == null){
  2132. parentNode.lastChild = newLast;
  2133. }else{
  2134. nextChild.previousSibling = newLast;
  2135. }
  2136. do{
  2137. newFirst.parentNode = parentNode;
  2138. }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
  2139. _onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);
  2140. if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
  2141. newChild.firstChild = newChild.lastChild = null;
  2142. }
  2143. return newChild;
  2144. }
  2145. function _appendSingleChild(parentNode,newChild){
  2146. var cp = newChild.parentNode;
  2147. if(cp){
  2148. var pre = parentNode.lastChild;
  2149. cp.removeChild(newChild);//remove and update
  2150. var pre = parentNode.lastChild;
  2151. }
  2152. var pre = parentNode.lastChild;
  2153. newChild.parentNode = parentNode;
  2154. newChild.previousSibling = pre;
  2155. newChild.nextSibling = null;
  2156. if(pre){
  2157. pre.nextSibling = newChild;
  2158. }else{
  2159. parentNode.firstChild = newChild;
  2160. }
  2161. parentNode.lastChild = newChild;
  2162. _onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
  2163. return newChild;
  2164. }
  2165. Document.prototype = {
  2166. nodeName : '#document',
  2167. nodeType : DOCUMENT_NODE,
  2168. doctype : null,
  2169. documentElement : null,
  2170. _inc : 1,
  2171. insertBefore : function(newChild, refChild){//raises
  2172. if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
  2173. var child = newChild.firstChild;
  2174. while(child){
  2175. var next = child.nextSibling;
  2176. this.insertBefore(child,refChild);
  2177. child = next;
  2178. }
  2179. return newChild;
  2180. }
  2181. if(this.documentElement == null && newChild.nodeType == 1){
  2182. this.documentElement = newChild;
  2183. }
  2184. return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
  2185. },
  2186. removeChild : function(oldChild){
  2187. if(this.documentElement == oldChild){
  2188. this.documentElement = null;
  2189. }
  2190. return _removeChild(this,oldChild);
  2191. },
  2192. importNode : function(importedNode,deep){
  2193. return importNode(this,importedNode,deep);
  2194. },
  2195. getElementById : function(id){
  2196. var rtv = null;
  2197. _visitNode(this.documentElement,function(node){
  2198. if(node.nodeType == 1){
  2199. if(node.getAttribute('id') == id){
  2200. rtv = node;
  2201. return true;
  2202. }
  2203. }
  2204. });
  2205. return rtv;
  2206. },
  2207. createElement : function(tagName){
  2208. var node = new Element();
  2209. node.ownerDocument = this;
  2210. node.nodeName = tagName;
  2211. node.tagName = tagName;
  2212. node.childNodes = new NodeList();
  2213. var attrs = node.attributes = new NamedNodeMap();
  2214. attrs._ownerElement = node;
  2215. return node;
  2216. },
  2217. createDocumentFragment : function(){
  2218. var node = new DocumentFragment();
  2219. node.ownerDocument = this;
  2220. node.childNodes = new NodeList();
  2221. return node;
  2222. },
  2223. createTextNode : function(data){
  2224. var node = new Text();
  2225. node.ownerDocument = this;
  2226. node.appendData(data);
  2227. return node;
  2228. },
  2229. createComment : function(data){
  2230. var node = new Comment();
  2231. node.ownerDocument = this;
  2232. node.appendData(data);
  2233. return node;
  2234. },
  2235. createCDATASection : function(data){
  2236. var node = new CDATASection();
  2237. node.ownerDocument = this;
  2238. node.appendData(data);
  2239. return node;
  2240. },
  2241. createProcessingInstruction : function(target,data){
  2242. var node = new ProcessingInstruction();
  2243. node.ownerDocument = this;
  2244. node.tagName = node.target = target;
  2245. node.nodeValue= node.data = data;
  2246. return node;
  2247. },
  2248. createAttribute : function(name){
  2249. var node = new Attr();
  2250. node.ownerDocument = this;
  2251. node.name = name;
  2252. node.nodeName = name;
  2253. node.localName = name;
  2254. node.specified = true;
  2255. return node;
  2256. },
  2257. createEntityReference : function(name){
  2258. var node = new EntityReference();
  2259. node.ownerDocument = this;
  2260. node.nodeName = name;
  2261. return node;
  2262. },
  2263. createElementNS : function(namespaceURI,qualifiedName){
  2264. var node = new Element();
  2265. var pl = qualifiedName.split(':');
  2266. var attrs = node.attributes = new NamedNodeMap();
  2267. node.childNodes = new NodeList();
  2268. node.ownerDocument = this;
  2269. node.nodeName = qualifiedName;
  2270. node.tagName = qualifiedName;
  2271. node.namespaceURI = namespaceURI;
  2272. if(pl.length == 2){
  2273. node.prefix = pl[0];
  2274. node.localName = pl[1];
  2275. }else{
  2276. node.localName = qualifiedName;
  2277. }
  2278. attrs._ownerElement = node;
  2279. return node;
  2280. },
  2281. createAttributeNS : function(namespaceURI,qualifiedName){
  2282. var node = new Attr();
  2283. var pl = qualifiedName.split(':');
  2284. node.ownerDocument = this;
  2285. node.nodeName = qualifiedName;
  2286. node.name = qualifiedName;
  2287. node.namespaceURI = namespaceURI;
  2288. node.specified = true;
  2289. if(pl.length == 2){
  2290. node.prefix = pl[0];
  2291. node.localName = pl[1];
  2292. }else{
  2293. node.localName = qualifiedName;
  2294. }
  2295. return node;
  2296. }
  2297. };
  2298. _extends(Document,Node);
  2299. function Element() {
  2300. this._nsMap = {};
  2301. };
  2302. Element.prototype = {
  2303. nodeType : ELEMENT_NODE,
  2304. hasAttribute : function(name){
  2305. return this.getAttributeNode(name)!=null;
  2306. },
  2307. getAttribute : function(name){
  2308. var attr = this.getAttributeNode(name);
  2309. return attr && attr.value || '';
  2310. },
  2311. getAttributeNode : function(name){
  2312. return this.attributes.getNamedItem(name);
  2313. },
  2314. setAttribute : function(name, value){
  2315. var attr = this.ownerDocument.createAttribute(name);
  2316. attr.value = attr.nodeValue = "" + value;
  2317. this.setAttributeNode(attr);
  2318. },
  2319. removeAttribute : function(name){
  2320. var attr = this.getAttributeNode(name);
  2321. attr && this.removeAttributeNode(attr);
  2322. },
  2323. appendChild:function(newChild){
  2324. if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
  2325. return this.insertBefore(newChild,null);
  2326. }else{
  2327. return _appendSingleChild(this,newChild);
  2328. }
  2329. },
  2330. setAttributeNode : function(newAttr){
  2331. return this.attributes.setNamedItem(newAttr);
  2332. },
  2333. setAttributeNodeNS : function(newAttr){
  2334. return this.attributes.setNamedItemNS(newAttr);
  2335. },
  2336. removeAttributeNode : function(oldAttr){
  2337. return this.attributes.removeNamedItem(oldAttr.nodeName);
  2338. },
  2339. removeAttributeNS : function(namespaceURI, localName){
  2340. var old = this.getAttributeNodeNS(namespaceURI, localName);
  2341. old && this.removeAttributeNode(old);
  2342. },
  2343. hasAttributeNS : function(namespaceURI, localName){
  2344. return this.getAttributeNodeNS(namespaceURI, localName)!=null;
  2345. },
  2346. getAttributeNS : function(namespaceURI, localName){
  2347. var attr = this.getAttributeNodeNS(namespaceURI, localName);
  2348. return attr && attr.value || '';
  2349. },
  2350. setAttributeNS : function(namespaceURI, qualifiedName, value){
  2351. var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
  2352. attr.value = attr.nodeValue = "" + value;
  2353. this.setAttributeNode(attr);
  2354. },
  2355. getAttributeNodeNS : function(namespaceURI, localName){
  2356. return this.attributes.getNamedItemNS(namespaceURI, localName);
  2357. },
  2358. getElementsByTagName : function(tagName){
  2359. return new LiveNodeList(this,function(base){
  2360. var ls = [];
  2361. _visitNode(base,function(node){
  2362. if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){
  2363. ls.push(node);
  2364. }
  2365. });
  2366. return ls;
  2367. });
  2368. },
  2369. getElementsByTagNameNS : function(namespaceURI, localName){
  2370. return new LiveNodeList(this,function(base){
  2371. var ls = [];
  2372. _visitNode(base,function(node){
  2373. if(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){
  2374. ls.push(node);
  2375. }
  2376. });
  2377. return ls;
  2378. });
  2379. }
  2380. };
  2381. Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
  2382. Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
  2383. _extends(Element,Node);
  2384. function Attr() {
  2385. };
  2386. Attr.prototype.nodeType = ATTRIBUTE_NODE;
  2387. _extends(Attr,Node);
  2388. function CharacterData() {
  2389. };
  2390. CharacterData.prototype = {
  2391. data : '',
  2392. substringData : function(offset, count) {
  2393. return this.data.substring(offset, offset+count);
  2394. },
  2395. appendData: function(text) {
  2396. text = this.data+text;
  2397. this.nodeValue = this.data = text;
  2398. this.length = text.length;
  2399. },
  2400. insertData: function(offset,text) {
  2401. this.replaceData(offset,0,text);
  2402. },
  2403. appendChild:function(newChild){
  2404. throw new Error(ExceptionMessage[3]);
  2405. return Node.prototype.appendChild.apply(this,arguments);
  2406. },
  2407. deleteData: function(offset, count) {
  2408. this.replaceData(offset,count,"");
  2409. },
  2410. replaceData: function(offset, count, text) {
  2411. var start = this.data.substring(0,offset);
  2412. var end = this.data.substring(offset+count);
  2413. text = start + text + end;
  2414. this.nodeValue = this.data = text;
  2415. this.length = text.length;
  2416. }
  2417. }
  2418. _extends(CharacterData,Node);
  2419. function Text() {
  2420. };
  2421. Text.prototype = {
  2422. nodeName : "#text",
  2423. nodeType : TEXT_NODE,
  2424. splitText : function(offset) {
  2425. var text = this.data;
  2426. var newText = text.substring(offset);
  2427. text = text.substring(0, offset);
  2428. this.data = this.nodeValue = text;
  2429. this.length = text.length;
  2430. var newNode = this.ownerDocument.createTextNode(newText);
  2431. if(this.parentNode){
  2432. this.parentNode.insertBefore(newNode, this.nextSibling);
  2433. }
  2434. return newNode;
  2435. }
  2436. }
  2437. _extends(Text,CharacterData);
  2438. function Comment() {
  2439. };
  2440. Comment.prototype = {
  2441. nodeName : "#comment",
  2442. nodeType : COMMENT_NODE
  2443. }
  2444. _extends(Comment,CharacterData);
  2445. function CDATASection() {
  2446. };
  2447. CDATASection.prototype = {
  2448. nodeName : "#cdata-section",
  2449. nodeType : CDATA_SECTION_NODE
  2450. }
  2451. _extends(CDATASection,CharacterData);
  2452. function DocumentType() {
  2453. }
  2454. DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
  2455. _extends(DocumentType,Node);
  2456. function Notation() {
  2457. }
  2458. Notation.prototype.nodeType = NOTATION_NODE;
  2459. _extends(Notation,Node);
  2460. function Entity() {
  2461. }
  2462. Entity.prototype.nodeType = ENTITY_NODE;
  2463. _extends(Entity,Node);
  2464. function EntityReference() {
  2465. }
  2466. EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
  2467. _extends(EntityReference,Node);
  2468. function DocumentFragment() {
  2469. }
  2470. DocumentFragment.prototype.nodeName = "#document-fragment";
  2471. DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
  2472. _extends(DocumentFragment,Node);
  2473. function ProcessingInstruction() {
  2474. }
  2475. ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
  2476. _extends(ProcessingInstruction,Node);
  2477. function XMLSerializer(){}
  2478. XMLSerializer.prototype.serializeToString = function(node){
  2479. var buf = [];
  2480. serializeToString(node,buf);
  2481. return buf.join('');
  2482. }
  2483. Node.prototype.toString =function(){
  2484. return XMLSerializer.prototype.serializeToString(this);
  2485. }
  2486. function serializeToString(node,buf){
  2487. switch(node.nodeType){
  2488. case ELEMENT_NODE:
  2489. var attrs = node.attributes;
  2490. var len = attrs.length;
  2491. var child = node.firstChild;
  2492. var nodeName = node.tagName;
  2493. var isHTML = htmlns === node.namespaceURI;
  2494. buf.push('<',nodeName);
  2495. for(var i=0;i<len;i++){
  2496. serializeToString(attrs.item(i),buf);
  2497. }
  2498. if(child || isHTML && !/^(?:meta|link|img|br|hr|input|button)$/i.test(nodeName)){
  2499. buf.push('>');
  2500. if(isHTML && /^script$/i.test(nodeName)){
  2501. if(child){
  2502. buf.push(child.data);
  2503. }
  2504. }else{
  2505. while(child){
  2506. serializeToString(child,buf);
  2507. child = child.nextSibling;
  2508. }
  2509. }
  2510. buf.push('</',nodeName,'>');
  2511. }else{
  2512. buf.push('/>');
  2513. }
  2514. return;
  2515. case DOCUMENT_NODE:
  2516. case DOCUMENT_FRAGMENT_NODE:
  2517. var child = node.firstChild;
  2518. while(child){
  2519. serializeToString(child,buf);
  2520. child = child.nextSibling;
  2521. }
  2522. return;
  2523. case ATTRIBUTE_NODE:
  2524. return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
  2525. case TEXT_NODE:
  2526. return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
  2527. case CDATA_SECTION_NODE:
  2528. return buf.push( '<![CDATA[',node.data,']]>');
  2529. case COMMENT_NODE:
  2530. return buf.push( "<!--",node.data,"-->");
  2531. case DOCUMENT_TYPE_NODE:
  2532. var pubid = node.publicId;
  2533. var sysid = node.systemId;
  2534. buf.push('<!DOCTYPE ',node.name);
  2535. if(pubid){
  2536. buf.push(' PUBLIC "',pubid);
  2537. if (sysid && sysid!='.') {
  2538. buf.push( '" "',sysid);
  2539. }
  2540. buf.push('">');
  2541. }else if(sysid && sysid!='.'){
  2542. buf.push(' SYSTEM "',sysid,'">');
  2543. }else{
  2544. var sub = node.internalSubset;
  2545. if(sub){
  2546. buf.push(" [",sub,"]");
  2547. }
  2548. buf.push(">");
  2549. }
  2550. return;
  2551. case PROCESSING_INSTRUCTION_NODE:
  2552. return buf.push( "<?",node.target," ",node.data,"?>");
  2553. case ENTITY_REFERENCE_NODE:
  2554. return buf.push( '&',node.nodeName,';');
  2555. default:
  2556. buf.push('??',node.nodeName);
  2557. }
  2558. }
  2559. function importNode(doc,node,deep){
  2560. var node2;
  2561. switch (node.nodeType) {
  2562. case ELEMENT_NODE:
  2563. node2 = node.cloneNode(false);
  2564. node2.ownerDocument = doc;
  2565. case DOCUMENT_FRAGMENT_NODE:
  2566. break;
  2567. case ATTRIBUTE_NODE:
  2568. deep = true;
  2569. break;
  2570. }
  2571. if(!node2){
  2572. node2 = node.cloneNode(false);//false
  2573. }
  2574. node2.ownerDocument = doc;
  2575. node2.parentNode = null;
  2576. if(deep){
  2577. var child = node.firstChild;
  2578. while(child){
  2579. node2.appendChild(importNode(doc,child,deep));
  2580. child = child.nextSibling;
  2581. }
  2582. }
  2583. return node2;
  2584. }
  2585. function cloneNode(doc,node,deep){
  2586. var node2 = new node.constructor();
  2587. for(var n in node){
  2588. var v = node[n];
  2589. if(typeof v != 'object' ){
  2590. if(v != node2[n]){
  2591. node2[n] = v;
  2592. }
  2593. }
  2594. }
  2595. if(node.childNodes){
  2596. node2.childNodes = new NodeList();
  2597. }
  2598. node2.ownerDocument = doc;
  2599. switch (node2.nodeType) {
  2600. case ELEMENT_NODE:
  2601. var attrs = node.attributes;
  2602. var attrs2 = node2.attributes = new NamedNodeMap();
  2603. var len = attrs.length;
  2604. attrs2._ownerElement = node2;
  2605. for(var i=0;i<len;i++){
  2606. node2.setAttributeNode(cloneNode(doc,attrs.item(i),true));
  2607. }
  2608. break;
  2609. case ATTRIBUTE_NODE:
  2610. deep = true;
  2611. }
  2612. if(deep){
  2613. var child = node.firstChild;
  2614. while(child){
  2615. node2.appendChild(cloneNode(doc,child,deep));
  2616. child = child.nextSibling;
  2617. }
  2618. }
  2619. return node2;
  2620. }
  2621. function __set__(object,key,value){
  2622. object[key] = value;
  2623. }
  2624. function getTextContent(node){
  2625. switch(node.nodeType){
  2626. case 1:
  2627. case 11:
  2628. var buf = [];
  2629. node = node.firstChild;
  2630. while(node){
  2631. if(node.nodeType!==7 && node.nodeType !==8){
  2632. buf.push(getTextContent(node));
  2633. }
  2634. node = node.nextSibling;
  2635. }
  2636. return buf.join('');
  2637. default:
  2638. return node.nodeValue;
  2639. }
  2640. }
  2641. try{
  2642. if(Object.defineProperty){
  2643. Object.defineProperty(LiveNodeList.prototype,'length',{
  2644. get:function(){
  2645. _updateLiveList(this);
  2646. return this.$$length;
  2647. }
  2648. });
  2649. Object.defineProperty(Node.prototype,'textContent',{
  2650. get:function(){
  2651. return getTextContent(this);
  2652. },
  2653. set:function(data){
  2654. switch(this.nodeType){
  2655. case 1:
  2656. case 11:
  2657. while(this.firstChild){
  2658. this.removeChild(this.firstChild);
  2659. }
  2660. if(data || String(data)){
  2661. this.appendChild(this.ownerDocument.createTextNode(data));
  2662. }
  2663. break;
  2664. default:
  2665. this.data = data;
  2666. this.value = value;
  2667. this.nodeValue = data;
  2668. }
  2669. }
  2670. });
  2671. __set__ = function(object,key,value){
  2672. object['$$'+key] = value;
  2673. };
  2674. }
  2675. }catch(e){//ie8
  2676. }
  2677. return DOMImplementation;
  2678. });
  2679. ace.define("ace/mode/xml/dom-parser",[], function(require, exports, module) {
  2680. 'use strict';
  2681. var XMLReader = require('./sax'),
  2682. DOMImplementation = require('./dom');
  2683. function DOMParser(options){
  2684. this.options = options ||{locator:{}};
  2685. }
  2686. DOMParser.prototype.parseFromString = function(source,mimeType){
  2687. var options = this.options;
  2688. var sax = new XMLReader();
  2689. var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
  2690. var errorHandler = options.errorHandler;
  2691. var locator = options.locator;
  2692. var defaultNSMap = options.xmlns||{};
  2693. var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
  2694. if(locator){
  2695. domBuilder.setDocumentLocator(locator)
  2696. }
  2697. sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
  2698. sax.domBuilder = options.domBuilder || domBuilder;
  2699. if(/\/x?html?$/.test(mimeType)){
  2700. entityMap.nbsp = '\xa0';
  2701. entityMap.copy = '\xa9';
  2702. defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
  2703. }
  2704. if(source){
  2705. sax.parse(source,defaultNSMap,entityMap);
  2706. }else{
  2707. sax.errorHandler.error("invalid document source");
  2708. }
  2709. return domBuilder.document;
  2710. }
  2711. function buildErrorHandler(errorImpl,domBuilder,locator){
  2712. if(!errorImpl){
  2713. if(domBuilder instanceof DOMHandler){
  2714. return domBuilder;
  2715. }
  2716. errorImpl = domBuilder ;
  2717. }
  2718. var errorHandler = {}
  2719. var isCallback = errorImpl instanceof Function;
  2720. locator = locator||{}
  2721. function build(key){
  2722. var fn = errorImpl[key];
  2723. if(!fn){
  2724. if(isCallback){
  2725. fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
  2726. }else{
  2727. var i=arguments.length;
  2728. while(--i){
  2729. if(fn = errorImpl[arguments[i]]){
  2730. break;
  2731. }
  2732. }
  2733. }
  2734. }
  2735. errorHandler[key] = fn && function(msg){
  2736. fn(msg+_locator(locator), msg, locator);
  2737. }||function(){};
  2738. }
  2739. build('warning','warn');
  2740. build('error','warn','warning');
  2741. build('fatalError','warn','warning','error');
  2742. return errorHandler;
  2743. }
  2744. function DOMHandler() {
  2745. this.cdata = false;
  2746. }
  2747. function position(locator,node){
  2748. node.lineNumber = locator.lineNumber;
  2749. node.columnNumber = locator.columnNumber;
  2750. }
  2751. DOMHandler.prototype = {
  2752. startDocument : function() {
  2753. this.document = new DOMImplementation().createDocument(null, null, null);
  2754. if (this.locator) {
  2755. this.document.documentURI = this.locator.systemId;
  2756. }
  2757. },
  2758. startElement:function(namespaceURI, localName, qName, attrs) {
  2759. var doc = this.document;
  2760. var el = doc.createElementNS(namespaceURI, qName||localName);
  2761. var len = attrs.length;
  2762. appendElement(this, el);
  2763. this.currentElement = el;
  2764. this.locator && position(this.locator,el)
  2765. for (var i = 0 ; i < len; i++) {
  2766. var namespaceURI = attrs.getURI(i);
  2767. var value = attrs.getValue(i);
  2768. var qName = attrs.getQName(i);
  2769. var attr = doc.createAttributeNS(namespaceURI, qName);
  2770. if( attr.getOffset){
  2771. position(attr.getOffset(1),attr)
  2772. }
  2773. attr.value = attr.nodeValue = value;
  2774. el.setAttributeNode(attr)
  2775. }
  2776. },
  2777. endElement:function(namespaceURI, localName, qName) {
  2778. var current = this.currentElement
  2779. var tagName = current.tagName;
  2780. this.currentElement = current.parentNode;
  2781. },
  2782. startPrefixMapping:function(prefix, uri) {
  2783. },
  2784. endPrefixMapping:function(prefix) {
  2785. },
  2786. processingInstruction:function(target, data) {
  2787. var ins = this.document.createProcessingInstruction(target, data);
  2788. this.locator && position(this.locator,ins)
  2789. appendElement(this, ins);
  2790. },
  2791. ignorableWhitespace:function(ch, start, length) {
  2792. },
  2793. characters:function(chars, start, length) {
  2794. chars = _toString.apply(this,arguments)
  2795. if(this.currentElement && chars){
  2796. if (this.cdata) {
  2797. var charNode = this.document.createCDATASection(chars);
  2798. this.currentElement.appendChild(charNode);
  2799. } else {
  2800. var charNode = this.document.createTextNode(chars);
  2801. this.currentElement.appendChild(charNode);
  2802. }
  2803. this.locator && position(this.locator,charNode)
  2804. }
  2805. },
  2806. skippedEntity:function(name) {
  2807. },
  2808. endDocument:function() {
  2809. this.document.normalize();
  2810. },
  2811. setDocumentLocator:function (locator) {
  2812. if(this.locator = locator){// && !('lineNumber' in locator)){
  2813. locator.lineNumber = 0;
  2814. }
  2815. },
  2816. comment:function(chars, start, length) {
  2817. chars = _toString.apply(this,arguments)
  2818. var comm = this.document.createComment(chars);
  2819. this.locator && position(this.locator,comm)
  2820. appendElement(this, comm);
  2821. },
  2822. startCDATA:function() {
  2823. this.cdata = true;
  2824. },
  2825. endCDATA:function() {
  2826. this.cdata = false;
  2827. },
  2828. startDTD:function(name, publicId, systemId) {
  2829. var impl = this.document.implementation;
  2830. if (impl && impl.createDocumentType) {
  2831. var dt = impl.createDocumentType(name, publicId, systemId);
  2832. this.locator && position(this.locator,dt)
  2833. appendElement(this, dt);
  2834. }
  2835. },
  2836. warning:function(error) {
  2837. console.warn(error,_locator(this.locator));
  2838. },
  2839. error:function(error) {
  2840. console.error(error,_locator(this.locator));
  2841. },
  2842. fatalError:function(error) {
  2843. console.error(error,_locator(this.locator));
  2844. throw error;
  2845. }
  2846. }
  2847. function _locator(l){
  2848. if(l){
  2849. return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
  2850. }
  2851. }
  2852. function _toString(chars,start,length){
  2853. if(typeof chars == 'string'){
  2854. return chars.substr(start,length)
  2855. }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
  2856. if(chars.length >= start+length || start){
  2857. return new java.lang.String(chars,start,length)+'';
  2858. }
  2859. return chars;
  2860. }
  2861. }
  2862. "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
  2863. DOMHandler.prototype[key] = function(){return null}
  2864. })
  2865. function appendElement (hander,node) {
  2866. if (!hander.currentElement) {
  2867. hander.document.appendChild(node);
  2868. } else {
  2869. hander.currentElement.appendChild(node);
  2870. }
  2871. }//appendChild and setAttributeNS are preformance key
  2872. return {
  2873. DOMParser: DOMParser
  2874. };
  2875. });
  2876. ace.define("ace/mode/xml_worker",[], function(require, exports, module) {
  2877. "use strict";
  2878. var oop = require("../lib/oop");
  2879. var lang = require("../lib/lang");
  2880. var Mirror = require("../worker/mirror").Mirror;
  2881. var DOMParser = require("./xml/dom-parser").DOMParser;
  2882. var Worker = exports.Worker = function(sender) {
  2883. Mirror.call(this, sender);
  2884. this.setTimeout(400);
  2885. this.context = null;
  2886. };
  2887. oop.inherits(Worker, Mirror);
  2888. (function() {
  2889. this.setOptions = function(options) {
  2890. this.context = options.context;
  2891. };
  2892. this.onUpdate = function() {
  2893. var value = this.doc.getValue();
  2894. if (!value)
  2895. return;
  2896. var parser = new DOMParser();
  2897. var errors = [];
  2898. parser.options.errorHandler = {
  2899. fatalError: function(fullMsg, errorMsg, locator) {
  2900. errors.push({
  2901. row: locator.lineNumber,
  2902. column: locator.columnNumber,
  2903. text: errorMsg,
  2904. type: "error"
  2905. });
  2906. },
  2907. error: function(fullMsg, errorMsg, locator) {
  2908. errors.push({
  2909. row: locator.lineNumber,
  2910. column: locator.columnNumber,
  2911. text: errorMsg,
  2912. type: "error"
  2913. });
  2914. },
  2915. warning: function(fullMsg, errorMsg, locator) {
  2916. errors.push({
  2917. row: locator.lineNumber,
  2918. column: locator.columnNumber,
  2919. text: errorMsg,
  2920. type: "warning"
  2921. });
  2922. }
  2923. };
  2924. parser.parseFromString(value);
  2925. this.sender.emit("error", errors);
  2926. };
  2927. }).call(Worker.prototype);
  2928. });
  2929. ace.define("ace/lib/es5-shim",[], function(require, exports, module) {
  2930. function Empty() {}
  2931. if (!Function.prototype.bind) {
  2932. Function.prototype.bind = function bind(that) { // .length is 1
  2933. var target = this;
  2934. if (typeof target != "function") {
  2935. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  2936. }
  2937. var args = slice.call(arguments, 1); // for normal call
  2938. var bound = function () {
  2939. if (this instanceof bound) {
  2940. var result = target.apply(
  2941. this,
  2942. args.concat(slice.call(arguments))
  2943. );
  2944. if (Object(result) === result) {
  2945. return result;
  2946. }
  2947. return this;
  2948. } else {
  2949. return target.apply(
  2950. that,
  2951. args.concat(slice.call(arguments))
  2952. );
  2953. }
  2954. };
  2955. if(target.prototype) {
  2956. Empty.prototype = target.prototype;
  2957. bound.prototype = new Empty();
  2958. Empty.prototype = null;
  2959. }
  2960. return bound;
  2961. };
  2962. }
  2963. var call = Function.prototype.call;
  2964. var prototypeOfArray = Array.prototype;
  2965. var prototypeOfObject = Object.prototype;
  2966. var slice = prototypeOfArray.slice;
  2967. var _toString = call.bind(prototypeOfObject.toString);
  2968. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  2969. var defineGetter;
  2970. var defineSetter;
  2971. var lookupGetter;
  2972. var lookupSetter;
  2973. var supportsAccessors;
  2974. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  2975. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  2976. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  2977. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  2978. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  2979. }
  2980. if ([1,2].splice(0).length != 2) {
  2981. if(function() { // test IE < 9 to splice bug - see issue #138
  2982. function makeArray(l) {
  2983. var a = new Array(l+2);
  2984. a[0] = a[1] = 0;
  2985. return a;
  2986. }
  2987. var array = [], lengthBefore;
  2988. array.splice.apply(array, makeArray(20));
  2989. array.splice.apply(array, makeArray(26));
  2990. lengthBefore = array.length; //46
  2991. array.splice(5, 0, "XXX"); // add one element
  2992. lengthBefore + 1 == array.length
  2993. if (lengthBefore + 1 == array.length) {
  2994. return true;// has right splice implementation without bugs
  2995. }
  2996. }()) {//IE 6/7
  2997. var array_splice = Array.prototype.splice;
  2998. Array.prototype.splice = function(start, deleteCount) {
  2999. if (!arguments.length) {
  3000. return [];
  3001. } else {
  3002. return array_splice.apply(this, [
  3003. start === void 0 ? 0 : start,
  3004. deleteCount === void 0 ? (this.length - start) : deleteCount
  3005. ].concat(slice.call(arguments, 2)))
  3006. }
  3007. };
  3008. } else {//IE8
  3009. Array.prototype.splice = function(pos, removeCount){
  3010. var length = this.length;
  3011. if (pos > 0) {
  3012. if (pos > length)
  3013. pos = length;
  3014. } else if (pos == void 0) {
  3015. pos = 0;
  3016. } else if (pos < 0) {
  3017. pos = Math.max(length + pos, 0);
  3018. }
  3019. if (!(pos+removeCount < length))
  3020. removeCount = length - pos;
  3021. var removed = this.slice(pos, pos+removeCount);
  3022. var insert = slice.call(arguments, 2);
  3023. var add = insert.length;
  3024. if (pos === length) {
  3025. if (add) {
  3026. this.push.apply(this, insert);
  3027. }
  3028. } else {
  3029. var remove = Math.min(removeCount, length - pos);
  3030. var tailOldPos = pos + remove;
  3031. var tailNewPos = tailOldPos + add - remove;
  3032. var tailCount = length - tailOldPos;
  3033. var lengthAfterRemove = length - remove;
  3034. if (tailNewPos < tailOldPos) { // case A
  3035. for (var i = 0; i < tailCount; ++i) {
  3036. this[tailNewPos+i] = this[tailOldPos+i];
  3037. }
  3038. } else if (tailNewPos > tailOldPos) { // case B
  3039. for (i = tailCount; i--; ) {
  3040. this[tailNewPos+i] = this[tailOldPos+i];
  3041. }
  3042. } // else, add == remove (nothing to do)
  3043. if (add && pos === lengthAfterRemove) {
  3044. this.length = lengthAfterRemove; // truncate array
  3045. this.push.apply(this, insert);
  3046. } else {
  3047. this.length = lengthAfterRemove + add; // reserves space
  3048. for (i = 0; i < add; ++i) {
  3049. this[pos+i] = insert[i];
  3050. }
  3051. }
  3052. }
  3053. return removed;
  3054. };
  3055. }
  3056. }
  3057. if (!Array.isArray) {
  3058. Array.isArray = function isArray(obj) {
  3059. return _toString(obj) == "[object Array]";
  3060. };
  3061. }
  3062. var boxedString = Object("a"),
  3063. splitString = boxedString[0] != "a" || !(0 in boxedString);
  3064. if (!Array.prototype.forEach) {
  3065. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  3066. var object = toObject(this),
  3067. self = splitString && _toString(this) == "[object String]" ?
  3068. this.split("") :
  3069. object,
  3070. thisp = arguments[1],
  3071. i = -1,
  3072. length = self.length >>> 0;
  3073. if (_toString(fun) != "[object Function]") {
  3074. throw new TypeError(); // TODO message
  3075. }
  3076. while (++i < length) {
  3077. if (i in self) {
  3078. fun.call(thisp, self[i], i, object);
  3079. }
  3080. }
  3081. };
  3082. }
  3083. if (!Array.prototype.map) {
  3084. Array.prototype.map = function map(fun /*, thisp*/) {
  3085. var object = toObject(this),
  3086. self = splitString && _toString(this) == "[object String]" ?
  3087. this.split("") :
  3088. object,
  3089. length = self.length >>> 0,
  3090. result = Array(length),
  3091. thisp = arguments[1];
  3092. if (_toString(fun) != "[object Function]") {
  3093. throw new TypeError(fun + " is not a function");
  3094. }
  3095. for (var i = 0; i < length; i++) {
  3096. if (i in self)
  3097. result[i] = fun.call(thisp, self[i], i, object);
  3098. }
  3099. return result;
  3100. };
  3101. }
  3102. if (!Array.prototype.filter) {
  3103. Array.prototype.filter = function filter(fun /*, thisp */) {
  3104. var object = toObject(this),
  3105. self = splitString && _toString(this) == "[object String]" ?
  3106. this.split("") :
  3107. object,
  3108. length = self.length >>> 0,
  3109. result = [],
  3110. value,
  3111. thisp = arguments[1];
  3112. if (_toString(fun) != "[object Function]") {
  3113. throw new TypeError(fun + " is not a function");
  3114. }
  3115. for (var i = 0; i < length; i++) {
  3116. if (i in self) {
  3117. value = self[i];
  3118. if (fun.call(thisp, value, i, object)) {
  3119. result.push(value);
  3120. }
  3121. }
  3122. }
  3123. return result;
  3124. };
  3125. }
  3126. if (!Array.prototype.every) {
  3127. Array.prototype.every = function every(fun /*, thisp */) {
  3128. var object = toObject(this),
  3129. self = splitString && _toString(this) == "[object String]" ?
  3130. this.split("") :
  3131. object,
  3132. length = self.length >>> 0,
  3133. thisp = arguments[1];
  3134. if (_toString(fun) != "[object Function]") {
  3135. throw new TypeError(fun + " is not a function");
  3136. }
  3137. for (var i = 0; i < length; i++) {
  3138. if (i in self && !fun.call(thisp, self[i], i, object)) {
  3139. return false;
  3140. }
  3141. }
  3142. return true;
  3143. };
  3144. }
  3145. if (!Array.prototype.some) {
  3146. Array.prototype.some = function some(fun /*, thisp */) {
  3147. var object = toObject(this),
  3148. self = splitString && _toString(this) == "[object String]" ?
  3149. this.split("") :
  3150. object,
  3151. length = self.length >>> 0,
  3152. thisp = arguments[1];
  3153. if (_toString(fun) != "[object Function]") {
  3154. throw new TypeError(fun + " is not a function");
  3155. }
  3156. for (var i = 0; i < length; i++) {
  3157. if (i in self && fun.call(thisp, self[i], i, object)) {
  3158. return true;
  3159. }
  3160. }
  3161. return false;
  3162. };
  3163. }
  3164. if (!Array.prototype.reduce) {
  3165. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  3166. var object = toObject(this),
  3167. self = splitString && _toString(this) == "[object String]" ?
  3168. this.split("") :
  3169. object,
  3170. length = self.length >>> 0;
  3171. if (_toString(fun) != "[object Function]") {
  3172. throw new TypeError(fun + " is not a function");
  3173. }
  3174. if (!length && arguments.length == 1) {
  3175. throw new TypeError("reduce of empty array with no initial value");
  3176. }
  3177. var i = 0;
  3178. var result;
  3179. if (arguments.length >= 2) {
  3180. result = arguments[1];
  3181. } else {
  3182. do {
  3183. if (i in self) {
  3184. result = self[i++];
  3185. break;
  3186. }
  3187. if (++i >= length) {
  3188. throw new TypeError("reduce of empty array with no initial value");
  3189. }
  3190. } while (true);
  3191. }
  3192. for (; i < length; i++) {
  3193. if (i in self) {
  3194. result = fun.call(void 0, result, self[i], i, object);
  3195. }
  3196. }
  3197. return result;
  3198. };
  3199. }
  3200. if (!Array.prototype.reduceRight) {
  3201. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  3202. var object = toObject(this),
  3203. self = splitString && _toString(this) == "[object String]" ?
  3204. this.split("") :
  3205. object,
  3206. length = self.length >>> 0;
  3207. if (_toString(fun) != "[object Function]") {
  3208. throw new TypeError(fun + " is not a function");
  3209. }
  3210. if (!length && arguments.length == 1) {
  3211. throw new TypeError("reduceRight of empty array with no initial value");
  3212. }
  3213. var result, i = length - 1;
  3214. if (arguments.length >= 2) {
  3215. result = arguments[1];
  3216. } else {
  3217. do {
  3218. if (i in self) {
  3219. result = self[i--];
  3220. break;
  3221. }
  3222. if (--i < 0) {
  3223. throw new TypeError("reduceRight of empty array with no initial value");
  3224. }
  3225. } while (true);
  3226. }
  3227. do {
  3228. if (i in this) {
  3229. result = fun.call(void 0, result, self[i], i, object);
  3230. }
  3231. } while (i--);
  3232. return result;
  3233. };
  3234. }
  3235. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  3236. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  3237. var self = splitString && _toString(this) == "[object String]" ?
  3238. this.split("") :
  3239. toObject(this),
  3240. length = self.length >>> 0;
  3241. if (!length) {
  3242. return -1;
  3243. }
  3244. var i = 0;
  3245. if (arguments.length > 1) {
  3246. i = toInteger(arguments[1]);
  3247. }
  3248. i = i >= 0 ? i : Math.max(0, length + i);
  3249. for (; i < length; i++) {
  3250. if (i in self && self[i] === sought) {
  3251. return i;
  3252. }
  3253. }
  3254. return -1;
  3255. };
  3256. }
  3257. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  3258. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  3259. var self = splitString && _toString(this) == "[object String]" ?
  3260. this.split("") :
  3261. toObject(this),
  3262. length = self.length >>> 0;
  3263. if (!length) {
  3264. return -1;
  3265. }
  3266. var i = length - 1;
  3267. if (arguments.length > 1) {
  3268. i = Math.min(i, toInteger(arguments[1]));
  3269. }
  3270. i = i >= 0 ? i : length - Math.abs(i);
  3271. for (; i >= 0; i--) {
  3272. if (i in self && sought === self[i]) {
  3273. return i;
  3274. }
  3275. }
  3276. return -1;
  3277. };
  3278. }
  3279. if (!Object.getPrototypeOf) {
  3280. Object.getPrototypeOf = function getPrototypeOf(object) {
  3281. return object.__proto__ || (
  3282. object.constructor ?
  3283. object.constructor.prototype :
  3284. prototypeOfObject
  3285. );
  3286. };
  3287. }
  3288. if (!Object.getOwnPropertyDescriptor) {
  3289. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  3290. "non-object: ";
  3291. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  3292. if ((typeof object != "object" && typeof object != "function") || object === null)
  3293. throw new TypeError(ERR_NON_OBJECT + object);
  3294. if (!owns(object, property))
  3295. return;
  3296. var descriptor, getter, setter;
  3297. descriptor = { enumerable: true, configurable: true };
  3298. if (supportsAccessors) {
  3299. var prototype = object.__proto__;
  3300. object.__proto__ = prototypeOfObject;
  3301. var getter = lookupGetter(object, property);
  3302. var setter = lookupSetter(object, property);
  3303. object.__proto__ = prototype;
  3304. if (getter || setter) {
  3305. if (getter) descriptor.get = getter;
  3306. if (setter) descriptor.set = setter;
  3307. return descriptor;
  3308. }
  3309. }
  3310. descriptor.value = object[property];
  3311. return descriptor;
  3312. };
  3313. }
  3314. if (!Object.getOwnPropertyNames) {
  3315. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  3316. return Object.keys(object);
  3317. };
  3318. }
  3319. if (!Object.create) {
  3320. var createEmpty;
  3321. if (Object.prototype.__proto__ === null) {
  3322. createEmpty = function () {
  3323. return { "__proto__": null };
  3324. };
  3325. } else {
  3326. createEmpty = function () {
  3327. var empty = {};
  3328. for (var i in empty)
  3329. empty[i] = null;
  3330. empty.constructor =
  3331. empty.hasOwnProperty =
  3332. empty.propertyIsEnumerable =
  3333. empty.isPrototypeOf =
  3334. empty.toLocaleString =
  3335. empty.toString =
  3336. empty.valueOf =
  3337. empty.__proto__ = null;
  3338. return empty;
  3339. }
  3340. }
  3341. Object.create = function create(prototype, properties) {
  3342. var object;
  3343. if (prototype === null) {
  3344. object = createEmpty();
  3345. } else {
  3346. if (typeof prototype != "object")
  3347. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  3348. var Type = function () {};
  3349. Type.prototype = prototype;
  3350. object = new Type();
  3351. object.__proto__ = prototype;
  3352. }
  3353. if (properties !== void 0)
  3354. Object.defineProperties(object, properties);
  3355. return object;
  3356. };
  3357. }
  3358. function doesDefinePropertyWork(object) {
  3359. try {
  3360. Object.defineProperty(object, "sentinel", {});
  3361. return "sentinel" in object;
  3362. } catch (exception) {
  3363. }
  3364. }
  3365. if (Object.defineProperty) {
  3366. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  3367. var definePropertyWorksOnDom = typeof document == "undefined" ||
  3368. doesDefinePropertyWork(document.createElement("div"));
  3369. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  3370. var definePropertyFallback = Object.defineProperty;
  3371. }
  3372. }
  3373. if (!Object.defineProperty || definePropertyFallback) {
  3374. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  3375. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  3376. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  3377. "on this javascript engine";
  3378. Object.defineProperty = function defineProperty(object, property, descriptor) {
  3379. if ((typeof object != "object" && typeof object != "function") || object === null)
  3380. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  3381. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  3382. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  3383. if (definePropertyFallback) {
  3384. try {
  3385. return definePropertyFallback.call(Object, object, property, descriptor);
  3386. } catch (exception) {
  3387. }
  3388. }
  3389. if (owns(descriptor, "value")) {
  3390. if (supportsAccessors && (lookupGetter(object, property) ||
  3391. lookupSetter(object, property)))
  3392. {
  3393. var prototype = object.__proto__;
  3394. object.__proto__ = prototypeOfObject;
  3395. delete object[property];
  3396. object[property] = descriptor.value;
  3397. object.__proto__ = prototype;
  3398. } else {
  3399. object[property] = descriptor.value;
  3400. }
  3401. } else {
  3402. if (!supportsAccessors)
  3403. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  3404. if (owns(descriptor, "get"))
  3405. defineGetter(object, property, descriptor.get);
  3406. if (owns(descriptor, "set"))
  3407. defineSetter(object, property, descriptor.set);
  3408. }
  3409. return object;
  3410. };
  3411. }
  3412. if (!Object.defineProperties) {
  3413. Object.defineProperties = function defineProperties(object, properties) {
  3414. for (var property in properties) {
  3415. if (owns(properties, property))
  3416. Object.defineProperty(object, property, properties[property]);
  3417. }
  3418. return object;
  3419. };
  3420. }
  3421. if (!Object.seal) {
  3422. Object.seal = function seal(object) {
  3423. return object;
  3424. };
  3425. }
  3426. if (!Object.freeze) {
  3427. Object.freeze = function freeze(object) {
  3428. return object;
  3429. };
  3430. }
  3431. try {
  3432. Object.freeze(function () {});
  3433. } catch (exception) {
  3434. Object.freeze = (function freeze(freezeObject) {
  3435. return function freeze(object) {
  3436. if (typeof object == "function") {
  3437. return object;
  3438. } else {
  3439. return freezeObject(object);
  3440. }
  3441. };
  3442. })(Object.freeze);
  3443. }
  3444. if (!Object.preventExtensions) {
  3445. Object.preventExtensions = function preventExtensions(object) {
  3446. return object;
  3447. };
  3448. }
  3449. if (!Object.isSealed) {
  3450. Object.isSealed = function isSealed(object) {
  3451. return false;
  3452. };
  3453. }
  3454. if (!Object.isFrozen) {
  3455. Object.isFrozen = function isFrozen(object) {
  3456. return false;
  3457. };
  3458. }
  3459. if (!Object.isExtensible) {
  3460. Object.isExtensible = function isExtensible(object) {
  3461. if (Object(object) === object) {
  3462. throw new TypeError(); // TODO message
  3463. }
  3464. var name = '';
  3465. while (owns(object, name)) {
  3466. name += '?';
  3467. }
  3468. object[name] = true;
  3469. var returnValue = owns(object, name);
  3470. delete object[name];
  3471. return returnValue;
  3472. };
  3473. }
  3474. if (!Object.keys) {
  3475. var hasDontEnumBug = true,
  3476. dontEnums = [
  3477. "toString",
  3478. "toLocaleString",
  3479. "valueOf",
  3480. "hasOwnProperty",
  3481. "isPrototypeOf",
  3482. "propertyIsEnumerable",
  3483. "constructor"
  3484. ],
  3485. dontEnumsLength = dontEnums.length;
  3486. for (var key in {"toString": null}) {
  3487. hasDontEnumBug = false;
  3488. }
  3489. Object.keys = function keys(object) {
  3490. if (
  3491. (typeof object != "object" && typeof object != "function") ||
  3492. object === null
  3493. ) {
  3494. throw new TypeError("Object.keys called on a non-object");
  3495. }
  3496. var keys = [];
  3497. for (var name in object) {
  3498. if (owns(object, name)) {
  3499. keys.push(name);
  3500. }
  3501. }
  3502. if (hasDontEnumBug) {
  3503. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  3504. var dontEnum = dontEnums[i];
  3505. if (owns(object, dontEnum)) {
  3506. keys.push(dontEnum);
  3507. }
  3508. }
  3509. }
  3510. return keys;
  3511. };
  3512. }
  3513. if (!Date.now) {
  3514. Date.now = function now() {
  3515. return new Date().getTime();
  3516. };
  3517. }
  3518. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  3519. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  3520. "\u2029\uFEFF";
  3521. if (!String.prototype.trim || ws.trim()) {
  3522. ws = "[" + ws + "]";
  3523. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  3524. trimEndRegexp = new RegExp(ws + ws + "*$");
  3525. String.prototype.trim = function trim() {
  3526. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  3527. };
  3528. }
  3529. function toInteger(n) {
  3530. n = +n;
  3531. if (n !== n) { // isNaN
  3532. n = 0;
  3533. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  3534. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  3535. }
  3536. return n;
  3537. }
  3538. function isPrimitive(input) {
  3539. var type = typeof input;
  3540. return (
  3541. input === null ||
  3542. type === "undefined" ||
  3543. type === "boolean" ||
  3544. type === "number" ||
  3545. type === "string"
  3546. );
  3547. }
  3548. function toPrimitive(input) {
  3549. var val, valueOf, toString;
  3550. if (isPrimitive(input)) {
  3551. return input;
  3552. }
  3553. valueOf = input.valueOf;
  3554. if (typeof valueOf === "function") {
  3555. val = valueOf.call(input);
  3556. if (isPrimitive(val)) {
  3557. return val;
  3558. }
  3559. }
  3560. toString = input.toString;
  3561. if (typeof toString === "function") {
  3562. val = toString.call(input);
  3563. if (isPrimitive(val)) {
  3564. return val;
  3565. }
  3566. }
  3567. throw new TypeError();
  3568. }
  3569. var toObject = function (o) {
  3570. if (o == null) { // this matches both null and undefined
  3571. throw new TypeError("can't convert "+o+" to object");
  3572. }
  3573. return Object(o);
  3574. };
  3575. });