Able to eval js with my scope!

This commit is contained in:
dylan
2023-05-01 18:42:55 -07:00
parent 5d742d5964
commit a7b675d541
7 changed files with 67 additions and 4 deletions

31
cart_tools.ts Normal file
View File

@@ -0,0 +1,31 @@
import faux from "./builtins.ts";
export type SheetType = "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts";
export const parseCodeSheet = (sheet: string) => {
try {
new Function(sheet);
} catch (err) {
throw err;
}
// deno-lint-ignore no-explicit-any
const G: any = {...faux, faux, log: console.log};
const context = new Proxy(G, {
get: (target, prop) => {
return target[prop];
},
set: (target, prop, value) => {
target[prop] = value;
return true;
},
has: () => {
return true;
},
});
const fn = new Function("context", `
with (context) {
${sheet}
}
`);
return fn(context);
}