worker-json.js 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397
  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",[], 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",[], 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",[], 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",[], 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",[], 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",[], 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. }
  972. else {
  973. applyDelta(this.$lines, delta, doNotValidate);
  974. this._signal("change", delta);
  975. }
  976. };
  977. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  978. var lines = delta.lines;
  979. var l = lines.length - MAX + 1;
  980. var row = delta.start.row;
  981. var column = delta.start.column;
  982. for (var from = 0, to = 0; from < l; from = to) {
  983. to += MAX - 1;
  984. var chunk = lines.slice(from, to);
  985. chunk.push("");
  986. this.applyDelta({
  987. start: this.pos(row + from, column),
  988. end: this.pos(row + to, column = 0),
  989. action: delta.action,
  990. lines: chunk
  991. }, true);
  992. }
  993. delta.lines = lines.slice(from);
  994. delta.start.row = row + from;
  995. delta.start.column = column;
  996. this.applyDelta(delta, true);
  997. };
  998. this.revertDelta = function(delta) {
  999. this.applyDelta({
  1000. start: this.clonePos(delta.start),
  1001. end: this.clonePos(delta.end),
  1002. action: (delta.action == "insert" ? "remove" : "insert"),
  1003. lines: delta.lines.slice()
  1004. });
  1005. };
  1006. this.indexToPosition = function(index, startRow) {
  1007. var lines = this.$lines || this.getAllLines();
  1008. var newlineLength = this.getNewLineCharacter().length;
  1009. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1010. index -= lines[i].length + newlineLength;
  1011. if (index < 0)
  1012. return {row: i, column: index + lines[i].length + newlineLength};
  1013. }
  1014. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  1015. };
  1016. this.positionToIndex = function(pos, startRow) {
  1017. var lines = this.$lines || this.getAllLines();
  1018. var newlineLength = this.getNewLineCharacter().length;
  1019. var index = 0;
  1020. var row = Math.min(pos.row, lines.length);
  1021. for (var i = startRow || 0; i < row; ++i)
  1022. index += lines[i].length + newlineLength;
  1023. return index + pos.column;
  1024. };
  1025. }).call(Document.prototype);
  1026. exports.Document = Document;
  1027. });
  1028. ace.define("ace/lib/lang",[], function(require, exports, module) {
  1029. "use strict";
  1030. exports.last = function(a) {
  1031. return a[a.length - 1];
  1032. };
  1033. exports.stringReverse = function(string) {
  1034. return string.split("").reverse().join("");
  1035. };
  1036. exports.stringRepeat = function (string, count) {
  1037. var result = '';
  1038. while (count > 0) {
  1039. if (count & 1)
  1040. result += string;
  1041. if (count >>= 1)
  1042. string += string;
  1043. }
  1044. return result;
  1045. };
  1046. var trimBeginRegexp = /^\s\s*/;
  1047. var trimEndRegexp = /\s\s*$/;
  1048. exports.stringTrimLeft = function (string) {
  1049. return string.replace(trimBeginRegexp, '');
  1050. };
  1051. exports.stringTrimRight = function (string) {
  1052. return string.replace(trimEndRegexp, '');
  1053. };
  1054. exports.copyObject = function(obj) {
  1055. var copy = {};
  1056. for (var key in obj) {
  1057. copy[key] = obj[key];
  1058. }
  1059. return copy;
  1060. };
  1061. exports.copyArray = function(array){
  1062. var copy = [];
  1063. for (var i=0, l=array.length; i<l; i++) {
  1064. if (array[i] && typeof array[i] == "object")
  1065. copy[i] = this.copyObject(array[i]);
  1066. else
  1067. copy[i] = array[i];
  1068. }
  1069. return copy;
  1070. };
  1071. exports.deepCopy = function deepCopy(obj) {
  1072. if (typeof obj !== "object" || !obj)
  1073. return obj;
  1074. var copy;
  1075. if (Array.isArray(obj)) {
  1076. copy = [];
  1077. for (var key = 0; key < obj.length; key++) {
  1078. copy[key] = deepCopy(obj[key]);
  1079. }
  1080. return copy;
  1081. }
  1082. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1083. return obj;
  1084. copy = {};
  1085. for (var key in obj)
  1086. copy[key] = deepCopy(obj[key]);
  1087. return copy;
  1088. };
  1089. exports.arrayToMap = function(arr) {
  1090. var map = {};
  1091. for (var i=0; i<arr.length; i++) {
  1092. map[arr[i]] = 1;
  1093. }
  1094. return map;
  1095. };
  1096. exports.createMap = function(props) {
  1097. var map = Object.create(null);
  1098. for (var i in props) {
  1099. map[i] = props[i];
  1100. }
  1101. return map;
  1102. };
  1103. exports.arrayRemove = function(array, value) {
  1104. for (var i = 0; i <= array.length; i++) {
  1105. if (value === array[i]) {
  1106. array.splice(i, 1);
  1107. }
  1108. }
  1109. };
  1110. exports.escapeRegExp = function(str) {
  1111. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1112. };
  1113. exports.escapeHTML = function(str) {
  1114. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1115. };
  1116. exports.getMatchOffsets = function(string, regExp) {
  1117. var matches = [];
  1118. string.replace(regExp, function(str) {
  1119. matches.push({
  1120. offset: arguments[arguments.length-2],
  1121. length: str.length
  1122. });
  1123. });
  1124. return matches;
  1125. };
  1126. exports.deferredCall = function(fcn) {
  1127. var timer = null;
  1128. var callback = function() {
  1129. timer = null;
  1130. fcn();
  1131. };
  1132. var deferred = function(timeout) {
  1133. deferred.cancel();
  1134. timer = setTimeout(callback, timeout || 0);
  1135. return deferred;
  1136. };
  1137. deferred.schedule = deferred;
  1138. deferred.call = function() {
  1139. this.cancel();
  1140. fcn();
  1141. return deferred;
  1142. };
  1143. deferred.cancel = function() {
  1144. clearTimeout(timer);
  1145. timer = null;
  1146. return deferred;
  1147. };
  1148. deferred.isPending = function() {
  1149. return timer;
  1150. };
  1151. return deferred;
  1152. };
  1153. exports.delayedCall = function(fcn, defaultTimeout) {
  1154. var timer = null;
  1155. var callback = function() {
  1156. timer = null;
  1157. fcn();
  1158. };
  1159. var _self = function(timeout) {
  1160. if (timer == null)
  1161. timer = setTimeout(callback, timeout || defaultTimeout);
  1162. };
  1163. _self.delay = function(timeout) {
  1164. timer && clearTimeout(timer);
  1165. timer = setTimeout(callback, timeout || defaultTimeout);
  1166. };
  1167. _self.schedule = _self;
  1168. _self.call = function() {
  1169. this.cancel();
  1170. fcn();
  1171. };
  1172. _self.cancel = function() {
  1173. timer && clearTimeout(timer);
  1174. timer = null;
  1175. };
  1176. _self.isPending = function() {
  1177. return timer;
  1178. };
  1179. return _self;
  1180. };
  1181. });
  1182. ace.define("ace/worker/mirror",[], function(require, exports, module) {
  1183. "use strict";
  1184. var Range = require("../range").Range;
  1185. var Document = require("../document").Document;
  1186. var lang = require("../lib/lang");
  1187. var Mirror = exports.Mirror = function(sender) {
  1188. this.sender = sender;
  1189. var doc = this.doc = new Document("");
  1190. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1191. var _self = this;
  1192. sender.on("change", function(e) {
  1193. var data = e.data;
  1194. if (data[0].start) {
  1195. doc.applyDeltas(data);
  1196. } else {
  1197. for (var i = 0; i < data.length; i += 2) {
  1198. if (Array.isArray(data[i+1])) {
  1199. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1200. } else {
  1201. var d = {action: "remove", start: data[i], end: data[i+1]};
  1202. }
  1203. doc.applyDelta(d, true);
  1204. }
  1205. }
  1206. if (_self.$timeout)
  1207. return deferredUpdate.schedule(_self.$timeout);
  1208. _self.onUpdate();
  1209. });
  1210. };
  1211. (function() {
  1212. this.$timeout = 500;
  1213. this.setTimeout = function(timeout) {
  1214. this.$timeout = timeout;
  1215. };
  1216. this.setValue = function(value) {
  1217. this.doc.setValue(value);
  1218. this.deferredUpdate.schedule(this.$timeout);
  1219. };
  1220. this.getValue = function(callbackId) {
  1221. this.sender.callback(this.doc.getValue(), callbackId);
  1222. };
  1223. this.onUpdate = function() {
  1224. };
  1225. this.isPending = function() {
  1226. return this.deferredUpdate.isPending();
  1227. };
  1228. }).call(Mirror.prototype);
  1229. });
  1230. ace.define("ace/mode/json/json_parse",[], function(require, exports, module) {
  1231. "use strict";
  1232. var at, // The index of the current character
  1233. ch, // The current character
  1234. escapee = {
  1235. '"': '"',
  1236. '\\': '\\',
  1237. '/': '/',
  1238. b: '\b',
  1239. f: '\f',
  1240. n: '\n',
  1241. r: '\r',
  1242. t: '\t'
  1243. },
  1244. text,
  1245. error = function (m) {
  1246. throw {
  1247. name: 'SyntaxError',
  1248. message: m,
  1249. at: at,
  1250. text: text
  1251. };
  1252. },
  1253. next = function (c) {
  1254. if (c && c !== ch) {
  1255. error("Expected '" + c + "' instead of '" + ch + "'");
  1256. }
  1257. ch = text.charAt(at);
  1258. at += 1;
  1259. return ch;
  1260. },
  1261. number = function () {
  1262. var number,
  1263. string = '';
  1264. if (ch === '-') {
  1265. string = '-';
  1266. next('-');
  1267. }
  1268. while (ch >= '0' && ch <= '9') {
  1269. string += ch;
  1270. next();
  1271. }
  1272. if (ch === '.') {
  1273. string += '.';
  1274. while (next() && ch >= '0' && ch <= '9') {
  1275. string += ch;
  1276. }
  1277. }
  1278. if (ch === 'e' || ch === 'E') {
  1279. string += ch;
  1280. next();
  1281. if (ch === '-' || ch === '+') {
  1282. string += ch;
  1283. next();
  1284. }
  1285. while (ch >= '0' && ch <= '9') {
  1286. string += ch;
  1287. next();
  1288. }
  1289. }
  1290. number = +string;
  1291. if (isNaN(number)) {
  1292. error("Bad number");
  1293. } else {
  1294. return number;
  1295. }
  1296. },
  1297. string = function () {
  1298. var hex,
  1299. i,
  1300. string = '',
  1301. uffff;
  1302. if (ch === '"') {
  1303. while (next()) {
  1304. if (ch === '"') {
  1305. next();
  1306. return string;
  1307. } else if (ch === '\\') {
  1308. next();
  1309. if (ch === 'u') {
  1310. uffff = 0;
  1311. for (i = 0; i < 4; i += 1) {
  1312. hex = parseInt(next(), 16);
  1313. if (!isFinite(hex)) {
  1314. break;
  1315. }
  1316. uffff = uffff * 16 + hex;
  1317. }
  1318. string += String.fromCharCode(uffff);
  1319. } else if (typeof escapee[ch] === 'string') {
  1320. string += escapee[ch];
  1321. } else {
  1322. break;
  1323. }
  1324. } else if (ch == "\n" || ch == "\r") {
  1325. break;
  1326. } else {
  1327. string += ch;
  1328. }
  1329. }
  1330. }
  1331. error("Bad string");
  1332. },
  1333. white = function () {
  1334. while (ch && ch <= ' ') {
  1335. next();
  1336. }
  1337. },
  1338. word = function () {
  1339. switch (ch) {
  1340. case 't':
  1341. next('t');
  1342. next('r');
  1343. next('u');
  1344. next('e');
  1345. return true;
  1346. case 'f':
  1347. next('f');
  1348. next('a');
  1349. next('l');
  1350. next('s');
  1351. next('e');
  1352. return false;
  1353. case 'n':
  1354. next('n');
  1355. next('u');
  1356. next('l');
  1357. next('l');
  1358. return null;
  1359. }
  1360. error("Unexpected '" + ch + "'");
  1361. },
  1362. value, // Place holder for the value function.
  1363. array = function () {
  1364. var array = [];
  1365. if (ch === '[') {
  1366. next('[');
  1367. white();
  1368. if (ch === ']') {
  1369. next(']');
  1370. return array; // empty array
  1371. }
  1372. while (ch) {
  1373. array.push(value());
  1374. white();
  1375. if (ch === ']') {
  1376. next(']');
  1377. return array;
  1378. }
  1379. next(',');
  1380. white();
  1381. }
  1382. }
  1383. error("Bad array");
  1384. },
  1385. object = function () {
  1386. var key,
  1387. object = {};
  1388. if (ch === '{') {
  1389. next('{');
  1390. white();
  1391. if (ch === '}') {
  1392. next('}');
  1393. return object; // empty object
  1394. }
  1395. while (ch) {
  1396. key = string();
  1397. white();
  1398. next(':');
  1399. if (Object.hasOwnProperty.call(object, key)) {
  1400. error('Duplicate key "' + key + '"');
  1401. }
  1402. object[key] = value();
  1403. white();
  1404. if (ch === '}') {
  1405. next('}');
  1406. return object;
  1407. }
  1408. next(',');
  1409. white();
  1410. }
  1411. }
  1412. error("Bad object");
  1413. };
  1414. value = function () {
  1415. white();
  1416. switch (ch) {
  1417. case '{':
  1418. return object();
  1419. case '[':
  1420. return array();
  1421. case '"':
  1422. return string();
  1423. case '-':
  1424. return number();
  1425. default:
  1426. return ch >= '0' && ch <= '9' ? number() : word();
  1427. }
  1428. };
  1429. return function (source, reviver) {
  1430. var result;
  1431. text = source;
  1432. at = 0;
  1433. ch = ' ';
  1434. result = value();
  1435. white();
  1436. if (ch) {
  1437. error("Syntax error");
  1438. }
  1439. return typeof reviver === 'function' ? function walk(holder, key) {
  1440. var k, v, value = holder[key];
  1441. if (value && typeof value === 'object') {
  1442. for (k in value) {
  1443. if (Object.hasOwnProperty.call(value, k)) {
  1444. v = walk(value, k);
  1445. if (v !== undefined) {
  1446. value[k] = v;
  1447. } else {
  1448. delete value[k];
  1449. }
  1450. }
  1451. }
  1452. }
  1453. return reviver.call(holder, key, value);
  1454. }({'': result}, '') : result;
  1455. };
  1456. });
  1457. ace.define("ace/mode/json_worker",[], function(require, exports, module) {
  1458. "use strict";
  1459. var oop = require("../lib/oop");
  1460. var Mirror = require("../worker/mirror").Mirror;
  1461. var parse = require("./json/json_parse");
  1462. var JsonWorker = exports.JsonWorker = function(sender) {
  1463. Mirror.call(this, sender);
  1464. this.setTimeout(200);
  1465. };
  1466. oop.inherits(JsonWorker, Mirror);
  1467. (function() {
  1468. this.onUpdate = function() {
  1469. var value = this.doc.getValue();
  1470. var errors = [];
  1471. try {
  1472. if (value)
  1473. parse(value);
  1474. } catch (e) {
  1475. var pos = this.doc.indexToPosition(e.at-1);
  1476. errors.push({
  1477. row: pos.row,
  1478. column: pos.column,
  1479. text: e.message,
  1480. type: "error"
  1481. });
  1482. }
  1483. this.sender.emit("annotate", errors);
  1484. };
  1485. }).call(JsonWorker.prototype);
  1486. });
  1487. ace.define("ace/lib/es5-shim",[], function(require, exports, module) {
  1488. //
  1489. //
  1490. function Empty() {}
  1491. if (!Function.prototype.bind) {
  1492. Function.prototype.bind = function bind(that) { // .length is 1
  1493. var target = this;
  1494. if (typeof target != "function") {
  1495. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  1496. }
  1497. var args = slice.call(arguments, 1); // for normal call
  1498. var bound = function () {
  1499. if (this instanceof bound) {
  1500. var result = target.apply(
  1501. this,
  1502. args.concat(slice.call(arguments))
  1503. );
  1504. if (Object(result) === result) {
  1505. return result;
  1506. }
  1507. return this;
  1508. } else {
  1509. return target.apply(
  1510. that,
  1511. args.concat(slice.call(arguments))
  1512. );
  1513. }
  1514. };
  1515. if(target.prototype) {
  1516. Empty.prototype = target.prototype;
  1517. bound.prototype = new Empty();
  1518. Empty.prototype = null;
  1519. }
  1520. //
  1521. return bound;
  1522. };
  1523. }
  1524. var call = Function.prototype.call;
  1525. var prototypeOfArray = Array.prototype;
  1526. var prototypeOfObject = Object.prototype;
  1527. var slice = prototypeOfArray.slice;
  1528. var _toString = call.bind(prototypeOfObject.toString);
  1529. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  1530. var defineGetter;
  1531. var defineSetter;
  1532. var lookupGetter;
  1533. var lookupSetter;
  1534. var supportsAccessors;
  1535. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  1536. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  1537. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  1538. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  1539. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  1540. }
  1541. //
  1542. //
  1543. if ([1,2].splice(0).length != 2) {
  1544. if(function() { // test IE < 9 to splice bug - see issue #138
  1545. function makeArray(l) {
  1546. var a = new Array(l+2);
  1547. a[0] = a[1] = 0;
  1548. return a;
  1549. }
  1550. var array = [], lengthBefore;
  1551. array.splice.apply(array, makeArray(20));
  1552. array.splice.apply(array, makeArray(26));
  1553. lengthBefore = array.length; //46
  1554. array.splice(5, 0, "XXX"); // add one element
  1555. lengthBefore + 1 == array.length
  1556. if (lengthBefore + 1 == array.length) {
  1557. return true;// has right splice implementation without bugs
  1558. }
  1559. }()) {//IE 6/7
  1560. var array_splice = Array.prototype.splice;
  1561. Array.prototype.splice = function(start, deleteCount) {
  1562. if (!arguments.length) {
  1563. return [];
  1564. } else {
  1565. return array_splice.apply(this, [
  1566. start === void 0 ? 0 : start,
  1567. deleteCount === void 0 ? (this.length - start) : deleteCount
  1568. ].concat(slice.call(arguments, 2)))
  1569. }
  1570. };
  1571. } else {//IE8
  1572. Array.prototype.splice = function(pos, removeCount){
  1573. var length = this.length;
  1574. if (pos > 0) {
  1575. if (pos > length)
  1576. pos = length;
  1577. } else if (pos == void 0) {
  1578. pos = 0;
  1579. } else if (pos < 0) {
  1580. pos = Math.max(length + pos, 0);
  1581. }
  1582. if (!(pos+removeCount < length))
  1583. removeCount = length - pos;
  1584. var removed = this.slice(pos, pos+removeCount);
  1585. var insert = slice.call(arguments, 2);
  1586. var add = insert.length;
  1587. if (pos === length) {
  1588. if (add) {
  1589. this.push.apply(this, insert);
  1590. }
  1591. } else {
  1592. var remove = Math.min(removeCount, length - pos);
  1593. var tailOldPos = pos + remove;
  1594. var tailNewPos = tailOldPos + add - remove;
  1595. var tailCount = length - tailOldPos;
  1596. var lengthAfterRemove = length - remove;
  1597. if (tailNewPos < tailOldPos) { // case A
  1598. for (var i = 0; i < tailCount; ++i) {
  1599. this[tailNewPos+i] = this[tailOldPos+i];
  1600. }
  1601. } else if (tailNewPos > tailOldPos) { // case B
  1602. for (i = tailCount; i--; ) {
  1603. this[tailNewPos+i] = this[tailOldPos+i];
  1604. }
  1605. } // else, add == remove (nothing to do)
  1606. if (add && pos === lengthAfterRemove) {
  1607. this.length = lengthAfterRemove; // truncate array
  1608. this.push.apply(this, insert);
  1609. } else {
  1610. this.length = lengthAfterRemove + add; // reserves space
  1611. for (i = 0; i < add; ++i) {
  1612. this[pos+i] = insert[i];
  1613. }
  1614. }
  1615. }
  1616. return removed;
  1617. };
  1618. }
  1619. }
  1620. if (!Array.isArray) {
  1621. Array.isArray = function isArray(obj) {
  1622. return _toString(obj) == "[object Array]";
  1623. };
  1624. }
  1625. var boxedString = Object("a"),
  1626. splitString = boxedString[0] != "a" || !(0 in boxedString);
  1627. if (!Array.prototype.forEach) {
  1628. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  1629. var object = toObject(this),
  1630. self = splitString && _toString(this) == "[object String]" ?
  1631. this.split("") :
  1632. object,
  1633. thisp = arguments[1],
  1634. i = -1,
  1635. length = self.length >>> 0;
  1636. if (_toString(fun) != "[object Function]") {
  1637. throw new TypeError(); // TODO message
  1638. }
  1639. while (++i < length) {
  1640. if (i in self) {
  1641. fun.call(thisp, self[i], i, object);
  1642. }
  1643. }
  1644. };
  1645. }
  1646. if (!Array.prototype.map) {
  1647. Array.prototype.map = function map(fun /*, thisp*/) {
  1648. var object = toObject(this),
  1649. self = splitString && _toString(this) == "[object String]" ?
  1650. this.split("") :
  1651. object,
  1652. length = self.length >>> 0,
  1653. result = Array(length),
  1654. thisp = arguments[1];
  1655. if (_toString(fun) != "[object Function]") {
  1656. throw new TypeError(fun + " is not a function");
  1657. }
  1658. for (var i = 0; i < length; i++) {
  1659. if (i in self)
  1660. result[i] = fun.call(thisp, self[i], i, object);
  1661. }
  1662. return result;
  1663. };
  1664. }
  1665. if (!Array.prototype.filter) {
  1666. Array.prototype.filter = function filter(fun /*, thisp */) {
  1667. var object = toObject(this),
  1668. self = splitString && _toString(this) == "[object String]" ?
  1669. this.split("") :
  1670. object,
  1671. length = self.length >>> 0,
  1672. result = [],
  1673. value,
  1674. thisp = arguments[1];
  1675. if (_toString(fun) != "[object Function]") {
  1676. throw new TypeError(fun + " is not a function");
  1677. }
  1678. for (var i = 0; i < length; i++) {
  1679. if (i in self) {
  1680. value = self[i];
  1681. if (fun.call(thisp, value, i, object)) {
  1682. result.push(value);
  1683. }
  1684. }
  1685. }
  1686. return result;
  1687. };
  1688. }
  1689. if (!Array.prototype.every) {
  1690. Array.prototype.every = function every(fun /*, thisp */) {
  1691. var object = toObject(this),
  1692. self = splitString && _toString(this) == "[object String]" ?
  1693. this.split("") :
  1694. object,
  1695. length = self.length >>> 0,
  1696. thisp = arguments[1];
  1697. if (_toString(fun) != "[object Function]") {
  1698. throw new TypeError(fun + " is not a function");
  1699. }
  1700. for (var i = 0; i < length; i++) {
  1701. if (i in self && !fun.call(thisp, self[i], i, object)) {
  1702. return false;
  1703. }
  1704. }
  1705. return true;
  1706. };
  1707. }
  1708. if (!Array.prototype.some) {
  1709. Array.prototype.some = function some(fun /*, thisp */) {
  1710. var object = toObject(this),
  1711. self = splitString && _toString(this) == "[object String]" ?
  1712. this.split("") :
  1713. object,
  1714. length = self.length >>> 0,
  1715. thisp = arguments[1];
  1716. if (_toString(fun) != "[object Function]") {
  1717. throw new TypeError(fun + " is not a function");
  1718. }
  1719. for (var i = 0; i < length; i++) {
  1720. if (i in self && fun.call(thisp, self[i], i, object)) {
  1721. return true;
  1722. }
  1723. }
  1724. return false;
  1725. };
  1726. }
  1727. if (!Array.prototype.reduce) {
  1728. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  1729. var object = toObject(this),
  1730. self = splitString && _toString(this) == "[object String]" ?
  1731. this.split("") :
  1732. object,
  1733. length = self.length >>> 0;
  1734. if (_toString(fun) != "[object Function]") {
  1735. throw new TypeError(fun + " is not a function");
  1736. }
  1737. if (!length && arguments.length == 1) {
  1738. throw new TypeError("reduce of empty array with no initial value");
  1739. }
  1740. var i = 0;
  1741. var result;
  1742. if (arguments.length >= 2) {
  1743. result = arguments[1];
  1744. } else {
  1745. do {
  1746. if (i in self) {
  1747. result = self[i++];
  1748. break;
  1749. }
  1750. if (++i >= length) {
  1751. throw new TypeError("reduce of empty array with no initial value");
  1752. }
  1753. } while (true);
  1754. }
  1755. for (; i < length; i++) {
  1756. if (i in self) {
  1757. result = fun.call(void 0, result, self[i], i, object);
  1758. }
  1759. }
  1760. return result;
  1761. };
  1762. }
  1763. if (!Array.prototype.reduceRight) {
  1764. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  1765. var object = toObject(this),
  1766. self = splitString && _toString(this) == "[object String]" ?
  1767. this.split("") :
  1768. object,
  1769. length = self.length >>> 0;
  1770. if (_toString(fun) != "[object Function]") {
  1771. throw new TypeError(fun + " is not a function");
  1772. }
  1773. if (!length && arguments.length == 1) {
  1774. throw new TypeError("reduceRight of empty array with no initial value");
  1775. }
  1776. var result, i = length - 1;
  1777. if (arguments.length >= 2) {
  1778. result = arguments[1];
  1779. } else {
  1780. do {
  1781. if (i in self) {
  1782. result = self[i--];
  1783. break;
  1784. }
  1785. if (--i < 0) {
  1786. throw new TypeError("reduceRight of empty array with no initial value");
  1787. }
  1788. } while (true);
  1789. }
  1790. do {
  1791. if (i in this) {
  1792. result = fun.call(void 0, result, self[i], i, object);
  1793. }
  1794. } while (i--);
  1795. return result;
  1796. };
  1797. }
  1798. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  1799. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  1800. var self = splitString && _toString(this) == "[object String]" ?
  1801. this.split("") :
  1802. toObject(this),
  1803. length = self.length >>> 0;
  1804. if (!length) {
  1805. return -1;
  1806. }
  1807. var i = 0;
  1808. if (arguments.length > 1) {
  1809. i = toInteger(arguments[1]);
  1810. }
  1811. i = i >= 0 ? i : Math.max(0, length + i);
  1812. for (; i < length; i++) {
  1813. if (i in self && self[i] === sought) {
  1814. return i;
  1815. }
  1816. }
  1817. return -1;
  1818. };
  1819. }
  1820. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  1821. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  1822. var self = splitString && _toString(this) == "[object String]" ?
  1823. this.split("") :
  1824. toObject(this),
  1825. length = self.length >>> 0;
  1826. if (!length) {
  1827. return -1;
  1828. }
  1829. var i = length - 1;
  1830. if (arguments.length > 1) {
  1831. i = Math.min(i, toInteger(arguments[1]));
  1832. }
  1833. i = i >= 0 ? i : length - Math.abs(i);
  1834. for (; i >= 0; i--) {
  1835. if (i in self && sought === self[i]) {
  1836. return i;
  1837. }
  1838. }
  1839. return -1;
  1840. };
  1841. }
  1842. //
  1843. //
  1844. if (!Object.getPrototypeOf) {
  1845. Object.getPrototypeOf = function getPrototypeOf(object) {
  1846. return object.__proto__ || (
  1847. object.constructor ?
  1848. object.constructor.prototype :
  1849. prototypeOfObject
  1850. );
  1851. };
  1852. }
  1853. if (!Object.getOwnPropertyDescriptor) {
  1854. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  1855. "non-object: ";
  1856. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  1857. if ((typeof object != "object" && typeof object != "function") || object === null)
  1858. throw new TypeError(ERR_NON_OBJECT + object);
  1859. if (!owns(object, property))
  1860. return;
  1861. var descriptor, getter, setter;
  1862. descriptor = { enumerable: true, configurable: true };
  1863. if (supportsAccessors) {
  1864. var prototype = object.__proto__;
  1865. object.__proto__ = prototypeOfObject;
  1866. var getter = lookupGetter(object, property);
  1867. var setter = lookupSetter(object, property);
  1868. object.__proto__ = prototype;
  1869. if (getter || setter) {
  1870. if (getter) descriptor.get = getter;
  1871. if (setter) descriptor.set = setter;
  1872. return descriptor;
  1873. }
  1874. }
  1875. descriptor.value = object[property];
  1876. return descriptor;
  1877. };
  1878. }
  1879. if (!Object.getOwnPropertyNames) {
  1880. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  1881. return Object.keys(object);
  1882. };
  1883. }
  1884. if (!Object.create) {
  1885. var createEmpty;
  1886. if (Object.prototype.__proto__ === null) {
  1887. createEmpty = function () {
  1888. return { "__proto__": null };
  1889. };
  1890. } else {
  1891. createEmpty = function () {
  1892. var empty = {};
  1893. for (var i in empty)
  1894. empty[i] = null;
  1895. empty.constructor =
  1896. empty.hasOwnProperty =
  1897. empty.propertyIsEnumerable =
  1898. empty.isPrototypeOf =
  1899. empty.toLocaleString =
  1900. empty.toString =
  1901. empty.valueOf =
  1902. empty.__proto__ = null;
  1903. return empty;
  1904. }
  1905. }
  1906. Object.create = function create(prototype, properties) {
  1907. var object;
  1908. if (prototype === null) {
  1909. object = createEmpty();
  1910. } else {
  1911. if (typeof prototype != "object")
  1912. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  1913. var Type = function () {};
  1914. Type.prototype = prototype;
  1915. object = new Type();
  1916. object.__proto__ = prototype;
  1917. }
  1918. if (properties !== void 0)
  1919. Object.defineProperties(object, properties);
  1920. return object;
  1921. };
  1922. }
  1923. function doesDefinePropertyWork(object) {
  1924. try {
  1925. Object.defineProperty(object, "sentinel", {});
  1926. return "sentinel" in object;
  1927. } catch (exception) {
  1928. }
  1929. }
  1930. if (Object.defineProperty) {
  1931. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  1932. var definePropertyWorksOnDom = typeof document == "undefined" ||
  1933. doesDefinePropertyWork(document.createElement("div"));
  1934. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  1935. var definePropertyFallback = Object.defineProperty;
  1936. }
  1937. }
  1938. if (!Object.defineProperty || definePropertyFallback) {
  1939. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  1940. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  1941. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  1942. "on this javascript engine";
  1943. Object.defineProperty = function defineProperty(object, property, descriptor) {
  1944. if ((typeof object != "object" && typeof object != "function") || object === null)
  1945. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  1946. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  1947. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  1948. if (definePropertyFallback) {
  1949. try {
  1950. return definePropertyFallback.call(Object, object, property, descriptor);
  1951. } catch (exception) {
  1952. }
  1953. }
  1954. if (owns(descriptor, "value")) {
  1955. if (supportsAccessors && (lookupGetter(object, property) ||
  1956. lookupSetter(object, property)))
  1957. {
  1958. var prototype = object.__proto__;
  1959. object.__proto__ = prototypeOfObject;
  1960. delete object[property];
  1961. object[property] = descriptor.value;
  1962. object.__proto__ = prototype;
  1963. } else {
  1964. object[property] = descriptor.value;
  1965. }
  1966. } else {
  1967. if (!supportsAccessors)
  1968. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  1969. if (owns(descriptor, "get"))
  1970. defineGetter(object, property, descriptor.get);
  1971. if (owns(descriptor, "set"))
  1972. defineSetter(object, property, descriptor.set);
  1973. }
  1974. return object;
  1975. };
  1976. }
  1977. if (!Object.defineProperties) {
  1978. Object.defineProperties = function defineProperties(object, properties) {
  1979. for (var property in properties) {
  1980. if (owns(properties, property))
  1981. Object.defineProperty(object, property, properties[property]);
  1982. }
  1983. return object;
  1984. };
  1985. }
  1986. if (!Object.seal) {
  1987. Object.seal = function seal(object) {
  1988. return object;
  1989. };
  1990. }
  1991. if (!Object.freeze) {
  1992. Object.freeze = function freeze(object) {
  1993. return object;
  1994. };
  1995. }
  1996. try {
  1997. Object.freeze(function () {});
  1998. } catch (exception) {
  1999. Object.freeze = (function freeze(freezeObject) {
  2000. return function freeze(object) {
  2001. if (typeof object == "function") {
  2002. return object;
  2003. } else {
  2004. return freezeObject(object);
  2005. }
  2006. };
  2007. })(Object.freeze);
  2008. }
  2009. if (!Object.preventExtensions) {
  2010. Object.preventExtensions = function preventExtensions(object) {
  2011. return object;
  2012. };
  2013. }
  2014. if (!Object.isSealed) {
  2015. Object.isSealed = function isSealed(object) {
  2016. return false;
  2017. };
  2018. }
  2019. if (!Object.isFrozen) {
  2020. Object.isFrozen = function isFrozen(object) {
  2021. return false;
  2022. };
  2023. }
  2024. if (!Object.isExtensible) {
  2025. Object.isExtensible = function isExtensible(object) {
  2026. if (Object(object) === object) {
  2027. throw new TypeError(); // TODO message
  2028. }
  2029. var name = '';
  2030. while (owns(object, name)) {
  2031. name += '?';
  2032. }
  2033. object[name] = true;
  2034. var returnValue = owns(object, name);
  2035. delete object[name];
  2036. return returnValue;
  2037. };
  2038. }
  2039. if (!Object.keys) {
  2040. var hasDontEnumBug = true,
  2041. dontEnums = [
  2042. "toString",
  2043. "toLocaleString",
  2044. "valueOf",
  2045. "hasOwnProperty",
  2046. "isPrototypeOf",
  2047. "propertyIsEnumerable",
  2048. "constructor"
  2049. ],
  2050. dontEnumsLength = dontEnums.length;
  2051. for (var key in {"toString": null}) {
  2052. hasDontEnumBug = false;
  2053. }
  2054. Object.keys = function keys(object) {
  2055. if (
  2056. (typeof object != "object" && typeof object != "function") ||
  2057. object === null
  2058. ) {
  2059. throw new TypeError("Object.keys called on a non-object");
  2060. }
  2061. var keys = [];
  2062. for (var name in object) {
  2063. if (owns(object, name)) {
  2064. keys.push(name);
  2065. }
  2066. }
  2067. if (hasDontEnumBug) {
  2068. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  2069. var dontEnum = dontEnums[i];
  2070. if (owns(object, dontEnum)) {
  2071. keys.push(dontEnum);
  2072. }
  2073. }
  2074. }
  2075. return keys;
  2076. };
  2077. }
  2078. //
  2079. //
  2080. if (!Date.now) {
  2081. Date.now = function now() {
  2082. return new Date().getTime();
  2083. };
  2084. }
  2085. //
  2086. //
  2087. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  2088. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  2089. "\u2029\uFEFF";
  2090. if (!String.prototype.trim || ws.trim()) {
  2091. ws = "[" + ws + "]";
  2092. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  2093. trimEndRegexp = new RegExp(ws + ws + "*$");
  2094. String.prototype.trim = function trim() {
  2095. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  2096. };
  2097. }
  2098. //
  2099. //
  2100. function toInteger(n) {
  2101. n = +n;
  2102. if (n !== n) { // isNaN
  2103. n = 0;
  2104. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  2105. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  2106. }
  2107. return n;
  2108. }
  2109. function isPrimitive(input) {
  2110. var type = typeof input;
  2111. return (
  2112. input === null ||
  2113. type === "undefined" ||
  2114. type === "boolean" ||
  2115. type === "number" ||
  2116. type === "string"
  2117. );
  2118. }
  2119. function toPrimitive(input) {
  2120. var val, valueOf, toString;
  2121. if (isPrimitive(input)) {
  2122. return input;
  2123. }
  2124. valueOf = input.valueOf;
  2125. if (typeof valueOf === "function") {
  2126. val = valueOf.call(input);
  2127. if (isPrimitive(val)) {
  2128. return val;
  2129. }
  2130. }
  2131. toString = input.toString;
  2132. if (typeof toString === "function") {
  2133. val = toString.call(input);
  2134. if (isPrimitive(val)) {
  2135. return val;
  2136. }
  2137. }
  2138. throw new TypeError();
  2139. }
  2140. var toObject = function (o) {
  2141. if (o == null) { // this matches both null and undefined
  2142. throw new TypeError("can't convert "+o+" to object");
  2143. }
  2144. return Object(o);
  2145. };
  2146. });