worker-json.js 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401
  1. "no use strict";
  2. !(function(window) {
  3. if (typeof window.window != "undefined" && window.document)
  4. return;
  5. if (window.require && window.define)
  6. return;
  7. if (!window.console) {
  8. window.console = function() {
  9. var msgs = Array.prototype.slice.call(arguments, 0);
  10. postMessage({type: "log", data: msgs});
  11. };
  12. window.console.error =
  13. window.console.warn =
  14. window.console.log =
  15. window.console.trace = window.console;
  16. }
  17. window.window = window;
  18. window.ace = window;
  19. window.onerror = function(message, file, line, col, err) {
  20. postMessage({type: "error", data: {
  21. message: message,
  22. data: err.data,
  23. file: file,
  24. line: line,
  25. col: col,
  26. stack: err.stack
  27. }});
  28. };
  29. window.normalizeModule = function(parentId, moduleName) {
  30. // normalize plugin requires
  31. if (moduleName.indexOf("!") !== -1) {
  32. var chunks = moduleName.split("!");
  33. return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
  34. }
  35. // normalize relative requires
  36. if (moduleName.charAt(0) == ".") {
  37. var base = parentId.split("/").slice(0, -1).join("/");
  38. moduleName = (base ? base + "/" : "") + moduleName;
  39. while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
  40. var previous = moduleName;
  41. moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  42. }
  43. }
  44. return moduleName;
  45. };
  46. window.require = function require(parentId, id) {
  47. if (!id) {
  48. id = parentId;
  49. parentId = null;
  50. }
  51. if (!id.charAt)
  52. throw new Error("worker.js require() accepts only (parentId, id) as arguments");
  53. id = window.normalizeModule(parentId, id);
  54. var module = window.require.modules[id];
  55. if (module) {
  56. if (!module.initialized) {
  57. module.initialized = true;
  58. module.exports = module.factory().exports;
  59. }
  60. return module.exports;
  61. }
  62. if (!window.require.tlns)
  63. return console.log("unable to load " + id);
  64. var path = resolveModuleId(id, window.require.tlns);
  65. if (path.slice(-3) != ".js") path += ".js";
  66. window.require.id = id;
  67. window.require.modules[id] = {}; // prevent infinite loop on broken modules
  68. importScripts(path);
  69. return window.require(parentId, id);
  70. };
  71. function resolveModuleId(id, paths) {
  72. var testPath = id, tail = "";
  73. while (testPath) {
  74. var alias = paths[testPath];
  75. if (typeof alias == "string") {
  76. return alias + tail;
  77. } else if (alias) {
  78. return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
  79. } else if (alias === false) {
  80. return "";
  81. }
  82. var i = testPath.lastIndexOf("/");
  83. if (i === -1) break;
  84. tail = testPath.substr(i) + tail;
  85. testPath = testPath.slice(0, i);
  86. }
  87. return id;
  88. }
  89. window.require.modules = {};
  90. window.require.tlns = {};
  91. window.define = function(id, deps, factory) {
  92. if (arguments.length == 2) {
  93. factory = deps;
  94. if (typeof id != "string") {
  95. deps = id;
  96. id = window.require.id;
  97. }
  98. } else if (arguments.length == 1) {
  99. factory = id;
  100. deps = [];
  101. id = window.require.id;
  102. }
  103. if (typeof factory != "function") {
  104. window.require.modules[id] = {
  105. exports: factory,
  106. initialized: true
  107. };
  108. return;
  109. }
  110. if (!deps.length)
  111. // If there is no dependencies, we inject "require", "exports" and
  112. // "module" as dependencies, to provide CommonJS compatibility.
  113. deps = ["require", "exports", "module"];
  114. var req = function(childId) {
  115. return window.require(id, childId);
  116. };
  117. window.require.modules[id] = {
  118. exports: {},
  119. factory: function() {
  120. var module = this;
  121. var returnExports = factory.apply(this, deps.slice(0, factory.length).map(function(dep) {
  122. switch (dep) {
  123. // Because "require", "exports" and "module" aren't actual
  124. // dependencies, we must handle them seperately.
  125. case "require": return req;
  126. case "exports": return module.exports;
  127. case "module": return module;
  128. // But for all other dependencies, we can just go ahead and
  129. // require them.
  130. default: return req(dep);
  131. }
  132. }));
  133. if (returnExports)
  134. module.exports = returnExports;
  135. return module;
  136. }
  137. };
  138. };
  139. window.define.amd = {};
  140. require.tlns = {};
  141. window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
  142. for (var i in topLevelNamespaces)
  143. require.tlns[i] = topLevelNamespaces[i];
  144. };
  145. window.initSender = function initSender() {
  146. var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
  147. var oop = window.require("ace/lib/oop");
  148. var Sender = function() {};
  149. (function() {
  150. oop.implement(this, EventEmitter);
  151. this.callback = function(data, callbackId) {
  152. postMessage({
  153. type: "call",
  154. id: callbackId,
  155. data: data
  156. });
  157. };
  158. this.emit = function(name, data) {
  159. postMessage({
  160. type: "event",
  161. name: name,
  162. data: data
  163. });
  164. };
  165. }).call(Sender.prototype);
  166. return new Sender();
  167. };
  168. var main = window.main = null;
  169. var sender = window.sender = null;
  170. window.onmessage = function(e) {
  171. var msg = e.data;
  172. if (msg.event && sender) {
  173. sender._signal(msg.event, msg.data);
  174. }
  175. else if (msg.command) {
  176. if (main[msg.command])
  177. main[msg.command].apply(main, msg.args);
  178. else if (window[msg.command])
  179. window[msg.command].apply(window, msg.args);
  180. else
  181. throw new Error("Unknown command:" + msg.command);
  182. }
  183. else if (msg.init) {
  184. window.initBaseUrls(msg.tlns);
  185. require("ace/lib/es5-shim");
  186. sender = window.sender = window.initSender();
  187. var clazz = require(msg.module)[msg.classname];
  188. main = window.main = new clazz(sender);
  189. }
  190. };
  191. })(this);
  192. 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. 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. 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. 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. this.addEventListener(eventName, function newCallback() {
  534. _self.removeEventListener(eventName, newCallback);
  535. callback.apply(null, arguments);
  536. });
  537. if (!callback) {
  538. return new Promise(function(resolve) {
  539. callback = resolve;
  540. });
  541. }
  542. };
  543. EventEmitter.setDefaultHandler = function(eventName, callback) {
  544. var handlers = this._defaultHandlers;
  545. if (!handlers)
  546. handlers = this._defaultHandlers = {_disabled_: {}};
  547. if (handlers[eventName]) {
  548. var old = handlers[eventName];
  549. var disabled = handlers._disabled_[eventName];
  550. if (!disabled)
  551. handlers._disabled_[eventName] = disabled = [];
  552. disabled.push(old);
  553. var i = disabled.indexOf(callback);
  554. if (i != -1)
  555. disabled.splice(i, 1);
  556. }
  557. handlers[eventName] = callback;
  558. };
  559. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  560. var handlers = this._defaultHandlers;
  561. if (!handlers)
  562. return;
  563. var disabled = handlers._disabled_[eventName];
  564. if (handlers[eventName] == callback) {
  565. if (disabled)
  566. this.setDefaultHandler(eventName, disabled.pop());
  567. } else if (disabled) {
  568. var i = disabled.indexOf(callback);
  569. if (i != -1)
  570. disabled.splice(i, 1);
  571. }
  572. };
  573. EventEmitter.on =
  574. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  575. this._eventRegistry = this._eventRegistry || {};
  576. var listeners = this._eventRegistry[eventName];
  577. if (!listeners)
  578. listeners = this._eventRegistry[eventName] = [];
  579. if (listeners.indexOf(callback) == -1)
  580. listeners[capturing ? "unshift" : "push"](callback);
  581. return callback;
  582. };
  583. EventEmitter.off =
  584. EventEmitter.removeListener =
  585. EventEmitter.removeEventListener = function(eventName, callback) {
  586. this._eventRegistry = this._eventRegistry || {};
  587. var listeners = this._eventRegistry[eventName];
  588. if (!listeners)
  589. return;
  590. var index = listeners.indexOf(callback);
  591. if (index !== -1)
  592. listeners.splice(index, 1);
  593. };
  594. EventEmitter.removeAllListeners = function(eventName) {
  595. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  596. };
  597. exports.EventEmitter = EventEmitter;
  598. });
  599. define("ace/anchor",[], function(require, exports, module) {
  600. "use strict";
  601. var oop = require("./lib/oop");
  602. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  603. var Anchor = exports.Anchor = function(doc, row, column) {
  604. this.$onChange = this.onChange.bind(this);
  605. this.attach(doc);
  606. if (typeof column == "undefined")
  607. this.setPosition(row.row, row.column);
  608. else
  609. this.setPosition(row, column);
  610. };
  611. (function() {
  612. oop.implement(this, EventEmitter);
  613. this.getPosition = function() {
  614. return this.$clipPositionToDocument(this.row, this.column);
  615. };
  616. this.getDocument = function() {
  617. return this.document;
  618. };
  619. this.$insertRight = false;
  620. this.onChange = function(delta) {
  621. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  622. return;
  623. if (delta.start.row > this.row)
  624. return;
  625. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  626. this.setPosition(point.row, point.column, true);
  627. };
  628. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  629. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  630. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  631. }
  632. function $getTransformedPoint(delta, point, moveIfEqual) {
  633. var deltaIsInsert = delta.action == "insert";
  634. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  635. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  636. var deltaStart = delta.start;
  637. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  638. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  639. return {
  640. row: point.row,
  641. column: point.column
  642. };
  643. }
  644. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  645. return {
  646. row: point.row + deltaRowShift,
  647. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  648. };
  649. }
  650. return {
  651. row: deltaStart.row,
  652. column: deltaStart.column
  653. };
  654. }
  655. this.setPosition = function(row, column, noClip) {
  656. var pos;
  657. if (noClip) {
  658. pos = {
  659. row: row,
  660. column: column
  661. };
  662. } else {
  663. pos = this.$clipPositionToDocument(row, column);
  664. }
  665. if (this.row == pos.row && this.column == pos.column)
  666. return;
  667. var old = {
  668. row: this.row,
  669. column: this.column
  670. };
  671. this.row = pos.row;
  672. this.column = pos.column;
  673. this._signal("change", {
  674. old: old,
  675. value: pos
  676. });
  677. };
  678. this.detach = function() {
  679. this.document.removeEventListener("change", this.$onChange);
  680. };
  681. this.attach = function(doc) {
  682. this.document = doc || this.document;
  683. this.document.on("change", this.$onChange);
  684. };
  685. this.$clipPositionToDocument = function(row, column) {
  686. var pos = {};
  687. if (row >= this.document.getLength()) {
  688. pos.row = Math.max(0, this.document.getLength() - 1);
  689. pos.column = this.document.getLine(pos.row).length;
  690. }
  691. else if (row < 0) {
  692. pos.row = 0;
  693. pos.column = 0;
  694. }
  695. else {
  696. pos.row = row;
  697. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  698. }
  699. if (column < 0)
  700. pos.column = 0;
  701. return pos;
  702. };
  703. }).call(Anchor.prototype);
  704. });
  705. define("ace/document",[], function(require, exports, module) {
  706. "use strict";
  707. var oop = require("./lib/oop");
  708. var applyDelta = require("./apply_delta").applyDelta;
  709. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  710. var Range = require("./range").Range;
  711. var Anchor = require("./anchor").Anchor;
  712. var Document = function(textOrLines) {
  713. this.$lines = [""];
  714. if (textOrLines.length === 0) {
  715. this.$lines = [""];
  716. } else if (Array.isArray(textOrLines)) {
  717. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  718. } else {
  719. this.insert({row: 0, column:0}, textOrLines);
  720. }
  721. };
  722. (function() {
  723. oop.implement(this, EventEmitter);
  724. this.setValue = function(text) {
  725. var len = this.getLength() - 1;
  726. this.remove(new Range(0, 0, len, this.getLine(len).length));
  727. this.insert({row: 0, column: 0}, text);
  728. };
  729. this.getValue = function() {
  730. return this.getAllLines().join(this.getNewLineCharacter());
  731. };
  732. this.createAnchor = function(row, column) {
  733. return new Anchor(this, row, column);
  734. };
  735. if ("aaa".split(/a/).length === 0) {
  736. this.$split = function(text) {
  737. return text.replace(/\r\n|\r/g, "\n").split("\n");
  738. };
  739. } else {
  740. this.$split = function(text) {
  741. return text.split(/\r\n|\r|\n/);
  742. };
  743. }
  744. this.$detectNewLine = function(text) {
  745. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  746. this.$autoNewLine = match ? match[1] : "\n";
  747. this._signal("changeNewLineMode");
  748. };
  749. this.getNewLineCharacter = function() {
  750. switch (this.$newLineMode) {
  751. case "windows":
  752. return "\r\n";
  753. case "unix":
  754. return "\n";
  755. default:
  756. return this.$autoNewLine || "\n";
  757. }
  758. };
  759. this.$autoNewLine = "";
  760. this.$newLineMode = "auto";
  761. this.setNewLineMode = function(newLineMode) {
  762. if (this.$newLineMode === newLineMode)
  763. return;
  764. this.$newLineMode = newLineMode;
  765. this._signal("changeNewLineMode");
  766. };
  767. this.getNewLineMode = function() {
  768. return this.$newLineMode;
  769. };
  770. this.isNewLine = function(text) {
  771. return (text == "\r\n" || text == "\r" || text == "\n");
  772. };
  773. this.getLine = function(row) {
  774. return this.$lines[row] || "";
  775. };
  776. this.getLines = function(firstRow, lastRow) {
  777. return this.$lines.slice(firstRow, lastRow + 1);
  778. };
  779. this.getAllLines = function() {
  780. return this.getLines(0, this.getLength());
  781. };
  782. this.getLength = function() {
  783. return this.$lines.length;
  784. };
  785. this.getTextRange = function(range) {
  786. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  787. };
  788. this.getLinesForRange = function(range) {
  789. var lines;
  790. if (range.start.row === range.end.row) {
  791. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  792. } else {
  793. lines = this.getLines(range.start.row, range.end.row);
  794. lines[0] = (lines[0] || "").substring(range.start.column);
  795. var l = lines.length - 1;
  796. if (range.end.row - range.start.row == l)
  797. lines[l] = lines[l].substring(0, range.end.column);
  798. }
  799. return lines;
  800. };
  801. this.insertLines = function(row, lines) {
  802. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  803. return this.insertFullLines(row, lines);
  804. };
  805. this.removeLines = function(firstRow, lastRow) {
  806. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  807. return this.removeFullLines(firstRow, lastRow);
  808. };
  809. this.insertNewLine = function(position) {
  810. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  811. return this.insertMergedLines(position, ["", ""]);
  812. };
  813. this.insert = function(position, text) {
  814. if (this.getLength() <= 1)
  815. this.$detectNewLine(text);
  816. return this.insertMergedLines(position, this.$split(text));
  817. };
  818. this.insertInLine = function(position, text) {
  819. var start = this.clippedPos(position.row, position.column);
  820. var end = this.pos(position.row, position.column + text.length);
  821. this.applyDelta({
  822. start: start,
  823. end: end,
  824. action: "insert",
  825. lines: [text]
  826. }, true);
  827. return this.clonePos(end);
  828. };
  829. this.clippedPos = function(row, column) {
  830. var length = this.getLength();
  831. if (row === undefined) {
  832. row = length;
  833. } else if (row < 0) {
  834. row = 0;
  835. } else if (row >= length) {
  836. row = length - 1;
  837. column = undefined;
  838. }
  839. var line = this.getLine(row);
  840. if (column == undefined)
  841. column = line.length;
  842. column = Math.min(Math.max(column, 0), line.length);
  843. return {row: row, column: column};
  844. };
  845. this.clonePos = function(pos) {
  846. return {row: pos.row, column: pos.column};
  847. };
  848. this.pos = function(row, column) {
  849. return {row: row, column: column};
  850. };
  851. this.$clipPosition = function(position) {
  852. var length = this.getLength();
  853. if (position.row >= length) {
  854. position.row = Math.max(0, length - 1);
  855. position.column = this.getLine(length - 1).length;
  856. } else {
  857. position.row = Math.max(0, position.row);
  858. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  859. }
  860. return position;
  861. };
  862. this.insertFullLines = function(row, lines) {
  863. row = Math.min(Math.max(row, 0), this.getLength());
  864. var column = 0;
  865. if (row < this.getLength()) {
  866. lines = lines.concat([""]);
  867. column = 0;
  868. } else {
  869. lines = [""].concat(lines);
  870. row--;
  871. column = this.$lines[row].length;
  872. }
  873. this.insertMergedLines({row: row, column: column}, lines);
  874. };
  875. this.insertMergedLines = function(position, lines) {
  876. var start = this.clippedPos(position.row, position.column);
  877. var end = {
  878. row: start.row + lines.length - 1,
  879. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  880. };
  881. this.applyDelta({
  882. start: start,
  883. end: end,
  884. action: "insert",
  885. lines: lines
  886. });
  887. return this.clonePos(end);
  888. };
  889. this.remove = function(range) {
  890. var start = this.clippedPos(range.start.row, range.start.column);
  891. var end = this.clippedPos(range.end.row, range.end.column);
  892. this.applyDelta({
  893. start: start,
  894. end: end,
  895. action: "remove",
  896. lines: this.getLinesForRange({start: start, end: end})
  897. });
  898. return this.clonePos(start);
  899. };
  900. this.removeInLine = function(row, startColumn, endColumn) {
  901. var start = this.clippedPos(row, startColumn);
  902. var end = this.clippedPos(row, endColumn);
  903. this.applyDelta({
  904. start: start,
  905. end: end,
  906. action: "remove",
  907. lines: this.getLinesForRange({start: start, end: end})
  908. }, true);
  909. return this.clonePos(start);
  910. };
  911. this.removeFullLines = function(firstRow, lastRow) {
  912. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  913. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  914. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  915. var deleteLastNewLine = lastRow < this.getLength() - 1;
  916. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  917. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  918. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  919. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  920. var range = new Range(startRow, startCol, endRow, endCol);
  921. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  922. this.applyDelta({
  923. start: range.start,
  924. end: range.end,
  925. action: "remove",
  926. lines: this.getLinesForRange(range)
  927. });
  928. return deletedLines;
  929. };
  930. this.removeNewLine = function(row) {
  931. if (row < this.getLength() - 1 && row >= 0) {
  932. this.applyDelta({
  933. start: this.pos(row, this.getLine(row).length),
  934. end: this.pos(row + 1, 0),
  935. action: "remove",
  936. lines: ["", ""]
  937. });
  938. }
  939. };
  940. this.replace = function(range, text) {
  941. if (!(range instanceof Range))
  942. range = Range.fromPoints(range.start, range.end);
  943. if (text.length === 0 && range.isEmpty())
  944. return range.start;
  945. if (text == this.getTextRange(range))
  946. return range.end;
  947. this.remove(range);
  948. var end;
  949. if (text) {
  950. end = this.insert(range.start, text);
  951. }
  952. else {
  953. end = range.start;
  954. }
  955. return end;
  956. };
  957. this.applyDeltas = function(deltas) {
  958. for (var i=0; i<deltas.length; i++) {
  959. this.applyDelta(deltas[i]);
  960. }
  961. };
  962. this.revertDeltas = function(deltas) {
  963. for (var i=deltas.length-1; i>=0; i--) {
  964. this.revertDelta(deltas[i]);
  965. }
  966. };
  967. this.applyDelta = function(delta, doNotValidate) {
  968. var isInsert = delta.action == "insert";
  969. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  970. : !Range.comparePoints(delta.start, delta.end)) {
  971. return;
  972. }
  973. if (isInsert && delta.lines.length > 20000) {
  974. this.$splitAndapplyLargeDelta(delta, 20000);
  975. }
  976. else {
  977. applyDelta(this.$lines, delta, doNotValidate);
  978. this._signal("change", delta);
  979. }
  980. };
  981. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  982. var lines = delta.lines;
  983. var l = lines.length - MAX + 1;
  984. var row = delta.start.row;
  985. var column = delta.start.column;
  986. for (var from = 0, to = 0; from < l; from = to) {
  987. to += MAX - 1;
  988. var chunk = lines.slice(from, to);
  989. chunk.push("");
  990. this.applyDelta({
  991. start: this.pos(row + from, column),
  992. end: this.pos(row + to, column = 0),
  993. action: delta.action,
  994. lines: chunk
  995. }, true);
  996. }
  997. delta.lines = lines.slice(from);
  998. delta.start.row = row + from;
  999. delta.start.column = column;
  1000. this.applyDelta(delta, true);
  1001. };
  1002. this.revertDelta = function(delta) {
  1003. this.applyDelta({
  1004. start: this.clonePos(delta.start),
  1005. end: this.clonePos(delta.end),
  1006. action: (delta.action == "insert" ? "remove" : "insert"),
  1007. lines: delta.lines.slice()
  1008. });
  1009. };
  1010. this.indexToPosition = function(index, startRow) {
  1011. var lines = this.$lines || this.getAllLines();
  1012. var newlineLength = this.getNewLineCharacter().length;
  1013. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1014. index -= lines[i].length + newlineLength;
  1015. if (index < 0)
  1016. return {row: i, column: index + lines[i].length + newlineLength};
  1017. }
  1018. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  1019. };
  1020. this.positionToIndex = function(pos, startRow) {
  1021. var lines = this.$lines || this.getAllLines();
  1022. var newlineLength = this.getNewLineCharacter().length;
  1023. var index = 0;
  1024. var row = Math.min(pos.row, lines.length);
  1025. for (var i = startRow || 0; i < row; ++i)
  1026. index += lines[i].length + newlineLength;
  1027. return index + pos.column;
  1028. };
  1029. }).call(Document.prototype);
  1030. exports.Document = Document;
  1031. });
  1032. define("ace/lib/lang",[], function(require, exports, module) {
  1033. "use strict";
  1034. exports.last = function(a) {
  1035. return a[a.length - 1];
  1036. };
  1037. exports.stringReverse = function(string) {
  1038. return string.split("").reverse().join("");
  1039. };
  1040. exports.stringRepeat = function (string, count) {
  1041. var result = '';
  1042. while (count > 0) {
  1043. if (count & 1)
  1044. result += string;
  1045. if (count >>= 1)
  1046. string += string;
  1047. }
  1048. return result;
  1049. };
  1050. var trimBeginRegexp = /^\s\s*/;
  1051. var trimEndRegexp = /\s\s*$/;
  1052. exports.stringTrimLeft = function (string) {
  1053. return string.replace(trimBeginRegexp, '');
  1054. };
  1055. exports.stringTrimRight = function (string) {
  1056. return string.replace(trimEndRegexp, '');
  1057. };
  1058. exports.copyObject = function(obj) {
  1059. var copy = {};
  1060. for (var key in obj) {
  1061. copy[key] = obj[key];
  1062. }
  1063. return copy;
  1064. };
  1065. exports.copyArray = function(array){
  1066. var copy = [];
  1067. for (var i=0, l=array.length; i<l; i++) {
  1068. if (array[i] && typeof array[i] == "object")
  1069. copy[i] = this.copyObject(array[i]);
  1070. else
  1071. copy[i] = array[i];
  1072. }
  1073. return copy;
  1074. };
  1075. exports.deepCopy = function deepCopy(obj) {
  1076. if (typeof obj !== "object" || !obj)
  1077. return obj;
  1078. var copy;
  1079. if (Array.isArray(obj)) {
  1080. copy = [];
  1081. for (var key = 0; key < obj.length; key++) {
  1082. copy[key] = deepCopy(obj[key]);
  1083. }
  1084. return copy;
  1085. }
  1086. if (Object.prototype.toString.call(obj) !== "[object Object]")
  1087. return obj;
  1088. copy = {};
  1089. for (var key in obj)
  1090. copy[key] = deepCopy(obj[key]);
  1091. return copy;
  1092. };
  1093. exports.arrayToMap = function(arr) {
  1094. var map = {};
  1095. for (var i=0; i<arr.length; i++) {
  1096. map[arr[i]] = 1;
  1097. }
  1098. return map;
  1099. };
  1100. exports.createMap = function(props) {
  1101. var map = Object.create(null);
  1102. for (var i in props) {
  1103. map[i] = props[i];
  1104. }
  1105. return map;
  1106. };
  1107. exports.arrayRemove = function(array, value) {
  1108. for (var i = 0; i <= array.length; i++) {
  1109. if (value === array[i]) {
  1110. array.splice(i, 1);
  1111. }
  1112. }
  1113. };
  1114. exports.escapeRegExp = function(str) {
  1115. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1116. };
  1117. exports.escapeHTML = function(str) {
  1118. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  1119. };
  1120. exports.getMatchOffsets = function(string, regExp) {
  1121. var matches = [];
  1122. string.replace(regExp, function(str) {
  1123. matches.push({
  1124. offset: arguments[arguments.length-2],
  1125. length: str.length
  1126. });
  1127. });
  1128. return matches;
  1129. };
  1130. exports.deferredCall = function(fcn) {
  1131. var timer = null;
  1132. var callback = function() {
  1133. timer = null;
  1134. fcn();
  1135. };
  1136. var deferred = function(timeout) {
  1137. deferred.cancel();
  1138. timer = setTimeout(callback, timeout || 0);
  1139. return deferred;
  1140. };
  1141. deferred.schedule = deferred;
  1142. deferred.call = function() {
  1143. this.cancel();
  1144. fcn();
  1145. return deferred;
  1146. };
  1147. deferred.cancel = function() {
  1148. clearTimeout(timer);
  1149. timer = null;
  1150. return deferred;
  1151. };
  1152. deferred.isPending = function() {
  1153. return timer;
  1154. };
  1155. return deferred;
  1156. };
  1157. exports.delayedCall = function(fcn, defaultTimeout) {
  1158. var timer = null;
  1159. var callback = function() {
  1160. timer = null;
  1161. fcn();
  1162. };
  1163. var _self = function(timeout) {
  1164. if (timer == null)
  1165. timer = setTimeout(callback, timeout || defaultTimeout);
  1166. };
  1167. _self.delay = function(timeout) {
  1168. timer && clearTimeout(timer);
  1169. timer = setTimeout(callback, timeout || defaultTimeout);
  1170. };
  1171. _self.schedule = _self;
  1172. _self.call = function() {
  1173. this.cancel();
  1174. fcn();
  1175. };
  1176. _self.cancel = function() {
  1177. timer && clearTimeout(timer);
  1178. timer = null;
  1179. };
  1180. _self.isPending = function() {
  1181. return timer;
  1182. };
  1183. return _self;
  1184. };
  1185. });
  1186. define("ace/worker/mirror",[], function(require, exports, module) {
  1187. "use strict";
  1188. var Range = require("../range").Range;
  1189. var Document = require("../document").Document;
  1190. var lang = require("../lib/lang");
  1191. var Mirror = exports.Mirror = function(sender) {
  1192. this.sender = sender;
  1193. var doc = this.doc = new Document("");
  1194. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1195. var _self = this;
  1196. sender.on("change", function(e) {
  1197. var data = e.data;
  1198. if (data[0].start) {
  1199. doc.applyDeltas(data);
  1200. } else {
  1201. for (var i = 0; i < data.length; i += 2) {
  1202. if (Array.isArray(data[i+1])) {
  1203. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1204. } else {
  1205. var d = {action: "remove", start: data[i], end: data[i+1]};
  1206. }
  1207. doc.applyDelta(d, true);
  1208. }
  1209. }
  1210. if (_self.$timeout)
  1211. return deferredUpdate.schedule(_self.$timeout);
  1212. _self.onUpdate();
  1213. });
  1214. };
  1215. (function() {
  1216. this.$timeout = 500;
  1217. this.setTimeout = function(timeout) {
  1218. this.$timeout = timeout;
  1219. };
  1220. this.setValue = function(value) {
  1221. this.doc.setValue(value);
  1222. this.deferredUpdate.schedule(this.$timeout);
  1223. };
  1224. this.getValue = function(callbackId) {
  1225. this.sender.callback(this.doc.getValue(), callbackId);
  1226. };
  1227. this.onUpdate = function() {
  1228. };
  1229. this.isPending = function() {
  1230. return this.deferredUpdate.isPending();
  1231. };
  1232. }).call(Mirror.prototype);
  1233. });
  1234. define("ace/mode/json/json_parse",[], function(require, exports, module) {
  1235. "use strict";
  1236. var at, // The index of the current character
  1237. ch, // The current character
  1238. escapee = {
  1239. '"': '"',
  1240. '\\': '\\',
  1241. '/': '/',
  1242. b: '\b',
  1243. f: '\f',
  1244. n: '\n',
  1245. r: '\r',
  1246. t: '\t'
  1247. },
  1248. text,
  1249. error = function (m) {
  1250. throw {
  1251. name: 'SyntaxError',
  1252. message: m,
  1253. at: at,
  1254. text: text
  1255. };
  1256. },
  1257. next = function (c) {
  1258. if (c && c !== ch) {
  1259. error("Expected '" + c + "' instead of '" + ch + "'");
  1260. }
  1261. ch = text.charAt(at);
  1262. at += 1;
  1263. return ch;
  1264. },
  1265. number = function () {
  1266. var number,
  1267. string = '';
  1268. if (ch === '-') {
  1269. string = '-';
  1270. next('-');
  1271. }
  1272. while (ch >= '0' && ch <= '9') {
  1273. string += ch;
  1274. next();
  1275. }
  1276. if (ch === '.') {
  1277. string += '.';
  1278. while (next() && ch >= '0' && ch <= '9') {
  1279. string += ch;
  1280. }
  1281. }
  1282. if (ch === 'e' || ch === 'E') {
  1283. string += ch;
  1284. next();
  1285. if (ch === '-' || ch === '+') {
  1286. string += ch;
  1287. next();
  1288. }
  1289. while (ch >= '0' && ch <= '9') {
  1290. string += ch;
  1291. next();
  1292. }
  1293. }
  1294. number = +string;
  1295. if (isNaN(number)) {
  1296. error("Bad number");
  1297. } else {
  1298. return number;
  1299. }
  1300. },
  1301. string = function () {
  1302. var hex,
  1303. i,
  1304. string = '',
  1305. uffff;
  1306. if (ch === '"') {
  1307. while (next()) {
  1308. if (ch === '"') {
  1309. next();
  1310. return string;
  1311. } else if (ch === '\\') {
  1312. next();
  1313. if (ch === 'u') {
  1314. uffff = 0;
  1315. for (i = 0; i < 4; i += 1) {
  1316. hex = parseInt(next(), 16);
  1317. if (!isFinite(hex)) {
  1318. break;
  1319. }
  1320. uffff = uffff * 16 + hex;
  1321. }
  1322. string += String.fromCharCode(uffff);
  1323. } else if (typeof escapee[ch] === 'string') {
  1324. string += escapee[ch];
  1325. } else {
  1326. break;
  1327. }
  1328. } else if (ch == "\n" || ch == "\r") {
  1329. break;
  1330. } else {
  1331. string += ch;
  1332. }
  1333. }
  1334. }
  1335. error("Bad string");
  1336. },
  1337. white = function () {
  1338. while (ch && ch <= ' ') {
  1339. next();
  1340. }
  1341. },
  1342. word = function () {
  1343. switch (ch) {
  1344. case 't':
  1345. next('t');
  1346. next('r');
  1347. next('u');
  1348. next('e');
  1349. return true;
  1350. case 'f':
  1351. next('f');
  1352. next('a');
  1353. next('l');
  1354. next('s');
  1355. next('e');
  1356. return false;
  1357. case 'n':
  1358. next('n');
  1359. next('u');
  1360. next('l');
  1361. next('l');
  1362. return null;
  1363. }
  1364. error("Unexpected '" + ch + "'");
  1365. },
  1366. value, // Place holder for the value function.
  1367. array = function () {
  1368. var array = [];
  1369. if (ch === '[') {
  1370. next('[');
  1371. white();
  1372. if (ch === ']') {
  1373. next(']');
  1374. return array; // empty array
  1375. }
  1376. while (ch) {
  1377. array.push(value());
  1378. white();
  1379. if (ch === ']') {
  1380. next(']');
  1381. return array;
  1382. }
  1383. next(',');
  1384. white();
  1385. }
  1386. }
  1387. error("Bad array");
  1388. },
  1389. object = function () {
  1390. var key,
  1391. object = {};
  1392. if (ch === '{') {
  1393. next('{');
  1394. white();
  1395. if (ch === '}') {
  1396. next('}');
  1397. return object; // empty object
  1398. }
  1399. while (ch) {
  1400. key = string();
  1401. white();
  1402. next(':');
  1403. if (Object.hasOwnProperty.call(object, key)) {
  1404. error('Duplicate key "' + key + '"');
  1405. }
  1406. object[key] = value();
  1407. white();
  1408. if (ch === '}') {
  1409. next('}');
  1410. return object;
  1411. }
  1412. next(',');
  1413. white();
  1414. }
  1415. }
  1416. error("Bad object");
  1417. };
  1418. value = function () {
  1419. white();
  1420. switch (ch) {
  1421. case '{':
  1422. return object();
  1423. case '[':
  1424. return array();
  1425. case '"':
  1426. return string();
  1427. case '-':
  1428. return number();
  1429. default:
  1430. return ch >= '0' && ch <= '9' ? number() : word();
  1431. }
  1432. };
  1433. return function (source, reviver) {
  1434. var result;
  1435. text = source;
  1436. at = 0;
  1437. ch = ' ';
  1438. result = value();
  1439. white();
  1440. if (ch) {
  1441. error("Syntax error");
  1442. }
  1443. return typeof reviver === 'function' ? function walk(holder, key) {
  1444. var k, v, value = holder[key];
  1445. if (value && typeof value === 'object') {
  1446. for (k in value) {
  1447. if (Object.hasOwnProperty.call(value, k)) {
  1448. v = walk(value, k);
  1449. if (v !== undefined) {
  1450. value[k] = v;
  1451. } else {
  1452. delete value[k];
  1453. }
  1454. }
  1455. }
  1456. }
  1457. return reviver.call(holder, key, value);
  1458. }({'': result}, '') : result;
  1459. };
  1460. });
  1461. define("ace/mode/json_worker",[], function(require, exports, module) {
  1462. "use strict";
  1463. var oop = require("../lib/oop");
  1464. var Mirror = require("../worker/mirror").Mirror;
  1465. var parse = require("./json/json_parse");
  1466. var JsonWorker = exports.JsonWorker = function(sender) {
  1467. Mirror.call(this, sender);
  1468. this.setTimeout(200);
  1469. };
  1470. oop.inherits(JsonWorker, Mirror);
  1471. (function() {
  1472. this.onUpdate = function() {
  1473. var value = this.doc.getValue();
  1474. var errors = [];
  1475. try {
  1476. if (value)
  1477. parse(value);
  1478. } catch (e) {
  1479. var pos = this.doc.indexToPosition(e.at-1);
  1480. errors.push({
  1481. row: pos.row,
  1482. column: pos.column,
  1483. text: e.message,
  1484. type: "error"
  1485. });
  1486. }
  1487. this.sender.emit("annotate", errors);
  1488. };
  1489. }).call(JsonWorker.prototype);
  1490. });
  1491. define("ace/lib/es5-shim",[], function(require, exports, module) {
  1492. function Empty() {}
  1493. if (!Function.prototype.bind) {
  1494. Function.prototype.bind = function bind(that) { // .length is 1
  1495. var target = this;
  1496. if (typeof target != "function") {
  1497. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  1498. }
  1499. var args = slice.call(arguments, 1); // for normal call
  1500. var bound = function () {
  1501. if (this instanceof bound) {
  1502. var result = target.apply(
  1503. this,
  1504. args.concat(slice.call(arguments))
  1505. );
  1506. if (Object(result) === result) {
  1507. return result;
  1508. }
  1509. return this;
  1510. } else {
  1511. return target.apply(
  1512. that,
  1513. args.concat(slice.call(arguments))
  1514. );
  1515. }
  1516. };
  1517. if(target.prototype) {
  1518. Empty.prototype = target.prototype;
  1519. bound.prototype = new Empty();
  1520. Empty.prototype = null;
  1521. }
  1522. return bound;
  1523. };
  1524. }
  1525. var call = Function.prototype.call;
  1526. var prototypeOfArray = Array.prototype;
  1527. var prototypeOfObject = Object.prototype;
  1528. var slice = prototypeOfArray.slice;
  1529. var _toString = call.bind(prototypeOfObject.toString);
  1530. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  1531. var defineGetter;
  1532. var defineSetter;
  1533. var lookupGetter;
  1534. var lookupSetter;
  1535. var supportsAccessors;
  1536. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  1537. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  1538. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  1539. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  1540. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  1541. }
  1542. if ([1,2].splice(0).length != 2) {
  1543. if(function() { // test IE < 9 to splice bug - see issue #138
  1544. function makeArray(l) {
  1545. var a = new Array(l+2);
  1546. a[0] = a[1] = 0;
  1547. return a;
  1548. }
  1549. var array = [], lengthBefore;
  1550. array.splice.apply(array, makeArray(20));
  1551. array.splice.apply(array, makeArray(26));
  1552. lengthBefore = array.length; //46
  1553. array.splice(5, 0, "XXX"); // add one element
  1554. lengthBefore + 1 == array.length
  1555. if (lengthBefore + 1 == array.length) {
  1556. return true;// has right splice implementation without bugs
  1557. }
  1558. }()) {//IE 6/7
  1559. var array_splice = Array.prototype.splice;
  1560. Array.prototype.splice = function(start, deleteCount) {
  1561. if (!arguments.length) {
  1562. return [];
  1563. } else {
  1564. return array_splice.apply(this, [
  1565. start === void 0 ? 0 : start,
  1566. deleteCount === void 0 ? (this.length - start) : deleteCount
  1567. ].concat(slice.call(arguments, 2)))
  1568. }
  1569. };
  1570. } else {//IE8
  1571. Array.prototype.splice = function(pos, removeCount){
  1572. var length = this.length;
  1573. if (pos > 0) {
  1574. if (pos > length)
  1575. pos = length;
  1576. } else if (pos == void 0) {
  1577. pos = 0;
  1578. } else if (pos < 0) {
  1579. pos = Math.max(length + pos, 0);
  1580. }
  1581. if (!(pos+removeCount < length))
  1582. removeCount = length - pos;
  1583. var removed = this.slice(pos, pos+removeCount);
  1584. var insert = slice.call(arguments, 2);
  1585. var add = insert.length;
  1586. if (pos === length) {
  1587. if (add) {
  1588. this.push.apply(this, insert);
  1589. }
  1590. } else {
  1591. var remove = Math.min(removeCount, length - pos);
  1592. var tailOldPos = pos + remove;
  1593. var tailNewPos = tailOldPos + add - remove;
  1594. var tailCount = length - tailOldPos;
  1595. var lengthAfterRemove = length - remove;
  1596. if (tailNewPos < tailOldPos) { // case A
  1597. for (var i = 0; i < tailCount; ++i) {
  1598. this[tailNewPos+i] = this[tailOldPos+i];
  1599. }
  1600. } else if (tailNewPos > tailOldPos) { // case B
  1601. for (i = tailCount; i--; ) {
  1602. this[tailNewPos+i] = this[tailOldPos+i];
  1603. }
  1604. } // else, add == remove (nothing to do)
  1605. if (add && pos === lengthAfterRemove) {
  1606. this.length = lengthAfterRemove; // truncate array
  1607. this.push.apply(this, insert);
  1608. } else {
  1609. this.length = lengthAfterRemove + add; // reserves space
  1610. for (i = 0; i < add; ++i) {
  1611. this[pos+i] = insert[i];
  1612. }
  1613. }
  1614. }
  1615. return removed;
  1616. };
  1617. }
  1618. }
  1619. if (!Array.isArray) {
  1620. Array.isArray = function isArray(obj) {
  1621. return _toString(obj) == "[object Array]";
  1622. };
  1623. }
  1624. var boxedString = Object("a"),
  1625. splitString = boxedString[0] != "a" || !(0 in boxedString);
  1626. if (!Array.prototype.forEach) {
  1627. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  1628. var object = toObject(this),
  1629. self = splitString && _toString(this) == "[object String]" ?
  1630. this.split("") :
  1631. object,
  1632. thisp = arguments[1],
  1633. i = -1,
  1634. length = self.length >>> 0;
  1635. if (_toString(fun) != "[object Function]") {
  1636. throw new TypeError(); // TODO message
  1637. }
  1638. while (++i < length) {
  1639. if (i in self) {
  1640. fun.call(thisp, self[i], i, object);
  1641. }
  1642. }
  1643. };
  1644. }
  1645. if (!Array.prototype.map) {
  1646. Array.prototype.map = function map(fun /*, thisp*/) {
  1647. var object = toObject(this),
  1648. self = splitString && _toString(this) == "[object String]" ?
  1649. this.split("") :
  1650. object,
  1651. length = self.length >>> 0,
  1652. result = Array(length),
  1653. thisp = arguments[1];
  1654. if (_toString(fun) != "[object Function]") {
  1655. throw new TypeError(fun + " is not a function");
  1656. }
  1657. for (var i = 0; i < length; i++) {
  1658. if (i in self)
  1659. result[i] = fun.call(thisp, self[i], i, object);
  1660. }
  1661. return result;
  1662. };
  1663. }
  1664. if (!Array.prototype.filter) {
  1665. Array.prototype.filter = function filter(fun /*, thisp */) {
  1666. var object = toObject(this),
  1667. self = splitString && _toString(this) == "[object String]" ?
  1668. this.split("") :
  1669. object,
  1670. length = self.length >>> 0,
  1671. result = [],
  1672. value,
  1673. thisp = arguments[1];
  1674. if (_toString(fun) != "[object Function]") {
  1675. throw new TypeError(fun + " is not a function");
  1676. }
  1677. for (var i = 0; i < length; i++) {
  1678. if (i in self) {
  1679. value = self[i];
  1680. if (fun.call(thisp, value, i, object)) {
  1681. result.push(value);
  1682. }
  1683. }
  1684. }
  1685. return result;
  1686. };
  1687. }
  1688. if (!Array.prototype.every) {
  1689. Array.prototype.every = function every(fun /*, thisp */) {
  1690. var object = toObject(this),
  1691. self = splitString && _toString(this) == "[object String]" ?
  1692. this.split("") :
  1693. object,
  1694. length = self.length >>> 0,
  1695. thisp = arguments[1];
  1696. if (_toString(fun) != "[object Function]") {
  1697. throw new TypeError(fun + " is not a function");
  1698. }
  1699. for (var i = 0; i < length; i++) {
  1700. if (i in self && !fun.call(thisp, self[i], i, object)) {
  1701. return false;
  1702. }
  1703. }
  1704. return true;
  1705. };
  1706. }
  1707. if (!Array.prototype.some) {
  1708. Array.prototype.some = function some(fun /*, thisp */) {
  1709. var object = toObject(this),
  1710. self = splitString && _toString(this) == "[object String]" ?
  1711. this.split("") :
  1712. object,
  1713. length = self.length >>> 0,
  1714. thisp = arguments[1];
  1715. if (_toString(fun) != "[object Function]") {
  1716. throw new TypeError(fun + " is not a function");
  1717. }
  1718. for (var i = 0; i < length; i++) {
  1719. if (i in self && fun.call(thisp, self[i], i, object)) {
  1720. return true;
  1721. }
  1722. }
  1723. return false;
  1724. };
  1725. }
  1726. if (!Array.prototype.reduce) {
  1727. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  1728. var object = toObject(this),
  1729. self = splitString && _toString(this) == "[object String]" ?
  1730. this.split("") :
  1731. object,
  1732. length = self.length >>> 0;
  1733. if (_toString(fun) != "[object Function]") {
  1734. throw new TypeError(fun + " is not a function");
  1735. }
  1736. if (!length && arguments.length == 1) {
  1737. throw new TypeError("reduce of empty array with no initial value");
  1738. }
  1739. var i = 0;
  1740. var result;
  1741. if (arguments.length >= 2) {
  1742. result = arguments[1];
  1743. } else {
  1744. do {
  1745. if (i in self) {
  1746. result = self[i++];
  1747. break;
  1748. }
  1749. if (++i >= length) {
  1750. throw new TypeError("reduce of empty array with no initial value");
  1751. }
  1752. } while (true);
  1753. }
  1754. for (; i < length; i++) {
  1755. if (i in self) {
  1756. result = fun.call(void 0, result, self[i], i, object);
  1757. }
  1758. }
  1759. return result;
  1760. };
  1761. }
  1762. if (!Array.prototype.reduceRight) {
  1763. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  1764. var object = toObject(this),
  1765. self = splitString && _toString(this) == "[object String]" ?
  1766. this.split("") :
  1767. object,
  1768. length = self.length >>> 0;
  1769. if (_toString(fun) != "[object Function]") {
  1770. throw new TypeError(fun + " is not a function");
  1771. }
  1772. if (!length && arguments.length == 1) {
  1773. throw new TypeError("reduceRight of empty array with no initial value");
  1774. }
  1775. var result, i = length - 1;
  1776. if (arguments.length >= 2) {
  1777. result = arguments[1];
  1778. } else {
  1779. do {
  1780. if (i in self) {
  1781. result = self[i--];
  1782. break;
  1783. }
  1784. if (--i < 0) {
  1785. throw new TypeError("reduceRight of empty array with no initial value");
  1786. }
  1787. } while (true);
  1788. }
  1789. do {
  1790. if (i in this) {
  1791. result = fun.call(void 0, result, self[i], i, object);
  1792. }
  1793. } while (i--);
  1794. return result;
  1795. };
  1796. }
  1797. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  1798. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  1799. var self = splitString && _toString(this) == "[object String]" ?
  1800. this.split("") :
  1801. toObject(this),
  1802. length = self.length >>> 0;
  1803. if (!length) {
  1804. return -1;
  1805. }
  1806. var i = 0;
  1807. if (arguments.length > 1) {
  1808. i = toInteger(arguments[1]);
  1809. }
  1810. i = i >= 0 ? i : Math.max(0, length + i);
  1811. for (; i < length; i++) {
  1812. if (i in self && self[i] === sought) {
  1813. return i;
  1814. }
  1815. }
  1816. return -1;
  1817. };
  1818. }
  1819. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  1820. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  1821. var self = splitString && _toString(this) == "[object String]" ?
  1822. this.split("") :
  1823. toObject(this),
  1824. length = self.length >>> 0;
  1825. if (!length) {
  1826. return -1;
  1827. }
  1828. var i = length - 1;
  1829. if (arguments.length > 1) {
  1830. i = Math.min(i, toInteger(arguments[1]));
  1831. }
  1832. i = i >= 0 ? i : length - Math.abs(i);
  1833. for (; i >= 0; i--) {
  1834. if (i in self && sought === self[i]) {
  1835. return i;
  1836. }
  1837. }
  1838. return -1;
  1839. };
  1840. }
  1841. if (!Object.getPrototypeOf) {
  1842. Object.getPrototypeOf = function getPrototypeOf(object) {
  1843. return object.__proto__ || (
  1844. object.constructor ?
  1845. object.constructor.prototype :
  1846. prototypeOfObject
  1847. );
  1848. };
  1849. }
  1850. if (!Object.getOwnPropertyDescriptor) {
  1851. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  1852. "non-object: ";
  1853. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  1854. if ((typeof object != "object" && typeof object != "function") || object === null)
  1855. throw new TypeError(ERR_NON_OBJECT + object);
  1856. if (!owns(object, property))
  1857. return;
  1858. var descriptor, getter, setter;
  1859. descriptor = { enumerable: true, configurable: true };
  1860. if (supportsAccessors) {
  1861. var prototype = object.__proto__;
  1862. object.__proto__ = prototypeOfObject;
  1863. var getter = lookupGetter(object, property);
  1864. var setter = lookupSetter(object, property);
  1865. object.__proto__ = prototype;
  1866. if (getter || setter) {
  1867. if (getter) descriptor.get = getter;
  1868. if (setter) descriptor.set = setter;
  1869. return descriptor;
  1870. }
  1871. }
  1872. descriptor.value = object[property];
  1873. return descriptor;
  1874. };
  1875. }
  1876. if (!Object.getOwnPropertyNames) {
  1877. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  1878. return Object.keys(object);
  1879. };
  1880. }
  1881. if (!Object.create) {
  1882. var createEmpty;
  1883. if (Object.prototype.__proto__ === null) {
  1884. createEmpty = function () {
  1885. return { "__proto__": null };
  1886. };
  1887. } else {
  1888. createEmpty = function () {
  1889. var empty = {};
  1890. for (var i in empty)
  1891. empty[i] = null;
  1892. empty.constructor =
  1893. empty.hasOwnProperty =
  1894. empty.propertyIsEnumerable =
  1895. empty.isPrototypeOf =
  1896. empty.toLocaleString =
  1897. empty.toString =
  1898. empty.valueOf =
  1899. empty.__proto__ = null;
  1900. return empty;
  1901. }
  1902. }
  1903. Object.create = function create(prototype, properties) {
  1904. var object;
  1905. if (prototype === null) {
  1906. object = createEmpty();
  1907. } else {
  1908. if (typeof prototype != "object")
  1909. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  1910. var Type = function () {};
  1911. Type.prototype = prototype;
  1912. object = new Type();
  1913. object.__proto__ = prototype;
  1914. }
  1915. if (properties !== void 0)
  1916. Object.defineProperties(object, properties);
  1917. return object;
  1918. };
  1919. }
  1920. function doesDefinePropertyWork(object) {
  1921. try {
  1922. Object.defineProperty(object, "sentinel", {});
  1923. return "sentinel" in object;
  1924. } catch (exception) {
  1925. }
  1926. }
  1927. if (Object.defineProperty) {
  1928. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  1929. var definePropertyWorksOnDom = typeof document == "undefined" ||
  1930. doesDefinePropertyWork(document.createElement("div"));
  1931. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  1932. var definePropertyFallback = Object.defineProperty;
  1933. }
  1934. }
  1935. if (!Object.defineProperty || definePropertyFallback) {
  1936. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  1937. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  1938. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  1939. "on this javascript engine";
  1940. Object.defineProperty = function defineProperty(object, property, descriptor) {
  1941. if ((typeof object != "object" && typeof object != "function") || object === null)
  1942. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  1943. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  1944. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  1945. if (definePropertyFallback) {
  1946. try {
  1947. return definePropertyFallback.call(Object, object, property, descriptor);
  1948. } catch (exception) {
  1949. }
  1950. }
  1951. if (owns(descriptor, "value")) {
  1952. if (supportsAccessors && (lookupGetter(object, property) ||
  1953. lookupSetter(object, property)))
  1954. {
  1955. var prototype = object.__proto__;
  1956. object.__proto__ = prototypeOfObject;
  1957. delete object[property];
  1958. object[property] = descriptor.value;
  1959. object.__proto__ = prototype;
  1960. } else {
  1961. object[property] = descriptor.value;
  1962. }
  1963. } else {
  1964. if (!supportsAccessors)
  1965. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  1966. if (owns(descriptor, "get"))
  1967. defineGetter(object, property, descriptor.get);
  1968. if (owns(descriptor, "set"))
  1969. defineSetter(object, property, descriptor.set);
  1970. }
  1971. return object;
  1972. };
  1973. }
  1974. if (!Object.defineProperties) {
  1975. Object.defineProperties = function defineProperties(object, properties) {
  1976. for (var property in properties) {
  1977. if (owns(properties, property))
  1978. Object.defineProperty(object, property, properties[property]);
  1979. }
  1980. return object;
  1981. };
  1982. }
  1983. if (!Object.seal) {
  1984. Object.seal = function seal(object) {
  1985. return object;
  1986. };
  1987. }
  1988. if (!Object.freeze) {
  1989. Object.freeze = function freeze(object) {
  1990. return object;
  1991. };
  1992. }
  1993. try {
  1994. Object.freeze(function () {});
  1995. } catch (exception) {
  1996. Object.freeze = (function freeze(freezeObject) {
  1997. return function freeze(object) {
  1998. if (typeof object == "function") {
  1999. return object;
  2000. } else {
  2001. return freezeObject(object);
  2002. }
  2003. };
  2004. })(Object.freeze);
  2005. }
  2006. if (!Object.preventExtensions) {
  2007. Object.preventExtensions = function preventExtensions(object) {
  2008. return object;
  2009. };
  2010. }
  2011. if (!Object.isSealed) {
  2012. Object.isSealed = function isSealed(object) {
  2013. return false;
  2014. };
  2015. }
  2016. if (!Object.isFrozen) {
  2017. Object.isFrozen = function isFrozen(object) {
  2018. return false;
  2019. };
  2020. }
  2021. if (!Object.isExtensible) {
  2022. Object.isExtensible = function isExtensible(object) {
  2023. if (Object(object) === object) {
  2024. throw new TypeError(); // TODO message
  2025. }
  2026. var name = '';
  2027. while (owns(object, name)) {
  2028. name += '?';
  2029. }
  2030. object[name] = true;
  2031. var returnValue = owns(object, name);
  2032. delete object[name];
  2033. return returnValue;
  2034. };
  2035. }
  2036. if (!Object.keys) {
  2037. var hasDontEnumBug = true,
  2038. dontEnums = [
  2039. "toString",
  2040. "toLocaleString",
  2041. "valueOf",
  2042. "hasOwnProperty",
  2043. "isPrototypeOf",
  2044. "propertyIsEnumerable",
  2045. "constructor"
  2046. ],
  2047. dontEnumsLength = dontEnums.length;
  2048. for (var key in {"toString": null}) {
  2049. hasDontEnumBug = false;
  2050. }
  2051. Object.keys = function keys(object) {
  2052. if (
  2053. (typeof object != "object" && typeof object != "function") ||
  2054. object === null
  2055. ) {
  2056. throw new TypeError("Object.keys called on a non-object");
  2057. }
  2058. var keys = [];
  2059. for (var name in object) {
  2060. if (owns(object, name)) {
  2061. keys.push(name);
  2062. }
  2063. }
  2064. if (hasDontEnumBug) {
  2065. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  2066. var dontEnum = dontEnums[i];
  2067. if (owns(object, dontEnum)) {
  2068. keys.push(dontEnum);
  2069. }
  2070. }
  2071. }
  2072. return keys;
  2073. };
  2074. }
  2075. if (!Date.now) {
  2076. Date.now = function now() {
  2077. return new Date().getTime();
  2078. };
  2079. }
  2080. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003" +
  2081. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  2082. "\u2029\uFEFF";
  2083. if (!String.prototype.trim) {
  2084. ws = "[" + ws + "]";
  2085. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  2086. trimEndRegexp = new RegExp(ws + ws + "*$");
  2087. String.prototype.trim = function trim() {
  2088. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  2089. };
  2090. }
  2091. function toInteger(n) {
  2092. n = +n;
  2093. if (n !== n) { // isNaN
  2094. n = 0;
  2095. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  2096. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  2097. }
  2098. return n;
  2099. }
  2100. function isPrimitive(input) {
  2101. var type = typeof input;
  2102. return (
  2103. input === null ||
  2104. type === "undefined" ||
  2105. type === "boolean" ||
  2106. type === "number" ||
  2107. type === "string"
  2108. );
  2109. }
  2110. function toPrimitive(input) {
  2111. var val, valueOf, toString;
  2112. if (isPrimitive(input)) {
  2113. return input;
  2114. }
  2115. valueOf = input.valueOf;
  2116. if (typeof valueOf === "function") {
  2117. val = valueOf.call(input);
  2118. if (isPrimitive(val)) {
  2119. return val;
  2120. }
  2121. }
  2122. toString = input.toString;
  2123. if (typeof toString === "function") {
  2124. val = toString.call(input);
  2125. if (isPrimitive(val)) {
  2126. return val;
  2127. }
  2128. }
  2129. throw new TypeError();
  2130. }
  2131. var toObject = function (o) {
  2132. if (o == null) { // this matches both null and undefined
  2133. throw new TypeError("can't convert "+o+" to object");
  2134. }
  2135. return Object(o);
  2136. };
  2137. });