make it work with variables too
This commit is contained in:
parent
8ebe55f457
commit
a0b06c6197
|
@ -41,9 +41,19 @@ class CodeRunner {
|
|||
if (!cb) {
|
||||
cb = function() {};
|
||||
}
|
||||
if (code.startsWith('await')) {
|
||||
code = code.substring(5); // remove await keyword
|
||||
code += '.then(console.log).catch(console.error)'; // Add promise catch
|
||||
const awaitIdx = code.indexOf('await');
|
||||
if (awaitIdx > -1) {
|
||||
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);
|
||||
if (forConsoleOnly && self.ipc.isServer()) {
|
||||
|
|
Loading…
Reference in New Issue