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 = [ export const UNSAFE_GLOBALS = [
"window", "window",
"top",
"self", "self",
"globalThis", "globalThis",
"this",
"parent", "parent",
"top",
"location",
"document", "document",
"frames",
"eval", "eval",
"frames",
]; ];
export function createGlobalProxy( export function createGlobalProxy(
@ -21,21 +23,17 @@ export function createGlobalProxy(
): typeof globalThis { ): typeof globalThis {
return new Proxy(self, { return new Proxy(self, {
get(target, prop) { 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); const value = Reflect.get(target, prop);
if (typeof prop === "string" && UNSAFE_GLOBALS.includes(prop))
return client.wrapfn(value);
return value; return value;
}, },
set(target, prop, value) { set(target, prop, value) {
if (prop === "location") { if (prop === "location") {
client.url = value; client.url = value;
return; return;
} }

View file

@ -7,10 +7,6 @@ import { indirectEval } from "./eval";
export function createWrapFn(client: ScramjetClient, self: typeof globalThis) { export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
return function (identifier: any, args: any) { return function (identifier: any, args: any) {
if (args && typeof args === "object" && args.length === 0)
for (const arg of args) {
// argdbg(arg);
}
if (iswindow && identifier instanceof self.Window) { if (iswindow && identifier instanceof self.Window) {
return client.globalProxy; return client.globalProxy;
} else if (iswindow && identifier instanceof self.parent.self.Window) { } else if (iswindow && identifier instanceof self.parent.self.Window) {