refactor wrap

This commit is contained in:
velzie 2024-10-14 10:28:22 -04:00
parent e04a719140
commit 490d4c96f5
No known key found for this signature in database
GPG key ID: AA51AEFB0A1F3820
2 changed files with 7 additions and 13 deletions

View file

@ -6,13 +6,15 @@ import { indirectEval } from "./shared/eval";
export const UNSAFE_GLOBALS = [
"window",
"top",
"self",
"globalThis",
"this",
"parent",
"top",
"location",
"document",
"frames",
"eval",
"frames",
];
export function createGlobalProxy(
@ -21,21 +23,17 @@ export function createGlobalProxy(
): typeof globalThis {
return new Proxy(self, {
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);
return value;
},
set(target, prop, value) {
if (prop === "location") {
client.url = value;
return;
}