Refactor velzie's global proxy refactor in a way that doesn't break things (i think)

This commit is contained in:
wearrrrr 2024-10-12 22:57:46 -05:00
parent 4128bc778a
commit a3cb21a500

View file

@ -2,6 +2,7 @@
import { ScramjetClient } from "./client";
// import { config } from "../shared";
import { getOwnPropertyDescriptorHandler } from "./helpers";
import { indirectEval } from "./shared/eval";
export const UNSAFE_GLOBALS = [
"window",
@ -20,8 +21,12 @@ export function createGlobalProxy(
): typeof globalThis {
return new Proxy(self, {
get(target, prop) {
const value = Reflect.get(target, prop);
if (prop === "location") return client.locationProxy;
if (typeof prop === "string" && UNSAFE_GLOBALS.includes(prop)) return client.wrapfn(self[prop]);
if (prop === "$scramjet") return;
if (prop === "eval") return indirectEval.bind(client);
const value = Reflect.get(target, prop);
if (typeof prop === "string" && UNSAFE_GLOBALS.includes(prop))
return client.wrapfn(value);