samples.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 monaco.Promise.as(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 monaco.Promise.as(XHR_SAMPLES[modelUrl]);
  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 monaco.Promise.as(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. var lines = text.split('\n');
  59. var newLines = lines.slice(0);
  60. var problemIsAt = 80733 + 5;
  61. while (newLines.length < problemIsAt) {
  62. newLines = newLines.concat(lines);
  63. }
  64. newLines = newLines.slice(0, problemIsAt);
  65. return newLines.join('\n');
  66. });
  67. addSample('Z___special-chars', 'text/plain', [
  68. "// single line \u000D comment", // Carriage return
  69. "// single line \u2028 comment", // Line separator
  70. "// single line \u2029 comment" // Paragraph separator
  71. ].join('\n'));
  72. // http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
  73. addSample('Z___invalid-unicode', 'text/plain', [
  74. '\uFFFE\uFFFF',
  75. '\uD800\uDC00',
  76. '\uD800\uDFFF',
  77. '\uDB7F\uDC00',
  78. '\uDB7F\uDFFF',
  79. '\uDB80\uDC00',
  80. '\uDB80\uDFFF',
  81. '\uDBFF\uDC00',
  82. '\uDBFF\uDFFF'
  83. ].join('\n'));
  84. addSample('Z___easy-debug.js', 'text/plain', (function() {
  85. var myValue = "Line1";
  86. for (var i = 2; i < 50; i++) {
  87. myValue += "\nLine" + i;
  88. }
  89. return myValue;
  90. })());
  91. addSample('Z___copy-paste.txt', 'text/plain', (function() {
  92. var i = 0, sampleCopyPasteLine = '';
  93. while (sampleCopyPasteLine.length < 1000) {
  94. i++;
  95. sampleCopyPasteLine += i;
  96. }
  97. var sampleCopyPaste = sampleCopyPasteLine;
  98. for (i = 1; i <= 600; i++) {
  99. sampleCopyPaste += '\n' + sampleCopyPasteLine;
  100. }
  101. return sampleCopyPaste;
  102. })());
  103. addSample('Z___xss', 'text/html', (function() {
  104. var xssRepresentations = [
  105. '<',
  106. 'BAD\u2028CHARACTER',
  107. '%3C',
  108. '&lt',
  109. '&lt;',
  110. '&LT',
  111. '&LT;',
  112. '&#60',
  113. '&#060',
  114. '&#0060',
  115. '&#00060',
  116. '&#000060',
  117. '&#0000060',
  118. '&#60;',
  119. '&#060;',
  120. '&#0060;',
  121. '&#00060;',
  122. '&#000060;',
  123. '&#0000060;',
  124. '&#x3c',
  125. '&#x03c',
  126. '&#x003c',
  127. '&#x0003c',
  128. '&#x00003c',
  129. '&#x000003c',
  130. '&#x3c;',
  131. '&#x03c;',
  132. '&#x003c;',
  133. '&#x0003c;',
  134. '&#x00003c;',
  135. '&#x000003c;',
  136. '&#X3c',
  137. '&#X03c',
  138. '&#X003c',
  139. '&#X0003c',
  140. '&#X00003c',
  141. '&#X000003c',
  142. '&#X3c;',
  143. '&#X03c;',
  144. '&#X003c;',
  145. '&#X0003c;',
  146. '&#X00003c;',
  147. '&#X000003c;',
  148. '&#x3C',
  149. '&#x03C',
  150. '&#x003C',
  151. '&#x0003C',
  152. '&#x00003C',
  153. '&#x000003C',
  154. '&#x3C;',
  155. '&#x03C;',
  156. '&#x003C;',
  157. '&#x0003C;',
  158. '&#x00003C;',
  159. '&#x000003C;',
  160. '&#X3C',
  161. '&#X03C',
  162. '&#X003C',
  163. '&#X0003C',
  164. '&#X00003C',
  165. '&#X000003C',
  166. '&#X3C;',
  167. '&#X03C;',
  168. '&#X003C;',
  169. '&#X0003C;',
  170. '&#X00003C;',
  171. '&#X000003C;',
  172. '\x3c',
  173. '\x3C',
  174. '\u003c',
  175. '\u003C'
  176. ];
  177. return xssRepresentations.length + ':\n' + xssRepresentations.join('\n');
  178. })());
  179. addSample('Z___many-links.js', 'text/javascript', (function() {
  180. var result = "bla bla a url: https://microsoft.com some more bla bla";
  181. for (var i = 0; i < 13; ++i) {
  182. result += "\n" + result;
  183. }
  184. return "/*" + result + "\n*/";
  185. })());
  186. addSample('Z___line-separators.js', 'text/javascript', (function() {
  187. return [
  188. "var x = '1'; // And\u2028 here I have a nice comment.",
  189. "",
  190. "var y = x + ' +\u2028 2 = res';",
  191. "",
  192. "y.replace(/re\u2028s/gi, '3');"
  193. ].join('\n');
  194. })());
  195. addXHRSample('Z___intellisense.js', 'run-editor-intellisense-js.txt', 'text/javascript');
  196. addSample('Z___recursion attack', 'text/html', (function() {
  197. var arr = [];
  198. for (var i = 0; i < 10000; i++) {
  199. arr.push('\n<script type="text/html">');
  200. }
  201. return arr.length + ':\n' + arr.join('');
  202. })());
  203. addSample('empty', 'text/plain', '');
  204. addXHRSample('Z___dynamic', 'run-editor-sample-dynamic.txt', {
  205. name: 'custom.1.',
  206. tokenizer: {
  207. root: [
  208. [/\[error.*/, "custom-error"],
  209. [/\[notice.*/, "custom-notice"],
  210. [/\[info.*/, "custom-info"],
  211. [/\[[a-zA-Z 0-9:]+\]/, "custom-date"],
  212. ],
  213. }
  214. });
  215. addXHRSample('Z___f12___css','run-editor-sample-f12-css.txt','text/css');
  216. return samples;
  217. });