mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-11 06:25:57 +00:00
make it work with variables too
This commit is contained in:
parent
8ebe55f457
commit
a0b06c6197
@ -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()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user