samples.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /// <reference path="../../node_modules/monaco-editor-core/monaco.d.ts" />
  2. define(['./generated/all-samples'], function (ALL_SAMPLES) {
  3. var XHR_SAMPLES = {};
  4. ALL_SAMPLES.forEach(function (sample) {
  5. XHR_SAMPLES[sample.name] = sample.content;
  6. });
  7. var samples = [];
  8. var modesIds = monaco.languages.getLanguages().map(function (language) {
  9. return language.id;
  10. });
  11. modesIds.sort();
  12. modesIds.forEach(function (modeId) {
  13. samples.push({
  14. name: 'sample - ' + modeId,
  15. mimeType: modeId,
  16. loadText: function () {
  17. return Promise.resolve(XHR_SAMPLES['sample.' + modeId + '.txt']);
  18. }
  19. });
  20. });
  21. function addXHRSample(name, modelUrl, mimeType, textModifier) {
  22. textModifier =
  23. textModifier ||
  24. function (text) {
  25. return text;
  26. };
  27. samples.push({
  28. name: name,
  29. mimeType: mimeType,
  30. loadText: function () {
  31. return Promise.resolve(XHR_SAMPLES[modelUrl]).then(textModifier);
  32. }
  33. });
  34. }
  35. function addStringPowerXHRSample(name, modelUrl, mimeType, power) {
  36. addXHRSample(name, modelUrl, mimeType, function (text) {
  37. var result = text;
  38. for (var i = 0; i < power; ++i) {
  39. result += '\n' + result;
  40. }
  41. return result;
  42. });
  43. }
  44. function addSample(name, mimeType, modelText) {
  45. samples.push({
  46. name: name,
  47. mimeType: mimeType,
  48. loadText: function () {
  49. return Promise.resolve(modelText);
  50. }
  51. });
  52. }
  53. addXHRSample('Y___FailingJS', 'run-editor-failing-js.txt', 'text/javascript');
  54. addXHRSample('Y___DefaultJS', 'run-editor-sample-js.txt', 'text/javascript');
  55. addStringPowerXHRSample('Y___BigJS', 'run-editor-sample-js.txt', 'text/javascript', 11);
  56. addXHRSample('Y___BigJS_msn', 'run-editor-sample-msn-js.txt', 'text/javascript');
  57. addXHRSample('Y___BigCSS', 'run-editor-sample-big-css.txt', 'text/css');
  58. addStringPowerXHRSample('Y___BigHTML', 'run-editor-sample-html.txt', 'text/html', 10);
  59. addXHRSample('Y___Korean', 'run-editor-korean.txt', 'text/plain');
  60. addXHRSample('Y___BOM.cs', 'run-editor-sample-bom-cs.txt', 'text/x-csharp');
  61. addXHRSample('Z___CR.ps1', 'run-editor-sample-cr-ps1.txt', 'text/x-powershell');
  62. addXHRSample('Z___jquery-min.js', 'run-editor-jquery-min-js.txt', 'text/javascript');
  63. addXHRSample(
  64. 'Z___scrolling-strategy.js',
  65. 'run-editor-sample-js.txt',
  66. 'text/plain',
  67. function (text) {
  68. console.log('here I am');
  69. var lines = text.split('\n');
  70. var newLines = lines.slice(0);
  71. var problemIsAt = 80733 + 5;
  72. while (newLines.length < problemIsAt) {
  73. newLines = newLines.concat(lines);
  74. }
  75. newLines = newLines.slice(0, problemIsAt);
  76. return newLines.join('\n');
  77. }
  78. );
  79. addSample(
  80. 'Z___special-chars',
  81. 'text/plain',
  82. [
  83. '// single line \u000D comment', // Carriage return
  84. '// single line \u2028 comment', // Line separator
  85. '// single line \u2029 comment' // Paragraph separator
  86. ].join('\n')
  87. );
  88. // http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
  89. addSample(
  90. 'Z___invalid-unicode',
  91. 'text/plain',
  92. [
  93. '\uFFFE\uFFFF',
  94. '\uD800\uDC00',
  95. '\uD800\uDFFF',
  96. '\uDB7F\uDC00',
  97. '\uDB7F\uDFFF',
  98. '\uDB80\uDC00',
  99. '\uDB80\uDFFF',
  100. '\uDBFF\uDC00',
  101. '\uDBFF\uDFFF'
  102. ].join('\n')
  103. );
  104. addSample(
  105. 'Z___easy-debug.js',
  106. 'text/plain',
  107. (function () {
  108. var myValue = 'Line1';
  109. for (var i = 2; i < 50; i++) {
  110. myValue += '\nLine' + i;
  111. }
  112. return myValue;
  113. })()
  114. );
  115. addSample(
  116. 'Z___copy-paste.txt',
  117. 'text/plain',
  118. (function () {
  119. var i = 0,
  120. sampleCopyPasteLine = '';
  121. while (sampleCopyPasteLine.length < 1000) {
  122. i++;
  123. sampleCopyPasteLine += i;
  124. }
  125. var sampleCopyPaste = sampleCopyPasteLine;
  126. for (i = 1; i <= 600; i++) {
  127. sampleCopyPaste += '\n' + sampleCopyPasteLine;
  128. }
  129. return sampleCopyPaste;
  130. })()
  131. );
  132. addSample(
  133. 'Z___xss',
  134. 'text/html',
  135. (function () {
  136. var xssRepresentations = [
  137. '<',
  138. 'BAD\u2028CHARACTER',
  139. '%3C',
  140. '&lt',
  141. '&lt;',
  142. '&LT',
  143. '&LT;',
  144. '&#60',
  145. '&#060',
  146. '&#0060',
  147. '&#00060',
  148. '&#000060',
  149. '&#0000060',
  150. '&#60;',
  151. '&#060;',
  152. '&#0060;',
  153. '&#00060;',
  154. '&#000060;',
  155. '&#0000060;',
  156. '&#x3c',
  157. '&#x03c',
  158. '&#x003c',
  159. '&#x0003c',
  160. '&#x00003c',
  161. '&#x000003c',
  162. '&#x3c;',
  163. '&#x03c;',
  164. '&#x003c;',
  165. '&#x0003c;',
  166. '&#x00003c;',
  167. '&#x000003c;',
  168. '&#X3c',
  169. '&#X03c',
  170. '&#X003c',
  171. '&#X0003c',
  172. '&#X00003c',
  173. '&#X000003c',
  174. '&#X3c;',
  175. '&#X03c;',
  176. '&#X003c;',
  177. '&#X0003c;',
  178. '&#X00003c;',
  179. '&#X000003c;',
  180. '&#x3C',
  181. '&#x03C',
  182. '&#x003C',
  183. '&#x0003C',
  184. '&#x00003C',
  185. '&#x000003C',
  186. '&#x3C;',
  187. '&#x03C;',
  188. '&#x003C;',
  189. '&#x0003C;',
  190. '&#x00003C;',
  191. '&#x000003C;',
  192. '&#X3C',
  193. '&#X03C',
  194. '&#X003C',
  195. '&#X0003C',
  196. '&#X00003C',
  197. '&#X000003C',
  198. '&#X3C;',
  199. '&#X03C;',
  200. '&#X003C;',
  201. '&#X0003C;',
  202. '&#X00003C;',
  203. '&#X000003C;',
  204. '\x3c',
  205. '\x3C',
  206. '\u003c',
  207. '\u003C'
  208. ];
  209. return xssRepresentations.length + ':\n' + xssRepresentations.join('\n');
  210. })()
  211. );
  212. addSample(
  213. 'Z___many-links.js',
  214. 'text/javascript',
  215. (function () {
  216. var result = 'bla bla a url: https://microsoft.com some more bla bla';
  217. for (var i = 0; i < 13; ++i) {
  218. result += '\n' + result;
  219. }
  220. return '/*' + result + '\n*/';
  221. })()
  222. );
  223. addSample(
  224. 'Z___line-separators.js',
  225. 'text/javascript',
  226. (function () {
  227. return [
  228. "var x = '1'; // And\u2028 here I have a nice comment.",
  229. '',
  230. "var y = x + ' +\u2028 2 = res';",
  231. '',
  232. "y.replace(/re\u2028s/gi, '3');"
  233. ].join('\n');
  234. })()
  235. );
  236. addXHRSample('Z___intellisense.js', 'run-editor-intellisense-js.txt', 'text/javascript');
  237. addSample(
  238. 'Z___recursion attack',
  239. 'text/html',
  240. (function () {
  241. var arr = [];
  242. for (var i = 0; i < 10000; i++) {
  243. arr.push('\n<script type="text/html">');
  244. }
  245. return arr.length + ':\n' + arr.join('');
  246. })()
  247. );
  248. addSample('empty', 'text/plain', '');
  249. addXHRSample('Z___dynamic', 'run-editor-sample-dynamic.txt', {
  250. name: 'custom.1.',
  251. tokenizer: {
  252. root: [
  253. [/\[error.*/, 'custom-error'],
  254. [/\[notice.*/, 'custom-notice'],
  255. [/\[info.*/, 'custom-info'],
  256. [/\[[a-zA-Z 0-9:]+\]/, 'custom-date']
  257. ]
  258. }
  259. });
  260. addXHRSample('Z___f12___css', 'run-editor-sample-f12-css.txt', 'text/css');
  261. return samples;
  262. });