samples.js 6.1 KB

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