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. window.console = function() {
  8. var msgs = Array.prototype.slice.call(arguments, 0);
  9. postMessage({type: "log", data: msgs});
  10. };
  11. window.console.error =
  12. window.console.warn =
  13. window.console.log =
  14. window.console.trace = window.console;
  15. window.window = window;
  16. window.ace = window;
  17. window.onerror = function(message, file, line, col, err) {
  18. postMessage({type: "error", data: {
  19. message: message,
  20. data: err.data,
  21. file: file,
  22. line: line,
  23. col: col,
  24. stack: err.stack
  25. }});
  26. };
  27. window.normalizeModule = function(parentId, moduleName) {
  28. // normalize plugin requires
  29. if (moduleName.indexOf("!") !== -1) {
  30. var chunks = moduleName.split("!");
  31. return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
  32. }
  33. // normalize relative requires
  34. if (moduleName.charAt(0) == ".") {
  35. var base = parentId.split("/").slice(0, -1).join("/");
  36. moduleName = (base ? base + "/" : "") + moduleName;
  37. while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
  38. var previous = moduleName;
  39. moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  40. }
  41. }
  42. return moduleName;
  43. };
  44. window.require = function require(parentId, id) {
  45. if (!id) {
  46. id = parentId;
  47. parentId = null;
  48. }
  49. if (!id.charAt)
  50. throw new Error("worker.js require() accepts only (parentId, id) as arguments");
  51. id = window.normalizeModule(parentId, id);
  52. var module = window.require.modules[id];
  53. if (module) {
  54. if (!module.initialized) {
  55. module.initialized = true;
  56. module.exports = module.factory().exports;
  57. }
  58. return module.exports;
  59. }
  60. if (!window.require.tlns)
  61. return console.log("unable to load " + id);
  62. var path = resolveModuleId(id, window.require.tlns);
  63. if (path.slice(-3) != ".js") path += ".js";
  64. window.require.id = id;
  65. window.require.modules[id] = {}; // prevent infinite loop on broken modules
  66. importScripts(path);
  67. return window.require(parentId, id);
  68. };
  69. function resolveModuleId(id, paths) {
  70. var testPath = id, tail = "";
  71. while (testPath) {
  72. var alias = paths[testPath];
  73. if (typeof alias == "string") {
  74. return alias + tail;
  75. } else if (alias) {
  76. return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
  77. } else if (alias === false) {
  78. return "";
  79. }
  80. var i = testPath.lastIndexOf("/");
  81. if (i === -1) break;
  82. tail = testPath.substr(i) + tail;
  83. testPath = testPath.slice(0, i);
  84. }
  85. return id;
  86. }
  87. window.require.modules = {};
  88. window.require.tlns = {};
  89. window.define = function(id, deps, factory) {
  90. if (arguments.length == 2) {
  91. factory = deps;
  92. if (typeof id != "string") {
  93. deps = id;
  94. id = window.require.id;
  95. }
  96. } else if (arguments.length == 1) {
  97. factory = id;
  98. deps = [];
  99. id = window.require.id;
  100. }
  101. if (typeof factory != "function") {
  102. window.require.modules[id] = {
  103. exports: factory,
  104. initialized: true
  105. };
  106. return;
  107. }
  108. if (!deps.length)
  109. // If there is no dependencies, we inject "require", "exports" and
  110. // "module" as dependencies, to provide CommonJS compatibility.
  111. deps = ["require", "exports", "module"];
  112. var req = function(childId) {
  113. return window.require(id, childId);
  114. };
  115. window.require.modules[id] = {
  116. exports: {},
  117. factory: function() {
  118. var module = this;
  119. var returnExports = factory.apply(this, deps.map(function(dep) {
  120. switch (dep) {
  121. // Because "require", "exports" and "module" aren't actual
  122. // dependencies, we must handle them seperately.
  123. case "require": return req;
  124. case "exports": return module.exports;
  125. case "module": return module;
  126. // But for all other dependencies, we can just go ahead and
  127. // require them.
  128. default: return req(dep);
  129. }
  130. }));
  131. if (returnExports)
  132. module.exports = returnExports;
  133. return module;
  134. }
  135. };
  136. };
  137. window.define.amd = {};
  138. require.tlns = {};
  139. window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
  140. for (var i in topLevelNamespaces)
  141. require.tlns[i] = topLevelNamespaces[i];
  142. };
  143. window.initSender = function initSender() {
  144. var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
  145. var oop = window.require("ace/lib/oop");
  146. var Sender = function() {};
  147. (function() {
  148. oop.implement(this, EventEmitter);
  149. this.callback = function(data, callbackId) {
  150. postMessage({
  151. type: "call",
  152. id: callbackId,
  153. data: data
  154. });
  155. };
  156. this.emit = function(name, data) {
  157. postMessage({
  158. type: "event",
  159. name: name,
  160. data: data
  161. });
  162. };
  163. }).call(Sender.prototype);
  164. return new Sender();
  165. };
  166. var main = window.main = null;
  167. var sender = window.sender = null;
  168. window.onmessage = function(e) {
  169. var msg = e.data;
  170. if (msg.event && sender) {
  171. sender._signal(msg.event, msg.data);
  172. }
  173. else if (msg.command) {
  174. if (main[msg.command])
  175. main[msg.command].apply(main, msg.args);
  176. else if (window[msg.command])
  177. window[msg.command].apply(window, msg.args);
  178. else
  179. throw new Error("Unknown command:" + msg.command);
  180. }
  181. else if (msg.init) {
  182. window.initBaseUrls(msg.tlns);
  183. require("ace/lib/es5-shim");
  184. sender = window.sender = window.initSender();
  185. var clazz = require(msg.module)[msg.classname];
  186. main = window.main = new clazz(sender);
  187. }
  188. };
  189. })(this);
  190. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  191. "use strict";
  192. exports.inherits = function(ctor, superCtor) {
  193. ctor.super_ = superCtor;
  194. ctor.prototype = Object.create(superCtor.prototype, {
  195. constructor: {
  196. value: ctor,
  197. enumerable: false,
  198. writable: true,
  199. configurable: true
  200. }
  201. });
  202. };
  203. exports.mixin = function(obj, mixin) {
  204. for (var key in mixin) {
  205. obj[key] = mixin[key];
  206. }
  207. return obj;
  208. };
  209. exports.implement = function(proto, mixin) {
  210. exports.mixin(proto, mixin);
  211. };
  212. });
  213. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  214. "use strict";
  215. var comparePoints = function(p1, p2) {
  216. return p1.row - p2.row || p1.column - p2.column;
  217. };
  218. var Range = function(startRow, startColumn, endRow, endColumn) {
  219. this.start = {
  220. row: startRow,
  221. column: startColumn
  222. };
  223. this.end = {
  224. row: endRow,
  225. column: endColumn
  226. };
  227. };
  228. (function() {
  229. this.isEqual = function(range) {
  230. return this.start.row === range.start.row &&
  231. this.end.row === range.end.row &&
  232. this.start.column === range.start.column &&
  233. this.end.column === range.end.column;
  234. };
  235. this.toString = function() {
  236. return ("Range: [" + this.start.row + "/" + this.start.column +
  237. "] -> [" + this.end.row + "/" + this.end.column + "]");
  238. };
  239. this.contains = function(row, column) {
  240. return this.compare(row, column) == 0;
  241. };
  242. this.compareRange = function(range) {
  243. var cmp,
  244. end = range.end,
  245. start = range.start;
  246. cmp = this.compare(end.row, end.column);
  247. if (cmp == 1) {
  248. cmp = this.compare(start.row, start.column);
  249. if (cmp == 1) {
  250. return 2;
  251. } else if (cmp == 0) {
  252. return 1;
  253. } else {
  254. return 0;
  255. }
  256. } else if (cmp == -1) {
  257. return -2;
  258. } else {
  259. cmp = this.compare(start.row, start.column);
  260. if (cmp == -1) {
  261. return -1;
  262. } else if (cmp == 1) {
  263. return 42;
  264. } else {
  265. return 0;
  266. }
  267. }
  268. };
  269. this.comparePoint = function(p) {
  270. return this.compare(p.row, p.column);
  271. };
  272. this.containsRange = function(range) {
  273. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  274. };
  275. this.intersects = function(range) {
  276. var cmp = this.compareRange(range);
  277. return (cmp == -1 || cmp == 0 || cmp == 1);
  278. };
  279. this.isEnd = function(row, column) {
  280. return this.end.row == row && this.end.column == column;
  281. };
  282. this.isStart = function(row, column) {
  283. return this.start.row == row && this.start.column == column;
  284. };
  285. this.setStart = function(row, column) {
  286. if (typeof row == "object") {
  287. this.start.column = row.column;
  288. this.start.row = row.row;
  289. } else {
  290. this.start.row = row;
  291. this.start.column = column;
  292. }
  293. };
  294. this.setEnd = function(row, column) {
  295. if (typeof row == "object") {
  296. this.end.column = row.column;
  297. this.end.row = row.row;
  298. } else {
  299. this.end.row = row;
  300. this.end.column = column;
  301. }
  302. };
  303. this.inside = function(row, column) {
  304. if (this.compare(row, column) == 0) {
  305. if (this.isEnd(row, column) || this.isStart(row, column)) {
  306. return false;
  307. } else {
  308. return true;
  309. }
  310. }
  311. return false;
  312. };
  313. this.insideStart = function(row, column) {
  314. if (this.compare(row, column) == 0) {
  315. if (this.isEnd(row, column)) {
  316. return false;
  317. } else {
  318. return true;
  319. }
  320. }
  321. return false;
  322. };
  323. this.insideEnd = function(row, column) {
  324. if (this.compare(row, column) == 0) {
  325. if (this.isStart(row, column)) {
  326. return false;
  327. } else {
  328. return true;
  329. }
  330. }
  331. return false;
  332. };
  333. this.compare = function(row, column) {
  334. if (!this.isMultiLine()) {
  335. if (row === this.start.row) {
  336. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  337. };
  338. }
  339. if (row < this.start.row)
  340. return -1;
  341. if (row > this.end.row)
  342. return 1;
  343. if (this.start.row === row)
  344. return column >= this.start.column ? 0 : -1;
  345. if (this.end.row === row)
  346. return column <= this.end.column ? 0 : 1;
  347. return 0;
  348. };
  349. this.compareStart = function(row, column) {
  350. if (this.start.row == row && this.start.column == column) {
  351. return -1;
  352. } else {
  353. return this.compare(row, column);
  354. }
  355. };
  356. this.compareEnd = function(row, column) {
  357. if (this.end.row == row && this.end.column == column) {
  358. return 1;
  359. } else {
  360. return this.compare(row, column);
  361. }
  362. };
  363. this.compareInside = function(row, column) {
  364. if (this.end.row == row && this.end.column == column) {
  365. return 1;
  366. } else if (this.start.row == row && this.start.column == column) {
  367. return -1;
  368. } else {
  369. return this.compare(row, column);
  370. }
  371. };
  372. this.clipRows = function(firstRow, lastRow) {
  373. if (this.end.row > lastRow)
  374. var end = {row: lastRow + 1, column: 0};
  375. else if (this.end.row < firstRow)
  376. var end = {row: firstRow, column: 0};
  377. if (this.start.row > lastRow)
  378. var start = {row: lastRow + 1, column: 0};
  379. else if (this.start.row < firstRow)
  380. var start = {row: firstRow, column: 0};
  381. return Range.fromPoints(start || this.start, end || this.end);
  382. };
  383. this.extend = function(row, column) {
  384. var cmp = this.compare(row, column);
  385. if (cmp == 0)
  386. return this;
  387. else if (cmp == -1)
  388. var start = {row: row, column: column};
  389. else
  390. var end = {row: row, column: column};
  391. return Range.fromPoints(start || this.start, end || this.end);
  392. };
  393. this.isEmpty = function() {
  394. return (this.start.row === this.end.row && this.start.column === this.end.column);
  395. };
  396. this.isMultiLine = function() {
  397. return (this.start.row !== this.end.row);
  398. };
  399. this.clone = function() {
  400. return Range.fromPoints(this.start, this.end);
  401. };
  402. this.collapseRows = function() {
  403. if (this.end.column == 0)
  404. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  405. else
  406. return new Range(this.start.row, 0, this.end.row, 0)
  407. };
  408. this.toScreenRange = function(session) {
  409. var screenPosStart = session.documentToScreenPosition(this.start);
  410. var screenPosEnd = session.documentToScreenPosition(this.end);
  411. return new Range(
  412. screenPosStart.row, screenPosStart.column,
  413. screenPosEnd.row, screenPosEnd.column
  414. );
  415. };
  416. this.moveBy = function(row, column) {
  417. this.start.row += row;
  418. this.start.column += column;
  419. this.end.row += row;
  420. this.end.column += column;
  421. };
  422. }).call(Range.prototype);
  423. Range.fromPoints = function(start, end) {
  424. return new Range(start.row, start.column, end.row, end.column);
  425. };
  426. Range.comparePoints = comparePoints;
  427. Range.comparePoints = function(p1, p2) {
  428. return p1.row - p2.row || p1.column - p2.column;
  429. };
  430. exports.Range = Range;
  431. });
  432. ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
  433. "use strict";
  434. function throwDeltaError(delta, errorText){
  435. console.log("Invalid Delta:", delta);
  436. throw "Invalid Delta: " + errorText;
  437. }
  438. function positionInDocument(docLines, position) {
  439. return position.row >= 0 && position.row < docLines.length &&
  440. position.column >= 0 && position.column <= docLines[position.row].length;
  441. }
  442. function validateDelta(docLines, delta) {
  443. if (delta.action != "insert" && delta.action != "remove")
  444. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  445. if (!(delta.lines instanceof Array))
  446. throwDeltaError(delta, "delta.lines must be an Array");
  447. if (!delta.start || !delta.end)
  448. throwDeltaError(delta, "delta.start/end must be an present");
  449. var start = delta.start;
  450. if (!positionInDocument(docLines, delta.start))
  451. throwDeltaError(delta, "delta.start must be contained in document");
  452. var end = delta.end;
  453. if (delta.action == "remove" && !positionInDocument(docLines, end))
  454. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  455. var numRangeRows = end.row - start.row;
  456. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  457. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  458. throwDeltaError(delta, "delta.range must match delta lines");
  459. }
  460. exports.applyDelta = function(docLines, delta, doNotValidate) {
  461. var row = delta.start.row;
  462. var startColumn = delta.start.column;
  463. var line = docLines[row] || "";
  464. switch (delta.action) {
  465. case "insert":
  466. var lines = delta.lines;
  467. if (lines.length === 1) {
  468. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  469. } else {
  470. var args = [row, 1].concat(delta.lines);
  471. docLines.splice.apply(docLines, args);
  472. docLines[row] = line.substring(0, startColumn) + docLines[row];
  473. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  474. }
  475. break;
  476. case "remove":
  477. var endColumn = delta.end.column;
  478. var endRow = delta.end.row;
  479. if (row === endRow) {
  480. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  481. } else {
  482. docLines.splice(
  483. row, endRow - row + 1,
  484. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  485. );
  486. }
  487. break;
  488. }
  489. }
  490. });
  491. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  492. "use strict";
  493. var EventEmitter = {};
  494. var stopPropagation = function() { this.propagationStopped = true; };
  495. var preventDefault = function() { this.defaultPrevented = true; };
  496. EventEmitter._emit =
  497. EventEmitter._dispatchEvent = function(eventName, e) {
  498. this._eventRegistry || (this._eventRegistry = {});
  499. this._defaultHandlers || (this._defaultHandlers = {});
  500. var listeners = this._eventRegistry[eventName] || [];
  501. var defaultHandler = this._defaultHandlers[eventName];
  502. if (!listeners.length && !defaultHandler)
  503. return;
  504. if (typeof e != "object" || !e)
  505. e = {};
  506. if (!e.type)
  507. e.type = eventName;
  508. if (!e.stopPropagation)
  509. e.stopPropagation = stopPropagation;
  510. if (!e.preventDefault)
  511. e.preventDefault = preventDefault;
  512. listeners = listeners.slice();
  513. for (var i=0; i<listeners.length; i++) {
  514. listeners[i](e, this);
  515. if (e.propagationStopped)
  516. break;
  517. }
  518. if (defaultHandler && !e.defaultPrevented)
  519. return defaultHandler(e, this);
  520. };
  521. EventEmitter._signal = function(eventName, e) {
  522. var listeners = (this._eventRegistry || {})[eventName];
  523. if (!listeners)
  524. return;
  525. listeners = listeners.slice();
  526. for (var i=0; i<listeners.length; i++)
  527. listeners[i](e, this);
  528. };
  529. EventEmitter.once = function(eventName, callback) {
  530. var _self = this;
  531. callback && this.addEventListener(eventName, function newCallback() {
  532. _self.removeEventListener(eventName, newCallback);
  533. callback.apply(null, arguments);
  534. });
  535. };
  536. EventEmitter.setDefaultHandler = function(eventName, callback) {
  537. var handlers = this._defaultHandlers
  538. if (!handlers)
  539. handlers = this._defaultHandlers = {_disabled_: {}};
  540. if (handlers[eventName]) {
  541. var old = handlers[eventName];
  542. var disabled = handlers._disabled_[eventName];
  543. if (!disabled)
  544. handlers._disabled_[eventName] = disabled = [];
  545. disabled.push(old);
  546. var i = disabled.indexOf(callback);
  547. if (i != -1)
  548. disabled.splice(i, 1);
  549. }
  550. handlers[eventName] = callback;
  551. };
  552. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  553. var handlers = this._defaultHandlers
  554. if (!handlers)
  555. return;
  556. var disabled = handlers._disabled_[eventName];
  557. if (handlers[eventName] == callback) {
  558. var old = handlers[eventName];
  559. if (disabled)
  560. this.setDefaultHandler(eventName, disabled.pop());
  561. } else if (disabled) {
  562. var i = disabled.indexOf(callback);
  563. if (i != -1)
  564. disabled.splice(i, 1);
  565. }
  566. };
  567. EventEmitter.on =
  568. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  569. this._eventRegistry = this._eventRegistry || {};
  570. var listeners = this._eventRegistry[eventName];
  571. if (!listeners)
  572. listeners = this._eventRegistry[eventName] = [];
  573. if (listeners.indexOf(callback) == -1)
  574. listeners[capturing ? "unshift" : "push"](callback);
  575. return callback;
  576. };
  577. EventEmitter.off =
  578. EventEmitter.removeListener =
  579. EventEmitter.removeEventListener = function(eventName, callback) {
  580. this._eventRegistry = this._eventRegistry || {};
  581. var listeners = this._eventRegistry[eventName];
  582. if (!listeners)
  583. return;
  584. var index = listeners.indexOf(callback);
  585. if (index !== -1)
  586. listeners.splice(index, 1);
  587. };
  588. EventEmitter.removeAllListeners = function(eventName) {
  589. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  590. };
  591. exports.EventEmitter = EventEmitter;
  592. });
  593. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  594. "use strict";
  595. var oop = require("./lib/oop");
  596. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  597. var Anchor = exports.Anchor = function(doc, row, column) {
  598. this.$onChange = this.onChange.bind(this);
  599. this.attach(doc);
  600. if (typeof column == "undefined")
  601. this.setPosition(row.row, row.column);
  602. else
  603. this.setPosition(row, column);
  604. };
  605. (function() {
  606. oop.implement(this, EventEmitter);
  607. this.getPosition = function() {
  608. return this.$clipPositionToDocument(this.row, this.column);
  609. };
  610. this.getDocument = function() {
  611. return this.document;
  612. };
  613. this.$insertRight = false;
  614. this.onChange = function(delta) {
  615. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  616. return;
  617. if (delta.start.row > this.row)
  618. return;
  619. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  620. this.setPosition(point.row, point.column, true);
  621. };
  622. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  623. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  624. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  625. }
  626. function $getTransformedPoint(delta, point, moveIfEqual) {
  627. var deltaIsInsert = delta.action == "insert";
  628. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  629. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  630. var deltaStart = delta.start;
  631. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  632. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  633. return {
  634. row: point.row,
  635. column: point.column
  636. };
  637. }
  638. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  639. return {
  640. row: point.row + deltaRowShift,
  641. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  642. };
  643. }
  644. return {
  645. row: deltaStart.row,
  646. column: deltaStart.column
  647. };
  648. }
  649. this.setPosition = function(row, column, noClip) {
  650. var pos;
  651. if (noClip) {
  652. pos = {
  653. row: row,
  654. column: column
  655. };
  656. } else {
  657. pos = this.$clipPositionToDocument(row, column);
  658. }
  659. if (this.row == pos.row && this.column == pos.column)
  660. return;
  661. var old = {
  662. row: this.row,
  663. column: this.column
  664. };
  665. this.row = pos.row;
  666. this.column = pos.column;
  667. this._signal("change", {
  668. old: old,
  669. value: pos
  670. });
  671. };
  672. this.detach = function() {
  673. this.document.removeEventListener("change", this.$onChange);
  674. };
  675. this.attach = function(doc) {
  676. this.document = doc || this.document;
  677. this.document.on("change", this.$onChange);
  678. };
  679. this.$clipPositionToDocument = function(row, column) {
  680. var pos = {};
  681. if (row >= this.document.getLength()) {
  682. pos.row = Math.max(0, this.document.getLength() - 1);
  683. pos.column = this.document.getLine(pos.row).length;
  684. }
  685. else if (row < 0) {
  686. pos.row = 0;
  687. pos.column = 0;
  688. }
  689. else {
  690. pos.row = row;
  691. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  692. }
  693. if (column < 0)
  694. pos.column = 0;
  695. return pos;
  696. };
  697. }).call(Anchor.prototype);
  698. });
  699. 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) {
  700. "use strict";
  701. var oop = require("./lib/oop");
  702. var applyDelta = require("./apply_delta").applyDelta;
  703. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  704. var Range = require("./range").Range;
  705. var Anchor = require("./anchor").Anchor;
  706. var Document = function(textOrLines) {
  707. this.$lines = [""];
  708. if (textOrLines.length === 0) {
  709. this.$lines = [""];
  710. } else if (Array.isArray(textOrLines)) {
  711. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  712. } else {
  713. this.insert({row: 0, column:0}, textOrLines);
  714. }
  715. };
  716. (function() {
  717. oop.implement(this, EventEmitter);
  718. this.setValue = function(text) {
  719. var len = this.getLength() - 1;
  720. this.remove(new Range(0, 0, len, this.getLine(len).length));
  721. this.insert({row: 0, column: 0}, text);
  722. };
  723. this.getValue = function() {
  724. return this.getAllLines().join(this.getNewLineCharacter());
  725. };
  726. this.createAnchor = function(row, column) {
  727. return new Anchor(this, row, column);
  728. };
  729. if ("aaa".split(/a/).length === 0) {
  730. this.$split = function(text) {
  731. return text.replace(/\r\n|\r/g, "\n").split("\n");
  732. };
  733. } else {
  734. this.$split = function(text) {
  735. return text.split(/\r\n|\r|\n/);
  736. };
  737. }
  738. this.$detectNewLine = function(text) {
  739. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  740. this.$autoNewLine = match ? match[1] : "\n";
  741. this._signal("changeNewLineMode");
  742. };
  743. this.getNewLineCharacter = function() {
  744. switch (this.$newLineMode) {
  745. case "windows":
  746. return "\r\n";
  747. case "unix":
  748. return "\n";
  749. default:
  750. return this.$autoNewLine || "\n";
  751. }
  752. };
  753. this.$autoNewLine = "";
  754. this.$newLineMode = "auto";
  755. this.setNewLineMode = function(newLineMode) {
  756. if (this.$newLineMode === newLineMode)
  757. return;
  758. this.$newLineMode = newLineMode;
  759. this._signal("changeNewLineMode");
  760. };
  761. this.getNewLineMode = function() {
  762. return this.$newLineMode;
  763. };
  764. this.isNewLine = function(text) {
  765. return (text == "\r\n" || text == "\r" || text == "\n");
  766. };
  767. this.getLine = function(row) {
  768. return this.$lines[row] || "";
  769. };
  770. this.getLines = function(firstRow, lastRow) {
  771. return this.$lines.slice(firstRow, lastRow + 1);
  772. };
  773. this.getAllLines = function() {
  774. return this.getLines(0, this.getLength());
  775. };
  776. this.getLength = function() {
  777. return this.$lines.length;
  778. };
  779. this.getTextRange = function(range) {
  780. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  781. };
  782. this.getLinesForRange = function(range) {
  783. var lines;
  784. if (range.start.row === range.end.row) {
  785. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  786. } else {
  787. lines = this.getLines(range.start.row, range.end.row);
  788. lines[0] = (lines[0] || "").substring(range.start.column);
  789. var l = lines.length - 1;
  790. if (range.end.row - range.start.row == l)
  791. lines[l] = lines[l].substring(0, range.end.column);
  792. }
  793. return lines;
  794. };
  795. this.insertLines = function(row, lines) {
  796. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  797. return this.insertFullLines(row, lines);
  798. };
  799. this.removeLines = function(firstRow, lastRow) {
  800. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  801. return this.removeFullLines(firstRow, lastRow);
  802. };
  803. this.insertNewLine = function(position) {
  804. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, [\'\', \'\']) instead.");
  805. return this.insertMergedLines(position, ["", ""]);
  806. };
  807. this.insert = function(position, text) {
  808. if (this.getLength() <= 1)
  809. this.$detectNewLine(text);
  810. return this.insertMergedLines(position, this.$split(text));
  811. };
  812. this.insertInLine = function(position, text) {
  813. var start = this.clippedPos(position.row, position.column);
  814. var end = this.pos(position.row, position.column + text.length);
  815. this.applyDelta({
  816. start: start,
  817. end: end,
  818. action: "insert",
  819. lines: [text]
  820. }, true);
  821. return this.clonePos(end);
  822. };
  823. this.clippedPos = function(row, column) {
  824. var length = this.getLength();
  825. if (row === undefined) {
  826. row = length;
  827. } else if (row < 0) {
  828. row = 0;
  829. } else if (row >= length) {
  830. row = length - 1;
  831. column = undefined;
  832. }
  833. var line = this.getLine(row);
  834. if (column == undefined)
  835. column = line.length;
  836. column = Math.min(Math.max(column, 0), line.length);
  837. return {row: row, column: column};
  838. };
  839. this.clonePos = function(pos) {
  840. return {row: pos.row, column: pos.column};
  841. };
  842. this.pos = function(row, column) {
  843. return {row: row, column: column};
  844. };
  845. this.$clipPosition = function(position) {
  846. var length = this.getLength();
  847. if (position.row >= length) {
  848. position.row = Math.max(0, length - 1);
  849. position.column = this.getLine(length - 1).length;
  850. } else {
  851. position.row = Math.max(0, position.row);
  852. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  853. }
  854. return position;
  855. };
  856. this.insertFullLines = function(row, lines) {
  857. row = Math.min(Math.max(row, 0), this.getLength());
  858. var column = 0;
  859. if (row < this.getLength()) {
  860. lines = lines.concat([""]);
  861. column = 0;
  862. } else {
  863. lines = [""].concat(lines);
  864. row--;
  865. column = this.$lines[row].length;
  866. }
  867. this.insertMergedLines({row: row, column: column}, lines);
  868. };
  869. this.insertMergedLines = function(position, lines) {
  870. var start = this.clippedPos(position.row, position.column);
  871. var end = {
  872. row: start.row + lines.length - 1,
  873. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  874. };
  875. this.applyDelta({
  876. start: start,
  877. end: end,
  878. action: "insert",
  879. lines: lines
  880. });
  881. return this.clonePos(end);
  882. };
  883. this.remove = function(range) {
  884. var start = this.clippedPos(range.start.row, range.start.column);
  885. var end = this.clippedPos(range.end.row, range.end.column);
  886. this.applyDelta({
  887. start: start,
  888. end: end,
  889. action: "remove",
  890. lines: this.getLinesForRange({start: start, end: end})
  891. });
  892. return this.clonePos(start);
  893. };
  894. this.removeInLine = function(row, startColumn, endColumn) {
  895. var start = this.clippedPos(row, startColumn);
  896. var end = this.clippedPos(row, endColumn);
  897. this.applyDelta({
  898. start: start,
  899. end: end,
  900. action: "remove",
  901. lines: this.getLinesForRange({start: start, end: end})
  902. }, true);
  903. return this.clonePos(start);
  904. };
  905. this.removeFullLines = function(firstRow, lastRow) {
  906. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  907. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  908. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  909. var deleteLastNewLine = lastRow < this.getLength() - 1;
  910. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  911. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  912. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  913. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  914. var range = new Range(startRow, startCol, endRow, endCol);
  915. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  916. this.applyDelta({
  917. start: range.start,
  918. end: range.end,
  919. action: "remove",
  920. lines: this.getLinesForRange(range)
  921. });
  922. return deletedLines;
  923. };
  924. this.removeNewLine = function(row) {
  925. if (row < this.getLength() - 1 && row >= 0) {
  926. this.applyDelta({
  927. start: this.pos(row, this.getLine(row).length),
  928. end: this.pos(row + 1, 0),
  929. action: "remove",
  930. lines: ["", ""]
  931. });
  932. }
  933. };
  934. this.replace = function(range, text) {
  935. if (!range instanceof Range)
  936. range = Range.fromPoints(range.start, range.end);
  937. if (text.length === 0 && range.isEmpty())
  938. return range.start;
  939. if (text == this.getTextRange(range))
  940. return range.end;
  941. this.remove(range);
  942. var end;
  943. if (text) {
  944. end = this.insert(range.start, text);
  945. }
  946. else {
  947. end = range.start;
  948. }
  949. return end;
  950. };
  951. this.applyDeltas = function(deltas) {
  952. for (var i=0; i<deltas.length; i++) {
  953. this.applyDelta(deltas[i]);
  954. }
  955. };
  956. this.revertDeltas = function(deltas) {
  957. for (var i=deltas.length-1; i>=0; i--) {
  958. this.revertDelta(deltas[i]);
  959. }
  960. };
  961. this.applyDelta = function(delta, doNotValidate) {
  962. var isInsert = delta.action == "insert";
  963. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  964. : !Range.comparePoints(delta.start, delta.end)) {
  965. return;
  966. }
  967. if (isInsert && delta.lines.length > 20000)
  968. this.$splitAndapplyLargeDelta(delta, 20000);
  969. applyDelta(this.$lines, delta, doNotValidate);
  970. this._signal("change", delta);
  971. };
  972. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  973. var lines = delta.lines;
  974. var l = lines.length;
  975. var row = delta.start.row;
  976. var column = delta.start.column;
  977. var from = 0, to = 0;
  978. do {
  979. from = to;
  980. to += MAX - 1;
  981. var chunk = lines.slice(from, to);
  982. if (to > l) {
  983. delta.lines = chunk;
  984. delta.start.row = row + from;
  985. delta.start.column = column;
  986. break;
  987. }
  988. chunk.push("");
  989. this.applyDelta({
  990. start: this.pos(row + from, column),
  991. end: this.pos(row + to, column = 0),
  992. action: delta.action,
  993. lines: chunk
  994. }, true);
  995. } while(true);
  996. };
  997. this.revertDelta = function(delta) {
  998. this.applyDelta({
  999. start: this.clonePos(delta.start),
  1000. end: this.clonePos(delta.end),
  1001. action: (delta.action == "insert" ? "remove" : "insert"),
  1002. lines: delta.lines.slice()
  1003. });
  1004. };
  1005. this.indexToPosition = function(index, startRow) {
  1006. var lines = this.$lines || this.getAllLines();
  1007. var newlineLength = this.getNewLineCharacter().length;
  1008. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1009. index -= lines[i].length + newlineLength;
  1010. if (index < 0)
  1011. return {row: i, column: index + lines[i].length + newlineLength};
  1012. }
  1013. return {row: l-1, column: lines[l-1].length};
  1014. };
  1015. this.positionToIndex = function(pos, startRow) {
  1016. var lines = this.$lines || this.getAllLines();
  1017. var newlineLength = this.getNewLineCharacter().length;
  1018. var index = 0;
  1019. var row = Math.min(pos.row, lines.length);
  1020. for (var i = startRow || 0; i < row; ++i)
  1021. index += lines[i].length + newlineLength;
  1022. return index + pos.column;
  1023. };
  1024. }).call(Document.prototype);
  1025. exports.Document = Document;
  1026. });
  1027. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  1028. "use strict";
  1029. exports.last = function(a) {
  1030. return a[a.length - 1];
  1031. };
  1032. exports.stringReverse = function(string) {
  1033. return string.split("").reverse().join("");
  1034. };
  1035. exports.stringRepeat = function (string, count) {
  1036. var result = '';
  1037. while (count > 0) {
  1038. if (count & 1)
  1039. result += string;
  1040. if (count >>= 1)
  1041. string += string;
  1042. }
  1043. return result;
  1044. };
  1045. var trimBeginRegexp = /^\s\s*/;
  1046. var trimEndRegexp = /\s\s*$/;
  1047. exports.stringTrimLeft = function (string) {
  1048. return string.replace(trimBeginRegexp, '');
  1049. };
  1050. exports.stringTrimRight = function (string) {
  1051. return string.replace(trimEndRegexp, '');
  1052. };
  1053. exports.copyObject = function(obj) {
  1054. var copy = {};
  1055. for (var key in obj) {
  1056. copy[key] = obj[key];
  1057. }
  1058. return copy;
  1059. };
  1060. exports.copyArray = function(array){
  1061. var copy = [];
  1062. for (var i=0, l=array.length; i<l; i++) {
  1063. if (array[i] && typeof array[i] == "object")
  1064. copy[i] = this.copyObject( array[i] );
  1065. else
  1066. copy[i] = array[i];
  1067. }
  1068. return copy;
  1069. };
  1070. exports.deepCopy = function deepCopy(obj) {
  1071. if (typeof obj !== "object" || !obj)
  1072. return obj;
  1073. var copy;
  1074. if (Array.isArray(obj)) {
  1075. copy = [];
  1076. for (var key = 0; key < obj.length; key++) {
  1077. copy[key] = deepCopy(obj[key]);
  1078. }
  1079. return copy;
  1080. }
  1081. var cons = obj.constructor;
  1082. if (cons === RegExp)
  1083. return obj;
  1084. copy = cons();
  1085. for (var key in obj) {
  1086. copy[key] = deepCopy(obj[key]);
  1087. }
  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. });