fix un proxy jank

This commit is contained in:
velzie 2024-07-30 14:16:17 -04:00
parent 98422f736d
commit 0fef6e8853
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
3 changed files with 18 additions and 13 deletions

View file

@ -1,5 +1,5 @@
import { iswindow } from "..";
import { ScramjetClient } from "../client";
import { ProxyCtx, ScramjetClient } from "../client";
export default function (client: ScramjetClient, self: typeof window) {
// an automated approach to cleaning the documentProxy from dom functions
@ -11,11 +11,7 @@ export default function (client: ScramjetClient, self: typeof window) {
if (typeof target[prop] === "function") {
client.RawProxy(target, prop, {
apply(ctx) {
if (ctx.this == client.windowProxy) ctx.this = self;
for (const i in ctx.args) {
if (ctx.args[i] === client.windowProxy)
ctx.args[i] = self.global;
}
unproxy(ctx, client);
},
});
}
@ -35,11 +31,7 @@ export default function (client: ScramjetClient, self: typeof window) {
if (typeof target[prop] === "function") {
client.RawProxy(target, prop, {
apply(ctx) {
for (const i in ctx.args) {
if (ctx.args[i] === client.documentProxy)
ctx.args[i] = self.document;
if (ctx.this === client.documentProxy) ctx.this = self.document;
}
unproxy(ctx, client);
},
});
}
@ -47,3 +39,14 @@ export default function (client: ScramjetClient, self: typeof window) {
}
}
}
export function unproxy(ctx: ProxyCtx, client: ScramjetClient) {
const self = client.global;
if (ctx.this === client.windowProxy) ctx.this = self;
if (ctx.this === client.documentProxy) ctx.this = self.document;
for (const i in ctx.args) {
if (ctx.args[i] === client.documentProxy) ctx.args[i] = self.document;
if (ctx.args[i] === client.windowProxy) ctx.args[i] = self;
}
}