From 5e4f498dfee41f47510cfe510900552fdafa5f75 Mon Sep 17 00:00:00 2001 From: velzie Date: Sat, 12 Oct 2024 22:45:12 -0400 Subject: [PATCH] refactor globalProxy --- src/client/global.ts | 34 ++++++++++++++-------------------- src/client/shared/wrap.ts | 4 ++++ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/client/global.ts b/src/client/global.ts index d083ef9..d294b7b 100644 --- a/src/client/global.ts +++ b/src/client/global.ts @@ -4,34 +4,28 @@ import { indirectEval } from "./shared/eval"; // import { config } from "../shared"; import { getOwnPropertyDescriptorHandler } from "./helpers"; +export const UNSAFE_GLOBALS = [ + "window", + "top", + "self", + "globalThis", + "parent", + "document", + "frames", + "eval", +]; + export function createGlobalProxy( client: ScramjetClient, self: typeof globalThis ): typeof globalThis { return new Proxy(self, { get(target, prop) { - if (prop === "location") return client.locationProxy; - - if ( - typeof prop === "string" && - [ - "window", - "top", - "self", - "globalThis", - "parent", - "document", - "frames", - ].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); + return value; }, diff --git a/src/client/shared/wrap.ts b/src/client/shared/wrap.ts index d2033b2..596ffd0 100644 --- a/src/client/shared/wrap.ts +++ b/src/client/shared/wrap.ts @@ -3,6 +3,7 @@ import { SCRAMJETCLIENT } from "../../symbols"; import { ScramjetClient } from "../client"; import { config } from "../../shared"; import { argdbg } from "./err"; +import { indirectEval } from "./eval"; export function createWrapFn(client: ScramjetClient, self: typeof globalThis) { return function (identifier: any, args: any) { @@ -46,6 +47,9 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) { } else if (isworker && identifier instanceof self.WorkerGlobalScope) { return client.globalProxy; } + if (identifier == self.eval) { + return indirectEval.bind(client); + } return identifier; };