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,6 @@
import { iswindow } from "..";
import { ScramjetClient } from "../client";
import { unproxy } from "./unproxy";
const realOnEvent = Symbol.for("scramjet original onevent function");
@ -45,6 +46,7 @@ export default function (client: ScramjetClient, self: Self) {
client.Proxy("EventTarget.prototype.addEventListener", {
apply(ctx) {
unproxy(ctx, client);
if (typeof ctx.args[1] === "object")
ctx.args[1] = wraplistener(ctx.args[1]);
},

View file

@ -2,12 +2,12 @@ import { isworker } from "../..";
import { ScramjetClient } from "../../client";
import { BareClient } from "../../shared";
const bare = new BareClient();
export default function (client: ScramjetClient, self: typeof globalThis) {
// r58 please fix
if (isworker) return;
const bare = new BareClient();
client.Proxy("WebSocket", {
construct(ctx) {
ctx.return(

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;
}
}