mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 07:20:02 -04:00
refactor wrap
This commit is contained in:
parent
e04a719140
commit
490d4c96f5
2 changed files with 7 additions and 13 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue