mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-21 10:38:37 +00:00
use Function instead of eval
- fixes scope issues (e.g. seq duplication) - should be much safer and much faster
This commit is contained in:
parent
1cbf4c8c7e
commit
273cb81da0
@ -15,9 +15,13 @@ export const extend = (...args) => {
|
|||||||
Object.assign(globalThis, ...args);
|
Object.assign(globalThis, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function safeEval(str) {
|
||||||
|
return Function('"use strict";return (' + str + ')')();
|
||||||
|
}
|
||||||
|
|
||||||
export const evaluate = async (code) => {
|
export const evaluate = async (code) => {
|
||||||
const shapeshifted = shapeshifter(code); // transform syntactically correct js code to semantically usable code
|
const shapeshifted = shapeshifter(code); // transform syntactically correct js code to semantically usable code
|
||||||
let evaluated = await eval(shapeshifted);
|
let evaluated = await safeEval(shapeshifted);
|
||||||
if (!isPattern(evaluated)) {
|
if (!isPattern(evaluated)) {
|
||||||
console.log('evaluated', evaluated);
|
console.log('evaluated', evaluated);
|
||||||
const message = `got "${typeof evaluated}" instead of pattern`;
|
const message = `got "${typeof evaluated}" instead of pattern`;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user