mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
refactor globalProxy
This commit is contained in:
parent
add57d720b
commit
5e4f498dfe
2 changed files with 18 additions and 20 deletions
|
@ -4,17 +4,7 @@ import { indirectEval } from "./shared/eval";
|
|||
// import { config } from "../shared";
|
||||
import { getOwnPropertyDescriptorHandler } from "./helpers";
|
||||
|
||||
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" &&
|
||||
[
|
||||
export const UNSAFE_GLOBALS = [
|
||||
"window",
|
||||
"top",
|
||||
"self",
|
||||
|
@ -22,16 +12,20 @@ export function createGlobalProxy(
|
|||
"parent",
|
||||
"document",
|
||||
"frames",
|
||||
].includes(prop)
|
||||
)
|
||||
return client.wrapfn(self[prop]);
|
||||
|
||||
if (prop === "$scramjet") return;
|
||||
|
||||
if (prop === "eval") return indirectEval.bind(client);
|
||||
"eval",
|
||||
];
|
||||
|
||||
export function createGlobalProxy(
|
||||
client: ScramjetClient,
|
||||
self: typeof globalThis
|
||||
): typeof globalThis {
|
||||
return new Proxy(self, {
|
||||
get(target, prop) {
|
||||
const value = Reflect.get(target, prop);
|
||||
|
||||
if (typeof prop === "string" && UNSAFE_GLOBALS.includes(prop))
|
||||
return client.wrapfn(value);
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue