make it work with variables too

This commit is contained in:
Jonathan Rainville 2018-08-22 14:09:10 -04:00
parent 8ebe55f457
commit a0b06c6197

View File

@ -41,9 +41,19 @@ class CodeRunner {
if (!cb) { if (!cb) {
cb = function() {}; cb = function() {};
} }
if (code.startsWith('await')) { const awaitIdx = code.indexOf('await');
code = code.substring(5); // remove await keyword if (awaitIdx > -1) {
code += '.then(console.log).catch(console.error)'; // Add promise catch let end = code.length;
if (code[end - 1] === ';') {
end--; // Remove the `;` because we add function calls
}
if (awaitIdx < 2) {
code = code.substring(5, end); // remove await keyword
code += '.then(console.log).catch(console.error);'; // Add promise catch
} else {
code = code.substring(0, end); // remove ending `;`
code = `(async function() {${code}.then(console.log);})();`;
}
} }
let result = RunCode.doEval(code); let result = RunCode.doEval(code);
if (forConsoleOnly && self.ipc.isServer()) { if (forConsoleOnly && self.ipc.isServer()) {