debt - more promise cleanup

This commit is contained in:
Johannes Rieken 2019-02-08 15:19:17 +01:00
parent a404c91e22
commit 70e48eeb52
5 changed files with 386 additions and 392 deletions

View file

@ -1,40 +1,40 @@
/// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />
define(['./samples-all.generated'], function(ALL_SAMPLES) {
define(['./samples-all.generated'], function (ALL_SAMPLES) {
var XHR_SAMPLES = {};
ALL_SAMPLES.forEach(function(sample) {
ALL_SAMPLES.forEach(function (sample) {
XHR_SAMPLES[sample.name] = sample.content;
});
var samples = [];
var modesIds = monaco.languages.getLanguages().map(function(language) { return language.id; });
var modesIds = monaco.languages.getLanguages().map(function (language) { return language.id; });
modesIds.sort();
modesIds.forEach(function(modeId) {
modesIds.forEach(function (modeId) {
samples.push({
name: 'sample - ' + modeId,
mimeType: modeId,
loadText: function() {
return monaco.Promise.as(XHR_SAMPLES['sample.' + modeId + '.txt']);
loadText: function () {
return Promise.resolve(XHR_SAMPLES['sample.' + modeId + '.txt']);
}
});
});
function addXHRSample(name, modelUrl, mimeType, textModifier) {
textModifier = textModifier || function(text) { return text; };
textModifier = textModifier || function (text) { return text; };
samples.push({
name: name,
mimeType: mimeType,
loadText: function() {
return monaco.Promise.as(XHR_SAMPLES[modelUrl]).then(textModifier);
loadText: function () {
return Promise.resolve(XHR_SAMPLES[modelUrl]).then(textModifier);
}
});
}
function addStringPowerXHRSample(name, modelUrl, mimeType, power) {
addXHRSample(name, modelUrl, mimeType, function(text) {
addXHRSample(name, modelUrl, mimeType, function (text) {
var result = text;
for (var i = 0; i < power; ++i) {
result += "\n" + result;
@ -47,8 +47,8 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
samples.push({
name: name,
mimeType: mimeType,
loadText: function() {
return monaco.Promise.as(modelText);
loadText: function () {
return Promise.resolve(modelText);
}
});
}
@ -65,7 +65,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
addXHRSample('Z___jquery-min.js', 'run-editor-jquery-min-js.txt', 'text/javascript');
addXHRSample('Z___scrolling-strategy.js', 'run-editor-sample-js.txt', 'text/plain', function(text) {
addXHRSample('Z___scrolling-strategy.js', 'run-editor-sample-js.txt', 'text/plain', function (text) {
console.log('here I am');
var lines = text.split('\n');
var newLines = lines.slice(0);
@ -98,7 +98,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
'\uDBFF\uDFFF'
].join('\n'));
addSample('Z___easy-debug.js', 'text/plain', (function() {
addSample('Z___easy-debug.js', 'text/plain', (function () {
var myValue = "Line1";
for (var i = 2; i < 50; i++) {
myValue += "\nLine" + i;
@ -106,7 +106,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
return myValue;
})());
addSample('Z___copy-paste.txt', 'text/plain', (function() {
addSample('Z___copy-paste.txt', 'text/plain', (function () {
var i = 0, sampleCopyPasteLine = '';
while (sampleCopyPasteLine.length < 1000) {
i++;
@ -119,7 +119,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
return sampleCopyPaste;
})());
addSample('Z___xss', 'text/html', (function() {
addSample('Z___xss', 'text/html', (function () {
var xssRepresentations = [
'<',
'BAD\u2028CHARACTER',
@ -196,7 +196,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
return xssRepresentations.length + ':\n' + xssRepresentations.join('\n');
})());
addSample('Z___many-links.js', 'text/javascript', (function() {
addSample('Z___many-links.js', 'text/javascript', (function () {
var result = "bla bla a url: https://microsoft.com some more bla bla";
for (var i = 0; i < 13; ++i) {
result += "\n" + result;
@ -204,7 +204,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
return "/*" + result + "\n*/";
})());
addSample('Z___line-separators.js', 'text/javascript', (function() {
addSample('Z___line-separators.js', 'text/javascript', (function () {
return [
"var x = '1'; // And\u2028 here I have a nice comment.",
"",
@ -216,7 +216,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
addXHRSample('Z___intellisense.js', 'run-editor-intellisense-js.txt', 'text/javascript');
addSample('Z___recursion attack', 'text/html', (function() {
addSample('Z___recursion attack', 'text/html', (function () {
var arr = [];
for (var i = 0; i < 10000; i++) {
arr.push('\n<script type="text/html">');
@ -238,7 +238,7 @@ define(['./samples-all.generated'], function(ALL_SAMPLES) {
}
});
addXHRSample('Z___f12___css','run-editor-sample-f12-css.txt','text/css');
addXHRSample('Z___f12___css', 'run-editor-sample-f12-css.txt', 'text/css');
return samples;
});