mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 15:30:00 -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 = [
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue