worker-json.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396
  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.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",["require","exports","module"], 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/range",["require","exports","module"], function(require, exports, module) {
  216. "use strict";
  217. var comparePoints = function(p1, p2) {
  218. return p1.row - p2.row || p1.column - p2.column;
  219. };
  220. var Range = function(startRow, startColumn, endRow, endColumn) {
  221. this.start = {
  222. row: startRow,
  223. column: startColumn
  224. };
  225. this.end = {
  226. row: endRow,
  227. column: endColumn
  228. };
  229. };
  230. (function() {
  231. this.isEqual = function(range) {
  232. return this.start.row === range.start.row &&
  233. this.end.row === range.end.row &&
  234. this.start.column === range.start.column &&
  235. this.end.column === range.end.column;
  236. };
  237. this.toString = function() {
  238. return ("Range: [" + this.start.row + "/" + this.start.column +
  239. "] -> [" + this.end.row + "/" + this.end.column + "]");
  240. };
  241. this.contains = function(row, column) {
  242. return this.compare(row, column) == 0;
  243. };
  244. this.compareRange = function(range) {
  245. var cmp,
  246. end = range.end,
  247. start = range.start;
  248. cmp = this.compare(end.row, end.column);
  249. if (cmp == 1) {
  250. cmp = this.compare(start.row, start.column);
  251. if (cmp == 1) {
  252. return 2;
  253. } else if (cmp == 0) {
  254. return 1;
  255. } else {
  256. return 0;
  257. }
  258. } else if (cmp == -1) {
  259. return -2;
  260. } else {
  261. cmp = this.compare(start.row, start.column);
  262. if (cmp == -1) {
  263. return -1;
  264. } else if (cmp == 1) {
  265. return 42;
  266. } else {
  267. return 0;
  268. }
  269. }
  270. };
  271. this.comparePoint = function(p) {
  272. return this.compare(p.row, p.column);
  273. };
  274. this.containsRange = function(range) {
  275. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  276. };
  277. this.intersects = function(range) {
  278. var cmp = this.compareRange(range);
  279. return (cmp == -1 || cmp == 0 || cmp == 1);
  280. };
  281. this.isEnd = function(row, column) {
  282. return this.end.row == row && this.end.column == column;
  283. };
  284. this.isStart = function(row, column) {
  285. return this.start.row == row && this.start.column == column;
  286. };
  287. this.setStart = function(row, column) {
  288. if (typeof row == "object") {
  289. this.start.column = row.column;
  290. this.start.row = row.row;
  291. } else {
  292. this.start.row = row;
  293. this.start.column = column;
  294. }
  295. };
  296. this.setEnd = function(row, column) {
  297. if (typeof row == "object") {
  298. this.end.column = row.column;
  299. this.end.row = row.row;
  300. } else {
  301. this.end.row = row;
  302. this.end.column = column;
  303. }
  304. };
  305. this.inside = function(row, column) {
  306. if (this.compare(row, column) == 0) {
  307. if (this.isEnd(row, column) || this.isStart(row, column)) {
  308. return false;
  309. } else {
  310. return true;
  311. }
  312. }
  313. return false;
  314. };
  315. this.insideStart = function(row, column) {
  316. if (this.compare(row, column) == 0) {
  317. if (this.isEnd(row, column)) {
  318. return false;
  319. } else {
  320. return true;
  321. }
  322. }
  323. return false;
  324. };
  325. this.insideEnd = function(row, column) {
  326. if (this.compare(row, column) == 0) {
  327. if (this.isStart(row, column)) {
  328. return false;
  329. } else {
  330. return true;
  331. }
  332. }
  333. return false;
  334. };
  335. this.compare = function(row, column) {
  336. if (!this.isMultiLine()) {
  337. if (row === this.start.row) {
  338. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  339. }
  340. }
  341. if (row < this.start.row)
  342. return -1;
  343. if (row > this.end.row)
  344. return 1;
  345. if (this.start.row === row)
  346. return column >= this.start.column ? 0 : -1;
  347. if (this.end.row === row)
  348. return column <= this.end.column ? 0 : 1;
  349. return 0;
  350. };
  351. this.compareStart = function(row, column) {
  352. if (this.start.row == row && this.start.column == column) {
  353. return -1;
  354. } else {
  355. return this.compare(row, column);
  356. }
  357. };
  358. this.compareEnd = function(row, column) {
  359. if (this.end.row == row && this.end.column == column) {
  360. return 1;
  361. } else {
  362. return this.compare(row, column);
  363. }
  364. };
  365. this.compareInside = function(row, column) {
  366. if (this.end.row == row && this.end.column == column) {
  367. return 1;
  368. } else if (this.start.row == row && this.start.column == column) {
  369. return -1;
  370. } else {
  371. return this.compare(row, column);
  372. }
  373. };
  374. this.clipRows = function(firstRow, lastRow) {
  375. if (this.end.row > lastRow)
  376. var end = {row: lastRow + 1, column: 0};
  377. else if (this.end.row < firstRow)
  378. var end = {row: firstRow, column: 0};
  379. if (this.start.row > lastRow)
  380. var start = {row: lastRow + 1, column: 0};
  381. else if (this.start.row < firstRow)
  382. var start = {row: firstRow, column: 0};
  383. return Range.fromPoints(start || this.start, end || this.end);
  384. };
  385. this.extend = function(row, column) {
  386. var cmp = this.compare(row, column);
  387. if (cmp == 0)
  388. return this;
  389. else if (cmp == -1)
  390. var start = {row: row, column: column};
  391. else
  392. var end = {row: row, column: column};
  393. return Range.fromPoints(start || this.start, end || this.end);
  394. };
  395. this.isEmpty = function() {
  396. return (this.start.row === this.end.row && this.start.column === this.end.column);
  397. };
  398. this.isMultiLine = function() {
  399. return (this.start.row !== this.end.row);
  400. };
  401. this.clone = function() {
  402. return Range.fromPoints(this.start, this.end);
  403. };
  404. this.collapseRows = function() {
  405. if (this.end.column == 0)
  406. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  407. else
  408. return new Range(this.start.row, 0, this.end.row, 0)
  409. };
  410. this.toScreenRange = function(session) {
  411. var screenPosStart = session.documentToScreenPosition(this.start);
  412. var screenPosEnd = session.documentToScreenPosition(this.end);
  413. return new Range(
  414. screenPosStart.row, screenPosStart.column,
  415. screenPosEnd.row, screenPosEnd.column
  416. );
  417. };
  418. this.moveBy = function(row, column) {
  419. this.start.row += row;
  420. this.start.column += column;
  421. this.end.row += row;
  422. this.end.column += column;
  423. };
  424. }).call(Range.prototype);
  425. Range.fromPoints = function(start, end) {
  426. return new Range(start.row, start.column, end.row, end.column);
  427. };
  428. Range.comparePoints = comparePoints;
  429. Range.comparePoints = function(p1, p2) {
  430. return p1.row - p2.row || p1.column - p2.column;
  431. };
  432. exports.Range = Range;
  433. });
  434. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  435. "use strict";
  436. function throwDeltaError(delta, errorText){
  437. console.log("Invalid Delta:", delta);
  438. throw "Invalid Delta: " + errorText;
  439. }
  440. function positionInDocument(docLines, position) {
  441. return position.row >= 0 && position.row < docLines.length &&
  442. position.column >= 0 && position.column <= docLines[position.row].length;
  443. }
  444. function validateDelta(docLines, delta) {
  445. if (delta.action != "insert" && delta.action != "remove")
  446. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  447. if (!(delta.lines instanceof Array))
  448. throwDeltaError(delta, "delta.lines must be an Array");
  449. if (!delta.start || !delta.end)
  450. throwDeltaError(delta, "delta.start/end must be an present");
  451. var start = delta.start;
  452. if (!positionInDocument(docLines, delta.start))
  453. throwDeltaError(delta, "delta.start must be contained in document");
  454. var end = delta.end;
  455. if (delta.action == "remove" && !positionInDocument(docLines, end))
  456. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  457. var numRangeRows = end.row - start.row;
  458. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  459. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  460. throwDeltaError(delta, "delta.range must match delta lines");
  461. }
  462. exports.applyDelta = function(docLines, delta, doNotValidate) {
  463. var row = delta.start.row;
  464. var startColumn = delta.start.column;
  465. var line = docLines[row] || "";
  466. switch (delta.action) {
  467. case "insert":
  468. var lines = delta.lines;
  469. if (lines.length === 1) {
  470. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  471. } else {
  472. var args = [row, 1].concat(delta.lines);
  473. docLines.splice.apply(docLines, args);
  474. docLines[row] = line.substring(0, startColumn) + docLines[row];
  475. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  476. }
  477. break;
  478. case "remove":
  479. var endColumn = delta.end.column;
  480. var endRow = delta.end.row;
  481. if (row === endRow) {
  482. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  483. } else {
  484. docLines.splice(
  485. row, endRow - row + 1,
  486. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  487. );
  488. }
  489. break;
  490. }
  491. }
  492. });
  493. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  494. "use strict";
  495. var EventEmitter = {};
  496. var stopPropagation = function() { this.propagationStopped = true; };
  497. var preventDefault = function() { this.defaultPrevented = true; };
  498. EventEmitter._emit =
  499. EventEmitter._dispatchEvent = function(eventName, e) {
  500. this._eventRegistry || (this._eventRegistry = {});
  501. this._defaultHandlers || (this._defaultHandlers = {});
  502. var listeners = this._eventRegistry[eventName] || [];
  503. var defaultHandler = this._defaultHandlers[eventName];
  504. if (!listeners.length && !defaultHandler)
  505. return;
  506. if (typeof e != "object" || !e)
  507. e = {};
  508. if (!e.type)
  509. e.type = eventName;
  510. if (!e.stopPropagation)
  511. e.stopPropagation = stopPropagation;
  512. if (!e.preventDefault)
  513. e.preventDefault = preventDefault;
  514. listeners = listeners.slice();
  515. for (var i=0; i<listeners.length; i++) {
  516. listeners[i](e, this);
  517. if (e.propagationStopped)
  518. break;
  519. }
  520. if (defaultHandler && !e.defaultPrevented)
  521. return defaultHandler(e, this);
  522. };
  523. EventEmitter._signal = function(eventName, e) {
  524. var listeners = (this._eventRegistry || {})[eventName];
  525. if (!listeners)
  526. return;
  527. listeners = listeners.slice();
  528. for (var i=0; i<listeners.length; i++)
  529. listeners[i](e, this);
  530. };
  531. EventEmitter.once = function(eventName, callback) {
  532. var _self = this;
  533. callback && this.addEventListener(eventName, function newCallback() {
  534. _self.removeEventListener(eventName, newCallback);
  535. callback.apply(null, arguments);
  536. });
  537. };
  538. EventEmitter.setDefaultHandler = function(eventName, callback) {
  539. var handlers = this._defaultHandlers
  540. if (!handlers)
  541. handlers = this._defaultHandlers = {_disabled_: {}};
  542. if (handlers[eventName]) {
  543. var old = handlers[eventName];
  544. var disabled = handlers._disabled_[eventName];
  545. if (!disabled)
  546. handlers._disabled_[eventName] = disabled = [];
  547. disabled.push(old);
  548. var i = disabled.indexOf(callback);
  549. if (i != -1)
  550. disabled.splice(i, 1);
  551. }
  552. handlers[eventName] = callback;
  553. };
  554. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  555. var handlers = this._defaultHandlers
  556. if (!handlers)
  557. return;
  558. var disabled = handlers._disabled_[eventName];
  559. if (handlers[eventName] == callback) {
  560. var old = handlers[eventName];
  561. if (disabled)
  562. this.setDefaultHandler(eventName, disabled.pop());
  563. } else if (disabled) {
  564. var i = disabled.indexOf(callback);
  565. if (i != -1)
  566. disabled.splice(i, 1);
  567. }
  568. };
  569. EventEmitter.on =
  570. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  571. this._eventRegistry = this._eventRegistry || {};
  572. var listeners = this._eventRegistry[eventName];
  573. if (!listeners)
  574. listeners = this._eventRegistry[eventName] = [];
  575. if (listeners.indexOf(callback) == -1)
  576. listeners[capturing ? "unshift" : "push"](callback);
  577. return callback;
  578. };
  579. EventEmitter.off =
  580. EventEmitter.removeListener =
  581. EventEmitter.removeEventListener = function(eventName, callback) {
  582. this._eventRegistry = this._eventRegistry || {};
  583. var listeners = this._eventRegistry[eventName];
  584. if (!listeners)
  585. return;
  586. var index = listeners.indexOf(callback);
  587. if (index !== -1)
  588. listeners.splice(index, 1);
  589. };
  590. EventEmitter.removeAllListeners = function(eventName) {
  591. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  592. };
  593. exports.EventEmitter = EventEmitter;
  594. });
  595. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  596. "use strict";
  597. var oop = require("./lib/oop");
  598. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  599. var Anchor = exports.Anchor = function(doc, row, column) {
  600. this.$onChange = this.onChange.bind(this);
  601. this.attach(doc);
  602. if (typeof column == "undefined")
  603. this.setPosition(row.row, row.column);
  604. else
  605. this.setPosition(row, column);
  606. };
  607. (function() {
  608. oop.implement(this, EventEmitter);
  609. this.getPosition = function() {
  610. return this.$clipPositionToDocument(this.row, this.column);
  611. };
  612. this.getDocument = function() {
  613. return this.document;
  614. };
  615. this.$insertRight = false;
  616. this.onChange = function(delta) {
  617. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  618. return;
  619. if (delta.start.row > this.row)
  620. return;
  621. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  622. this.setPosition(point.row, point.column, true);
  623. };
  624. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  625. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  626. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  627. }
  628. function $getTransformedPoint(delta, point, moveIfEqual) {
  629. var deltaIsInsert = delta.action == "insert";
  630. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  631. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  632. var deltaStart = delta.start;
  633. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  634. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  635. return {
  636. row: point.row,
  637. column: point.column
  638. };
  639. }
  640. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  641. return {
  642. row: point.row + deltaRowShift,
  643. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  644. };
  645. }
  646. return {
  647. row: deltaStart.row,
  648. column: deltaStart.column
  649. };
  650. }
  651. this.setPosition = function(row, column, noClip) {
  652. var pos;
  653. if (noClip) {
  654. pos = {
  655. row: row,
  656. column: column
  657. };
  658. } else {
  659. pos = this.$clipPositionToDocument(row, column);
  660. }
  661. if (this.row == pos.row && this.column == pos.column)
  662. return;
  663. var old = {
  664. row: this.row,
  665. column: this.column
  666. };
  667. this.row = pos.row;
  668. this.column = pos.column;
  669. this._signal("change", {
  670. old: old,
  671. value: pos
  672. });
  673. };
  674. this.detach = function() {
  675. this.document.removeEventListener("change", this.$onChange);
  676. };
  677. this.attach = function(doc) {
  678. this.document = doc || this.document;
  679. this.document.on("change", this.$onChange);
  680. };
  681. this.$clipPositionToDocument = function(row, column) {
  682. var pos = {};
  683. if (row >= this.document.getLength()) {
  684. pos.row = Math.max(0, this.document.getLength() - 1);
  685. pos.column = this.document.getLine(pos.row).length;
  686. }
  687. else if (row < 0) {
  688. pos.row = 0;
  689. pos.column = 0;
  690. }
  691. else {
  692. pos.row = row;
  693. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  694. }
  695. if (column < 0)
  696. pos.column = 0;
  697. return pos;
  698. };
  699. }).call(Anchor.prototype);
  700. });
  701. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  702. "use strict";
  703. var oop = require("./lib/oop");
  704. var applyDelta = require("./apply_delta").applyDelta;
  705. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  706. var Range = require("./range").Range;
  707. var Anchor = require("./anchor").Anchor;
  708. var Document = function(textOrLines) {
  709. this.$lines = [""];
  710. if (textOrLines.length === 0) {
  711. this.$lines = [""];
  712. } else if (Array.isArray(textOrLines)) {
  713. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  714. } else {
  715. this.insert({row: 0, column:0}, textOrLines);
  716. }
  717. };
  718. (function() {
  719. oop.implement(this, EventEmitter);
  720. this.setValue = function(text) {
  721. var len = this.getLength() - 1;
  722. this.remove(new Range(0, 0, len, this.getLine(len).length));
  723. this.insert({row: 0, column: 0}, text);
  724. };
  725. this.getValue = function() {
  726. return this.getAllLines().join(this.getNewLineCharacter());
  727. };
  728. this.createAnchor = function(row, column) {
  729. return new Anchor(this, row, column);
  730. };
  731. if ("aaa".split(/a/).length === 0) {
  732. this.$split = function(text) {
  733. return text.replace(/\r\n|\r/g, "\n").split("\n");
  734. };
  735. } else {
  736. this.$split = function(text) {
  737. return text.split(/\r\n|\r|\n/);
  738. };
  739. }
  740. this.$detectNewLine = function(text) {
  741. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  742. this.$autoNewLine = match ? match[1] : "\n";
  743. this._signal("changeNewLineMode");
  744. };
  745. this.getNewLineCharacter = function() {
  746. switch (this.$newLineMode) {
  747. case "windows":
  748. return "\r\n";
  749. case "unix":
  750. return "\n";
  751. default:
  752. return this.$autoNewLine || "\n";
  753. }
  754. };
  755. this.$autoNewLine = "";
  756. this.$newLineMode = "auto";
  757. this.setNewLineMode = function(newLineMode) {
  758. if (this.$newLineMode === newLineMode)
  759. return;
  760. this.$newLineMode = newLineMode;
  761. this._signal("changeNewLineMode");
  762. };
  763. this.getNewLineMode = function() {
  764. return this.$newLineMode;
  765. };
  766. this.isNewLine = function(text) {
  767. return (text == "\r\n" || text == "\r" || text == "\n");
  768. };
  769. this.getLine = function(row) {
  770. return this.$lines[row] || "";
  771. };
  772. this.getLines = function(firstRow, lastRow) {
  773. return this.$lines.slice(firstRow, lastRow + 1);
  774. };
  775. this.getAllLines = function() {
  776. return this.getLines(0, this.getLength());
  777. };
  778. this.getLength = function() {
  779. return this.$lines.length;
  780. };
  781. this.getTextRange = function(range) {
  782. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  783. };
  784. this.getLinesForRange = function(range) {
  785. var lines;
  786. if (range.start.row === range.end.row) {
  787. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  788. } else {
  789. lines = this.getLines(range.start.row, range.end.row);
  790. lines[0] = (lines[0] || "").substring(range.start.column);
  791. var l = lines.length - 1;
  792. if (range.end.row - range.start.row == l)
  793. lines[l] = lines[l].substring(0, range.end.column);
  794. }
  795. return lines;
  796. };
  797. this.insertLines = function(row, lines) {
  798. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  799. return this.insertFullLines(row, lines);
  800. };
  801. this.removeLines = function(firstRow, lastRow) {
  802. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  803. return this.removeFullLines(firstRow, lastRow);
  804. };
  805. this.insertNewLine = function(position) {
  806. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  807. return this.insertMergedLines(position, ["", ""]);
  808. };
  809. this.insert = function(position, text) {
  810. if (this.getLength() <= 1)
  811. this.$detectNewLine(text);
  812. return this.insertMergedLines(position, this.$split(text));
  813. };
  814. this.insertInLine = function(position, text) {
  815. var start = this.clippedPos(position.row, position.column);
  816. var end = this.pos(position.row, position.column + text.length);
  817. this.applyDelta({
  818. start: start,
  819. end: end,
  820. action: "insert",
  821. lines: [text]
  822. }, true);
  823. return this.clonePos(end);
  824. };
  825. this.clippedPos = function(row, column) {
  826. var length = this.getLength();
  827. if (row === undefined) {
  828. row = length;
  829. } else if (row < 0) {
  830. row = 0;
  831. } else if (row >= length) {
  832. row = length - 1;
  833. column = undefined;
  834. }
  835. var line = this.getLine(row);
  836. if (column == undefined)
  837. column = line.length;
  838. column = Math.min(Math.max(column, 0), line.length);
  839. return {row: row, column: column};
  840. };
  841. this.clonePos = function(pos) {
  842. return {row: pos.row, column: pos.column};
  843. };
  844. this.pos = function(row, column) {
  845. return {row: row, column: column};
  846. };
  847. this.$clipPosition = function(position) {
  848. var length = this.getLength();
  849. if (position.row >= length) {
  850. position.row = Math.max(0, length - 1);
  851. position.column = this.getLine(length - 1).length;
  852. } else {
  853. position.row = Math.max(0, position.row);
  854. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  855. }
  856. return position;
  857. };
  858. this.insertFullLines = function(row, lines) {
  859. row = Math.min(Math.max(row, 0), this.getLength());
  860. var column = 0;
  861. if (row < this.getLength()) {
  862. lines = lines.concat([""]);
  863. column = 0;
  864. } else {
  865. lines = [""].concat(lines);
  866. row--;
  867. column = this.$lines[row].length;
  868. }
  869. this.insertMergedLines({row: row, column: column}, lines);
  870. };
  871. this.insertMergedLines = function(position, lines) {
  872. var start = this.clippedPos(position.row, position.column);
  873. var end = {
  874. row: start.row + lines.length - 1,
  875. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  876. };
  877. this.applyDelta({
  878. start: start,
  879. end: end,
  880. action: "insert",
  881. lines: lines
  882. });
  883. return this.clonePos(end);
  884. };
  885. this.remove = function(range) {
  886. var start = this.clippedPos(range.start.row, range.start.column);
  887. var end = this.clippedPos(range.end.row, range.end.column);
  888. this.applyDelta({
  889. start: start,
  890. end: end,
  891. action: "remove",
  892. lines: this.getLinesForRange({start: start, end: end})
  893. });
  894. return this.clonePos(start);
  895. };
  896. this.removeInLine = function(row, startColumn, endColumn) {
  897. var start = this.clippedPos(row, startColumn);
  898. var end = this.clippedPos(row, endColumn);
  899. this.applyDelta({
  900. start: start,
  901. end: end,
  902. action: "remove",
  903. lines: this.getLinesForRange({start: start, end: end})
  904. }, true);
  905. return this.clonePos(start);
  906. };
  907. this.removeFullLines = function(firstRow, lastRow) {
  908. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  909. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  910. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  911. var deleteLastNewLine = lastRow < this.getLength() - 1;
  912. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  913. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  914. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  915. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  916. var range = new Range(startRow, startCol, endRow, endCol);
  917. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  918. this.applyDelta({
  919. start: range.start,
  920. end: range.end,
  921. action: "remove",
  922. lines: this.getLinesForRange(range)
  923. });
  924. return deletedLines;
  925. };
  926. this.removeNewLine = function(row) {
  927. if (row < this.getLength() - 1 && row >= 0) {
  928. this.applyDelta({
  929. start: this.pos(row, this.getLine(row).length),
  930. end: this.pos(row + 1, 0),
  931. action: "remove",
  932. lines: ["", ""]
  933. });
  934. }
  935. };
  936. this.replace = function(range, text) {
  937. if (!(range instanceof Range))
  938. range = Range.fromPoints(range.start, range.end);
  939. if (text.length === 0 && range.isEmpty())
  940. return range.start;
  941. if (text == this.getTextRange(range))
  942. return range.end;
  943. this.remove(range);
  944. var end;
  945. if (text) {
  946. end = this.insert(range.start, text);
  947. }
  948. else {
  949. end = range.start;
  950. }
  951. return end;
  952. };
  953. this.applyDeltas = function(deltas) {
  954. for (var i=0; i<deltas.length; i++) {
  955. this.applyDelta(deltas[i]);
  956. }
  957. };
  958. this.revertDeltas = function(deltas) {
  959. for (var i=deltas.length-1; i>=0; i--) {
  960. this.revertDelta(deltas[i]);
  961. }
  962. };
  963. this.applyDelta = function(delta, doNotValidate) {
  964. var isInsert = delta.action == "insert";
  965. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  966. : !Range.comparePoints(delta.start, delta.end)) {
  967. return;
  968. }
  969. if (isInsert && delta.lines.length > 20000)
  970. this.$splitAndapplyLargeDelta(delta, 20000);
  971. applyDelta(this.$lines, delta, doNotValidate);
  972. this._signal("change", delta);
  973. };
  974. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  975. var lines = delta.lines;
  976. var l = lines.length;
  977. var row = delta.start.row;
  978. var column = delta.start.column;
  979. var from = 0, to = 0;
  980. do {
  981. from = to;
  982. to += MAX - 1;
  983. var chunk = lines.slice(from, to);
  984. if (to > l) {
  985. delta.lines = chunk;
  986. delta.start.row = row + from;
  987. delta.start.column = column;
  988. break;
  989. }
  990. chunk.push("");
  991. this.applyDelta({
  992. start: this.pos(row + from, column),
  993. end: this.pos(row + to, column = 0),
  994. action: delta.action,
  995. lines: chunk
  996. }, true);
  997. } while(true);
  998. };
  999. this.revertDelta = function(delta) {
  1000. this.applyDelta({
  1001. start: this.clonePos(delta.start),
  1002. end: this.clonePos(delta.end),
  1003. action: (delta.action == "insert" ? "remove" : "insert"),
  1004. lines: delta.lines.slice()
  1005. });
  1006. };
  1007. this.indexToPosition = function(index, startRow) {
  1008. var lines = this.$lines || this.getAllLines();
  1009. var newlineLength = this.getNewLineCharacter().length;
  1010. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1011. index -= lines[i].length + newlineLength;
  1012. if (index < 0)
  1013. return {row: i, column: index + lines[i].length + newlineLength};
  1014. }
  1015. return {row: l-1, column: lines[l-1].length};
  1016. };
  1017. this.positionToIndex = function(pos, startRow) {
  1018. var lines = this.$lines || this.getAllLines();
  1019. var newlineLength = this.getNewLineCharacter().length;
  1020. var index = 0;
  1021. var row = Math.min(pos.row, lines.length);
  1022. for (var i = startRow || 0; i < row; ++i)
  1023. index += lines[i].length + newlineLength;
  1024. return index + pos.column;
  1025. };
  1026. }).call(Document.prototype);
  1027. exports.Document = Document;
  1028. });
  1029. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1030. "use strict";
  1031. exports.last = function(a) {
  1032. return a[a.length - 1];
  1033. };
  1034. exports.stringReverse = function(string) {
  1035. return string.split("").reverse().join("");
  1036. };
  1037. exports.stringRepeat = function (string, count) {
  1038. var result = '';
  1039. while (count > 0) {
  1040. if (count & 1)
  1041. result += string;
  1042. if (count >>= 1)
  1043. string += string;
  1044. }
  1045. return result;
  1046. };
  1047. var trimBeginRegexp = /^\s\s*/;
  1048. var trimEndRegexp = /\s\s*$/;
  1049. exports.stringTrimLeft = function (string) {
  1050. return string.replace(trimBeginRegexp, '');
  1051. };
  1052. exports.stringTrimRight = function (string) {
  1053. return string.replace(trimEndRegexp, '');
  1054. };
  1055. exports.copyObject = function(obj) {
  1056. var copy = {};
  1057. for (var key in obj) {
  1058. copy[key] = obj[key];
  1059. }
  1060. return copy;
  1061. };
  1062. exports.copyArray = function(array){
  1063. var copy = [];
  1064. for (var i=0, l=array.length; i<l; i++) {
  1065. if (array[i] && typeof array[i] == "object")
  1066. copy[i] = this.copyObject(array[i]);
  1067. else
  1068. copy[i] = array[i];
  1069. }
  1070. return copy;
  1071. };
  1072. exports.deepCopy = function deepCopy(obj) {
  1073. if (typeof obj !== "object" || !obj)
  1074. return obj;
  1075. var copy;
  1076. if (Array.isArray(obj)) {
  1077. copy = [];
  1078. for (var key = 0; key < obj.length; key++) {
  1079. copy[key] = deepCopy(obj[key]);
  1080. }
  1081. return copy;
  1082. }
  1083. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1084. return obj;
  1085. copy = {};
  1086. for (var key in obj)
  1087. copy[key] = deepCopy(obj[key]);
  1088. return copy;
  1089. };
  1090. exports.arrayToMap = function(arr) {
  1091. var map = {};
  1092. for (var i=0; i<arr.length; i++) {
  1093. map[arr[i]] = 1;
  1094. }
  1095. return map;
  1096. };
  1097. exports.createMap = function(props) {
  1098. var map = Object.create(null);
  1099. for (var i in props) {
  1100. map[i] = props[i];
  1101. }
  1102. return map;
  1103. };
  1104. exports.arrayRemove = function(array, value) {
  1105. for (var i = 0; i <= array.length; i++) {
  1106. if (value === array[i]) {
  1107. array.splice(i, 1);
  1108. }
  1109. }
  1110. };
  1111. exports.escapeRegExp = function(str) {
  1112. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1113. };
  1114. exports.escapeHTML = function(str) {
  1115. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1116. };
  1117. exports.getMatchOffsets = function(string, regExp) {
  1118. var matches = [];
  1119. string.replace(regExp, function(str) {
  1120. matches.push({
  1121. offset: arguments[arguments.length-2],
  1122. length: str.length
  1123. });
  1124. });
  1125. return matches;
  1126. };
  1127. exports.deferredCall = function(fcn) {
  1128. var timer = null;
  1129. var callback = function() {
  1130. timer = null;
  1131. fcn();
  1132. };
  1133. var deferred = function(timeout) {
  1134. deferred.cancel();
  1135. timer = setTimeout(callback, timeout || 0);
  1136. return deferred;
  1137. };
  1138. deferred.schedule = deferred;
  1139. deferred.call = function() {
  1140. this.cancel();
  1141. fcn();
  1142. return deferred;
  1143. };
  1144. deferred.cancel = function() {
  1145. clearTimeout(timer);
  1146. timer = null;
  1147. return deferred;
  1148. };
  1149. deferred.isPending = function() {
  1150. return timer;
  1151. };
  1152. return deferred;
  1153. };
  1154. exports.delayedCall = function(fcn, defaultTimeout) {
  1155. var timer = null;
  1156. var callback = function() {
  1157. timer = null;
  1158. fcn();
  1159. };
  1160. var _self = function(timeout) {
  1161. if (timer == null)
  1162. timer = setTimeout(callback, timeout || defaultTimeout);
  1163. };
  1164. _self.delay = function(timeout) {
  1165. timer && clearTimeout(timer);
  1166. timer = setTimeout(callback, timeout || defaultTimeout);
  1167. };
  1168. _self.schedule = _self;
  1169. _self.call = function() {
  1170. this.cancel();
  1171. fcn();
  1172. };
  1173. _self.cancel = function() {
  1174. timer && clearTimeout(timer);
  1175. timer = null;
  1176. };
  1177. _self.isPending = function() {
  1178. return timer;
  1179. };
  1180. return _self;
  1181. };
  1182. });
  1183. ace.define("ace/worker/mirror",["require","exports","module","ace/range","ace/document","ace/lib/lang"], function(require, exports, module) {
  1184. "use strict";
  1185. var Range = require("../range").Range;
  1186. var Document = require("../document").Document;
  1187. var lang = require("../lib/lang");
  1188. var Mirror = exports.Mirror = function(sender) {
  1189. this.sender = sender;
  1190. var doc = this.doc = new Document("");
  1191. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1192. var _self = this;
  1193. sender.on("change", function(e) {
  1194. var data = e.data;
  1195. if (data[0].start) {
  1196. doc.applyDeltas(data);
  1197. } else {
  1198. for (var i = 0; i < data.length; i += 2) {
  1199. if (Array.isArray(data[i+1])) {
  1200. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1201. } else {
  1202. var d = {action: "remove", start: data[i], end: data[i+1]};
  1203. }
  1204. doc.applyDelta(d, true);
  1205. }
  1206. }
  1207. if (_self.$timeout)
  1208. return deferredUpdate.schedule(_self.$timeout);
  1209. _self.onUpdate();
  1210. });
  1211. };
  1212. (function() {
  1213. this.$timeout = 500;
  1214. this.setTimeout = function(timeout) {
  1215. this.$timeout = timeout;
  1216. };
  1217. this.setValue = function(value) {
  1218. this.doc.setValue(value);
  1219. this.deferredUpdate.schedule(this.$timeout);
  1220. };
  1221. this.getValue = function(callbackId) {
  1222. this.sender.callback(this.doc.getValue(), callbackId);
  1223. };
  1224. this.onUpdate = function() {
  1225. };
  1226. this.isPending = function() {
  1227. return this.deferredUpdate.isPending();
  1228. };
  1229. }).call(Mirror.prototype);
  1230. });
  1231. ace.define("ace/mode/json/json_parse",["require","exports","module"], function(require, exports, module) {
  1232. "use strict";
  1233. var at, // The index of the current character
  1234. ch, // The current character
  1235. escapee = {
  1236. '"': '"',
  1237. '\\': '\\',
  1238. '/': '/',
  1239. b: '\b',
  1240. f: '\f',
  1241. n: '\n',
  1242. r: '\r',
  1243. t: '\t'
  1244. },
  1245. text,
  1246. error = function (m) {
  1247. throw {
  1248. name: 'SyntaxError',
  1249. message: m,
  1250. at: at,
  1251. text: text
  1252. };
  1253. },
  1254. next = function (c) {
  1255. if (c && c !== ch) {
  1256. error("Expected '" + c + "' instead of '" + ch + "'");
  1257. }
  1258. ch = text.charAt(at);
  1259. at += 1;
  1260. return ch;
  1261. },
  1262. number = function () {
  1263. var number,
  1264. string = '';
  1265. if (ch === '-') {
  1266. string = '-';
  1267. next('-');
  1268. }
  1269. while (ch >= '0' && ch <= '9') {
  1270. string += ch;
  1271. next();
  1272. }
  1273. if (ch === '.') {
  1274. string += '.';
  1275. while (next() && ch >= '0' && ch <= '9') {
  1276. string += ch;
  1277. }
  1278. }
  1279. if (ch === 'e' || ch === 'E') {
  1280. string += ch;
  1281. next();
  1282. if (ch === '-' || ch === '+') {
  1283. string += ch;
  1284. next();
  1285. }
  1286. while (ch >= '0' && ch <= '9') {
  1287. string += ch;
  1288. next();
  1289. }
  1290. }
  1291. number = +string;
  1292. if (isNaN(number)) {
  1293. error("Bad number");
  1294. } else {
  1295. return number;
  1296. }
  1297. },
  1298. string = function () {
  1299. var hex,
  1300. i,
  1301. string = '',
  1302. uffff;
  1303. if (ch === '"') {
  1304. while (next()) {
  1305. if (ch === '"') {
  1306. next();
  1307. return string;
  1308. } else if (ch === '\\') {
  1309. next();
  1310. if (ch === 'u') {
  1311. uffff = 0;
  1312. for (i = 0; i < 4; i += 1) {
  1313. hex = parseInt(next(), 16);
  1314. if (!isFinite(hex)) {
  1315. break;
  1316. }
  1317. uffff = uffff * 16 + hex;
  1318. }
  1319. string += String.fromCharCode(uffff);
  1320. } else if (typeof escapee[ch] === 'string') {
  1321. string += escapee[ch];
  1322. } else {
  1323. break;
  1324. }
  1325. } else {
  1326. string += ch;
  1327. }
  1328. }
  1329. }
  1330. error("Bad string");
  1331. },
  1332. white = function () {
  1333. while (ch && ch <= ' ') {
  1334. next();
  1335. }
  1336. },
  1337. word = function () {
  1338. switch (ch) {
  1339. case 't':
  1340. next('t');
  1341. next('r');
  1342. next('u');
  1343. next('e');
  1344. return true;
  1345. case 'f':
  1346. next('f');
  1347. next('a');
  1348. next('l');
  1349. next('s');
  1350. next('e');
  1351. return false;
  1352. case 'n':
  1353. next('n');
  1354. next('u');
  1355. next('l');
  1356. next('l');
  1357. return null;
  1358. }
  1359. error("Unexpected '" + ch + "'");
  1360. },
  1361. value, // Place holder for the value function.
  1362. array = function () {
  1363. var array = [];
  1364. if (ch === '[') {
  1365. next('[');
  1366. white();
  1367. if (ch === ']') {
  1368. next(']');
  1369. return array; // empty array
  1370. }
  1371. while (ch) {
  1372. array.push(value());
  1373. white();
  1374. if (ch === ']') {
  1375. next(']');
  1376. return array;
  1377. }
  1378. next(',');
  1379. white();
  1380. }
  1381. }
  1382. error("Bad array");
  1383. },
  1384. object = function () {
  1385. var key,
  1386. object = {};
  1387. if (ch === '{') {
  1388. next('{');
  1389. white();
  1390. if (ch === '}') {
  1391. next('}');
  1392. return object; // empty object
  1393. }
  1394. while (ch) {
  1395. key = string();
  1396. white();
  1397. next(':');
  1398. if (Object.hasOwnProperty.call(object, key)) {
  1399. error('Duplicate key "' + key + '"');
  1400. }
  1401. object[key] = value();
  1402. white();
  1403. if (ch === '}') {
  1404. next('}');
  1405. return object;
  1406. }
  1407. next(',');
  1408. white();
  1409. }
  1410. }
  1411. error("Bad object");
  1412. };
  1413. value = function () {
  1414. white();
  1415. switch (ch) {
  1416. case '{':
  1417. return object();
  1418. case '[':
  1419. return array();
  1420. case '"':
  1421. return string();
  1422. case '-':
  1423. return number();
  1424. default:
  1425. return ch >= '0' && ch <= '9' ? number() : word();
  1426. }
  1427. };
  1428. return function (source, reviver) {
  1429. var result;
  1430. text = source;
  1431. at = 0;
  1432. ch = ' ';
  1433. result = value();
  1434. white();
  1435. if (ch) {
  1436. error("Syntax error");
  1437. }
  1438. return typeof reviver === 'function' ? function walk(holder, key) {
  1439. var k, v, value = holder[key];
  1440. if (value && typeof value === 'object') {
  1441. for (k in value) {
  1442. if (Object.hasOwnProperty.call(value, k)) {
  1443. v = walk(value, k);
  1444. if (v !== undefined) {
  1445. value[k] = v;
  1446. } else {
  1447. delete value[k];
  1448. }
  1449. }
  1450. }
  1451. }
  1452. return reviver.call(holder, key, value);
  1453. }({'': result}, '') : result;
  1454. };
  1455. });
  1456. ace.define("ace/mode/json_worker",["require","exports","module","ace/lib/oop","ace/worker/mirror","ace/mode/json/json_parse"], function(require, exports, module) {
  1457. "use strict";
  1458. var oop = require("../lib/oop");
  1459. var Mirror = require("../worker/mirror").Mirror;
  1460. var parse = require("./json/json_parse");
  1461. var JsonWorker = exports.JsonWorker = function(sender) {
  1462. Mirror.call(this, sender);
  1463. this.setTimeout(200);
  1464. };
  1465. oop.inherits(JsonWorker, Mirror);
  1466. (function() {
  1467. this.onUpdate = function() {
  1468. var value = this.doc.getValue();
  1469. var errors = [];
  1470. try {
  1471. if (value)
  1472. parse(value);
  1473. } catch (e) {
  1474. var pos = this.doc.indexToPosition(e.at-1);
  1475. errors.push({
  1476. row: pos.row,
  1477. column: pos.column,
  1478. text: e.message,
  1479. type: "error"
  1480. });
  1481. }
  1482. this.sender.emit("annotate", errors);
  1483. };
  1484. }).call(JsonWorker.prototype);
  1485. });
  1486. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  1487. function Empty() {}
  1488. if (!Function.prototype.bind) {
  1489. Function.prototype.bind = function bind(that) { // .length is 1
  1490. var target = this;
  1491. if (typeof target != "function") {
  1492. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  1493. }
  1494. var args = slice.call(arguments, 1); // for normal call
  1495. var bound = function () {
  1496. if (this instanceof bound) {
  1497. var result = target.apply(
  1498. this,
  1499. args.concat(slice.call(arguments))
  1500. );
  1501. if (Object(result) === result) {
  1502. return result;
  1503. }
  1504. return this;
  1505. } else {
  1506. return target.apply(
  1507. that,
  1508. args.concat(slice.call(arguments))
  1509. );
  1510. }
  1511. };
  1512. if(target.prototype) {
  1513. Empty.prototype = target.prototype;
  1514. bound.prototype = new Empty();
  1515. Empty.prototype = null;
  1516. }
  1517. return bound;
  1518. };
  1519. }
  1520. var call = Function.prototype.call;
  1521. var prototypeOfArray = Array.prototype;
  1522. var prototypeOfObject = Object.prototype;
  1523. var slice = prototypeOfArray.slice;
  1524. var _toString = call.bind(prototypeOfObject.toString);
  1525. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  1526. var defineGetter;
  1527. var defineSetter;
  1528. var lookupGetter;
  1529. var lookupSetter;
  1530. var supportsAccessors;
  1531. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  1532. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  1533. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  1534. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  1535. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  1536. }
  1537. if ([1,2].splice(0).length != 2) {
  1538. if(function() { // test IE < 9 to splice bug - see issue #138
  1539. function makeArray(l) {
  1540. var a = new Array(l+2);
  1541. a[0] = a[1] = 0;
  1542. return a;
  1543. }
  1544. var array = [], lengthBefore;
  1545. array.splice.apply(array, makeArray(20));
  1546. array.splice.apply(array, makeArray(26));
  1547. lengthBefore = array.length; //46
  1548. array.splice(5, 0, "XXX"); // add one element
  1549. lengthBefore + 1 == array.length
  1550. if (lengthBefore + 1 == array.length) {
  1551. return true;// has right splice implementation without bugs
  1552. }
  1553. }()) {//IE 6/7
  1554. var array_splice = Array.prototype.splice;
  1555. Array.prototype.splice = function(start, deleteCount) {
  1556. if (!arguments.length) {
  1557. return [];
  1558. } else {
  1559. return array_splice.apply(this, [
  1560. start === void 0 ? 0 : start,
  1561. deleteCount === void 0 ? (this.length - start) : deleteCount
  1562. ].concat(slice.call(arguments, 2)))
  1563. }
  1564. };
  1565. } else {//IE8
  1566. Array.prototype.splice = function(pos, removeCount){
  1567. var length = this.length;
  1568. if (pos > 0) {
  1569. if (pos > length)
  1570. pos = length;
  1571. } else if (pos == void 0) {
  1572. pos = 0;
  1573. } else if (pos < 0) {
  1574. pos = Math.max(length + pos, 0);
  1575. }
  1576. if (!(pos+removeCount < length))
  1577. removeCount = length - pos;
  1578. var removed = this.slice(pos, pos+removeCount);
  1579. var insert = slice.call(arguments, 2);
  1580. var add = insert.length;
  1581. if (pos === length) {
  1582. if (add) {
  1583. this.push.apply(this, insert);
  1584. }
  1585. } else {
  1586. var remove = Math.min(removeCount, length - pos);
  1587. var tailOldPos = pos + remove;
  1588. var tailNewPos = tailOldPos + add - remove;
  1589. var tailCount = length - tailOldPos;
  1590. var lengthAfterRemove = length - remove;
  1591. if (tailNewPos < tailOldPos) { // case A
  1592. for (var i = 0; i < tailCount; ++i) {
  1593. this[tailNewPos+i] = this[tailOldPos+i];
  1594. }
  1595. } else if (tailNewPos > tailOldPos) { // case B
  1596. for (i = tailCount; i--; ) {
  1597. this[tailNewPos+i] = this[tailOldPos+i];
  1598. }
  1599. } // else, add == remove (nothing to do)
  1600. if (add && pos === lengthAfterRemove) {
  1601. this.length = lengthAfterRemove; // truncate array
  1602. this.push.apply(this, insert);
  1603. } else {
  1604. this.length = lengthAfterRemove + add; // reserves space
  1605. for (i = 0; i < add; ++i) {
  1606. this[pos+i] = insert[i];
  1607. }
  1608. }
  1609. }
  1610. return removed;
  1611. };
  1612. }
  1613. }
  1614. if (!Array.isArray) {
  1615. Array.isArray = function isArray(obj) {
  1616. return _toString(obj) == "[object Array]";
  1617. };
  1618. }
  1619. var boxedString = Object("a"),
  1620. splitString = boxedString[0] != "a" || !(0 in boxedString);
  1621. if (!Array.prototype.forEach) {
  1622. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  1623. var object = toObject(this),
  1624. self = splitString && _toString(this) == "[object String]" ?
  1625. this.split("") :
  1626. object,
  1627. thisp = arguments[1],
  1628. i = -1,
  1629. length = self.length >>> 0;
  1630. if (_toString(fun) != "[object Function]") {
  1631. throw new TypeError(); // TODO message
  1632. }
  1633. while (++i < length) {
  1634. if (i in self) {
  1635. fun.call(thisp, self[i], i, object);
  1636. }
  1637. }
  1638. };
  1639. }
  1640. if (!Array.prototype.map) {
  1641. Array.prototype.map = function map(fun /*, thisp*/) {
  1642. var object = toObject(this),
  1643. self = splitString && _toString(this) == "[object String]" ?
  1644. this.split("") :
  1645. object,
  1646. length = self.length >>> 0,
  1647. result = Array(length),
  1648. thisp = arguments[1];
  1649. if (_toString(fun) != "[object Function]") {
  1650. throw new TypeError(fun + " is not a function");
  1651. }
  1652. for (var i = 0; i < length; i++) {
  1653. if (i in self)
  1654. result[i] = fun.call(thisp, self[i], i, object);
  1655. }
  1656. return result;
  1657. };
  1658. }
  1659. if (!Array.prototype.filter) {
  1660. Array.prototype.filter = function filter(fun /*, thisp */) {
  1661. var object = toObject(this),
  1662. self = splitString && _toString(this) == "[object String]" ?
  1663. this.split("") :
  1664. object,
  1665. length = self.length >>> 0,
  1666. result = [],
  1667. value,
  1668. thisp = arguments[1];
  1669. if (_toString(fun) != "[object Function]") {
  1670. throw new TypeError(fun + " is not a function");
  1671. }
  1672. for (var i = 0; i < length; i++) {
  1673. if (i in self) {
  1674. value = self[i];
  1675. if (fun.call(thisp, value, i, object)) {
  1676. result.push(value);
  1677. }
  1678. }
  1679. }
  1680. return result;
  1681. };
  1682. }
  1683. if (!Array.prototype.every) {
  1684. Array.prototype.every = function every(fun /*, thisp */) {
  1685. var object = toObject(this),
  1686. self = splitString && _toString(this) == "[object String]" ?
  1687. this.split("") :
  1688. object,
  1689. length = self.length >>> 0,
  1690. thisp = arguments[1];
  1691. if (_toString(fun) != "[object Function]") {
  1692. throw new TypeError(fun + " is not a function");
  1693. }
  1694. for (var i = 0; i < length; i++) {
  1695. if (i in self && !fun.call(thisp, self[i], i, object)) {
  1696. return false;
  1697. }
  1698. }
  1699. return true;
  1700. };
  1701. }
  1702. if (!Array.prototype.some) {
  1703. Array.prototype.some = function some(fun /*, thisp */) {
  1704. var object = toObject(this),
  1705. self = splitString && _toString(this) == "[object String]" ?
  1706. this.split("") :
  1707. object,
  1708. length = self.length >>> 0,
  1709. thisp = arguments[1];
  1710. if (_toString(fun) != "[object Function]") {
  1711. throw new TypeError(fun + " is not a function");
  1712. }
  1713. for (var i = 0; i < length; i++) {
  1714. if (i in self && fun.call(thisp, self[i], i, object)) {
  1715. return true;
  1716. }
  1717. }
  1718. return false;
  1719. };
  1720. }
  1721. if (!Array.prototype.reduce) {
  1722. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  1723. var object = toObject(this),
  1724. self = splitString && _toString(this) == "[object String]" ?
  1725. this.split("") :
  1726. object,
  1727. length = self.length >>> 0;
  1728. if (_toString(fun) != "[object Function]") {
  1729. throw new TypeError(fun + " is not a function");
  1730. }
  1731. if (!length && arguments.length == 1) {
  1732. throw new TypeError("reduce of empty array with no initial value");
  1733. }
  1734. var i = 0;
  1735. var result;
  1736. if (arguments.length >= 2) {
  1737. result = arguments[1];
  1738. } else {
  1739. do {
  1740. if (i in self) {
  1741. result = self[i++];
  1742. break;
  1743. }
  1744. if (++i >= length) {
  1745. throw new TypeError("reduce of empty array with no initial value");
  1746. }
  1747. } while (true);
  1748. }
  1749. for (; i < length; i++) {
  1750. if (i in self) {
  1751. result = fun.call(void 0, result, self[i], i, object);
  1752. }
  1753. }
  1754. return result;
  1755. };
  1756. }
  1757. if (!Array.prototype.reduceRight) {
  1758. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  1759. var object = toObject(this),
  1760. self = splitString && _toString(this) == "[object String]" ?
  1761. this.split("") :
  1762. object,
  1763. length = self.length >>> 0;
  1764. if (_toString(fun) != "[object Function]") {
  1765. throw new TypeError(fun + " is not a function");
  1766. }
  1767. if (!length && arguments.length == 1) {
  1768. throw new TypeError("reduceRight of empty array with no initial value");
  1769. }
  1770. var result, i = length - 1;
  1771. if (arguments.length >= 2) {
  1772. result = arguments[1];
  1773. } else {
  1774. do {
  1775. if (i in self) {
  1776. result = self[i--];
  1777. break;
  1778. }
  1779. if (--i < 0) {
  1780. throw new TypeError("reduceRight of empty array with no initial value");
  1781. }
  1782. } while (true);
  1783. }
  1784. do {
  1785. if (i in this) {
  1786. result = fun.call(void 0, result, self[i], i, object);
  1787. }
  1788. } while (i--);
  1789. return result;
  1790. };
  1791. }
  1792. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  1793. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  1794. var self = splitString && _toString(this) == "[object String]" ?
  1795. this.split("") :
  1796. toObject(this),
  1797. length = self.length >>> 0;
  1798. if (!length) {
  1799. return -1;
  1800. }
  1801. var i = 0;
  1802. if (arguments.length > 1) {
  1803. i = toInteger(arguments[1]);
  1804. }
  1805. i = i >= 0 ? i : Math.max(0, length + i);
  1806. for (; i < length; i++) {
  1807. if (i in self && self[i] === sought) {
  1808. return i;
  1809. }
  1810. }
  1811. return -1;
  1812. };
  1813. }
  1814. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  1815. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  1816. var self = splitString && _toString(this) == "[object String]" ?
  1817. this.split("") :
  1818. toObject(this),
  1819. length = self.length >>> 0;
  1820. if (!length) {
  1821. return -1;
  1822. }
  1823. var i = length - 1;
  1824. if (arguments.length > 1) {
  1825. i = Math.min(i, toInteger(arguments[1]));
  1826. }
  1827. i = i >= 0 ? i : length - Math.abs(i);
  1828. for (; i >= 0; i--) {
  1829. if (i in self && sought === self[i]) {
  1830. return i;
  1831. }
  1832. }
  1833. return -1;
  1834. };
  1835. }
  1836. if (!Object.getPrototypeOf) {
  1837. Object.getPrototypeOf = function getPrototypeOf(object) {
  1838. return object.__proto__ || (
  1839. object.constructor ?
  1840. object.constructor.prototype :
  1841. prototypeOfObject
  1842. );
  1843. };
  1844. }
  1845. if (!Object.getOwnPropertyDescriptor) {
  1846. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  1847. "non-object: ";
  1848. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  1849. if ((typeof object != "object" && typeof object != "function") || object === null)
  1850. throw new TypeError(ERR_NON_OBJECT + object);
  1851. if (!owns(object, property))
  1852. return;
  1853. var descriptor, getter, setter;
  1854. descriptor = { enumerable: true, configurable: true };
  1855. if (supportsAccessors) {
  1856. var prototype = object.__proto__;
  1857. object.__proto__ = prototypeOfObject;
  1858. var getter = lookupGetter(object, property);
  1859. var setter = lookupSetter(object, property);
  1860. object.__proto__ = prototype;
  1861. if (getter || setter) {
  1862. if (getter) descriptor.get = getter;
  1863. if (setter) descriptor.set = setter;
  1864. return descriptor;
  1865. }
  1866. }
  1867. descriptor.value = object[property];
  1868. return descriptor;
  1869. };
  1870. }
  1871. if (!Object.getOwnPropertyNames) {
  1872. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  1873. return Object.keys(object);
  1874. };
  1875. }
  1876. if (!Object.create) {
  1877. var createEmpty;
  1878. if (Object.prototype.__proto__ === null) {
  1879. createEmpty = function () {
  1880. return { "__proto__": null };
  1881. };
  1882. } else {
  1883. createEmpty = function () {
  1884. var empty = {};
  1885. for (var i in empty)
  1886. empty[i] = null;
  1887. empty.constructor =
  1888. empty.hasOwnProperty =
  1889. empty.propertyIsEnumerable =
  1890. empty.isPrototypeOf =
  1891. empty.toLocaleString =
  1892. empty.toString =
  1893. empty.valueOf =
  1894. empty.__proto__ = null;
  1895. return empty;
  1896. }
  1897. }
  1898. Object.create = function create(prototype, properties) {
  1899. var object;
  1900. if (prototype === null) {
  1901. object = createEmpty();
  1902. } else {
  1903. if (typeof prototype != "object")
  1904. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  1905. var Type = function () {};
  1906. Type.prototype = prototype;
  1907. object = new Type();
  1908. object.__proto__ = prototype;
  1909. }
  1910. if (properties !== void 0)
  1911. Object.defineProperties(object, properties);
  1912. return object;
  1913. };
  1914. }
  1915. function doesDefinePropertyWork(object) {
  1916. try {
  1917. Object.defineProperty(object, "sentinel", {});
  1918. return "sentinel" in object;
  1919. } catch (exception) {
  1920. }
  1921. }
  1922. if (Object.defineProperty) {
  1923. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  1924. var definePropertyWorksOnDom = typeof document == "undefined" ||
  1925. doesDefinePropertyWork(document.createElement("div"));
  1926. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  1927. var definePropertyFallback = Object.defineProperty;
  1928. }
  1929. }
  1930. if (!Object.defineProperty || definePropertyFallback) {
  1931. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  1932. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  1933. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  1934. "on this javascript engine";
  1935. Object.defineProperty = function defineProperty(object, property, descriptor) {
  1936. if ((typeof object != "object" && typeof object != "function") || object === null)
  1937. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  1938. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  1939. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  1940. if (definePropertyFallback) {
  1941. try {
  1942. return definePropertyFallback.call(Object, object, property, descriptor);
  1943. } catch (exception) {
  1944. }
  1945. }
  1946. if (owns(descriptor, "value")) {
  1947. if (supportsAccessors && (lookupGetter(object, property) ||
  1948. lookupSetter(object, property)))
  1949. {
  1950. var prototype = object.__proto__;
  1951. object.__proto__ = prototypeOfObject;
  1952. delete object[property];
  1953. object[property] = descriptor.value;
  1954. object.__proto__ = prototype;
  1955. } else {
  1956. object[property] = descriptor.value;
  1957. }
  1958. } else {
  1959. if (!supportsAccessors)
  1960. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  1961. if (owns(descriptor, "get"))
  1962. defineGetter(object, property, descriptor.get);
  1963. if (owns(descriptor, "set"))
  1964. defineSetter(object, property, descriptor.set);
  1965. }
  1966. return object;
  1967. };
  1968. }
  1969. if (!Object.defineProperties) {
  1970. Object.defineProperties = function defineProperties(object, properties) {
  1971. for (var property in properties) {
  1972. if (owns(properties, property))
  1973. Object.defineProperty(object, property, properties[property]);
  1974. }
  1975. return object;
  1976. };
  1977. }
  1978. if (!Object.seal) {
  1979. Object.seal = function seal(object) {
  1980. return object;
  1981. };
  1982. }
  1983. if (!Object.freeze) {
  1984. Object.freeze = function freeze(object) {
  1985. return object;
  1986. };
  1987. }
  1988. try {
  1989. Object.freeze(function () {});
  1990. } catch (exception) {
  1991. Object.freeze = (function freeze(freezeObject) {
  1992. return function freeze(object) {
  1993. if (typeof object == "function") {
  1994. return object;
  1995. } else {
  1996. return freezeObject(object);
  1997. }
  1998. };
  1999. })(Object.freeze);
  2000. }
  2001. if (!Object.preventExtensions) {
  2002. Object.preventExtensions = function preventExtensions(object) {
  2003. return object;
  2004. };
  2005. }
  2006. if (!Object.isSealed) {
  2007. Object.isSealed = function isSealed(object) {
  2008. return false;
  2009. };
  2010. }
  2011. if (!Object.isFrozen) {
  2012. Object.isFrozen = function isFrozen(object) {
  2013. return false;
  2014. };
  2015. }
  2016. if (!Object.isExtensible) {
  2017. Object.isExtensible = function isExtensible(object) {
  2018. if (Object(object) === object) {
  2019. throw new TypeError(); // TODO message
  2020. }
  2021. var name = '';
  2022. while (owns(object, name)) {
  2023. name += '?';
  2024. }
  2025. object[name] = true;
  2026. var returnValue = owns(object, name);
  2027. delete object[name];
  2028. return returnValue;
  2029. };
  2030. }
  2031. if (!Object.keys) {
  2032. var hasDontEnumBug = true,
  2033. dontEnums = [
  2034. "toString",
  2035. "toLocaleString",
  2036. "valueOf",
  2037. "hasOwnProperty",
  2038. "isPrototypeOf",
  2039. "propertyIsEnumerable",
  2040. "constructor"
  2041. ],
  2042. dontEnumsLength = dontEnums.length;
  2043. for (var key in {"toString": null}) {
  2044. hasDontEnumBug = false;
  2045. }
  2046. Object.keys = function keys(object) {
  2047. if (
  2048. (typeof object != "object" && typeof object != "function") ||
  2049. object === null
  2050. ) {
  2051. throw new TypeError("Object.keys called on a non-object");
  2052. }
  2053. var keys = [];
  2054. for (var name in object) {
  2055. if (owns(object, name)) {
  2056. keys.push(name);
  2057. }
  2058. }
  2059. if (hasDontEnumBug) {
  2060. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  2061. var dontEnum = dontEnums[i];
  2062. if (owns(object, dontEnum)) {
  2063. keys.push(dontEnum);
  2064. }
  2065. }
  2066. }
  2067. return keys;
  2068. };
  2069. }
  2070. if (!Date.now) {
  2071. Date.now = function now() {
  2072. return new Date().getTime();
  2073. };
  2074. }
  2075. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  2076. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  2077. "\u2029\uFEFF";
  2078. if (!String.prototype.trim || ws.trim()) {
  2079. ws = "[" + ws + "]";
  2080. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  2081. trimEndRegexp = new RegExp(ws + ws + "*$");
  2082. String.prototype.trim = function trim() {
  2083. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  2084. };
  2085. }
  2086. function toInteger(n) {
  2087. n = +n;
  2088. if (n !== n) { // isNaN
  2089. n = 0;
  2090. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  2091. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  2092. }
  2093. return n;
  2094. }
  2095. function isPrimitive(input) {
  2096. var type = typeof input;
  2097. return (
  2098. input === null ||
  2099. type === "undefined" ||
  2100. type === "boolean" ||
  2101. type === "number" ||
  2102. type === "string"
  2103. );
  2104. }
  2105. function toPrimitive(input) {
  2106. var val, valueOf, toString;
  2107. if (isPrimitive(input)) {
  2108. return input;
  2109. }
  2110. valueOf = input.valueOf;
  2111. if (typeof valueOf === "function") {
  2112. val = valueOf.call(input);
  2113. if (isPrimitive(val)) {
  2114. return val;
  2115. }
  2116. }
  2117. toString = input.toString;
  2118. if (typeof toString === "function") {
  2119. val = toString.call(input);
  2120. if (isPrimitive(val)) {
  2121. return val;
  2122. }
  2123. }
  2124. throw new TypeError();
  2125. }
  2126. var toObject = function (o) {
  2127. if (o == null) { // this matches both null and undefined
  2128. throw new TypeError("can't convert "+o+" to object");
  2129. }
  2130. return Object(o);
  2131. };
  2132. });