Able to eval js with my scope!
This commit is contained in:
31
cart_tools.ts
Normal file
31
cart_tools.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user