mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
use unproxy instead of replacing this on the windowprxy
This commit is contained in:
parent
12b17bc3b4
commit
7289a329c4
4 changed files with 50 additions and 41 deletions
|
@ -174,27 +174,4 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
return ctx.set(value);
|
||||
},
|
||||
});
|
||||
|
||||
// an automated approach to cleaning the documentProxy from dom functions
|
||||
// it will trigger an illegal invocation if you pass the proxy to c++ code, we gotta hotswap it out with the real one
|
||||
for (const target of [
|
||||
self.Node.prototype,
|
||||
self.MutationObserver.prototype,
|
||||
self.document,
|
||||
]) {
|
||||
for (const prop in target) {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
49
src/client/shared/unproxy.ts
Normal file
49
src/client/shared/unproxy.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { iswindow } from "..";
|
||||
import { ScramjetClient } from "../client";
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof window) {
|
||||
// an automated approach to cleaning the documentProxy from dom functions
|
||||
// it will trigger an illegal invocation if you pass the proxy to c++ code, we gotta hotswap it out with the real one
|
||||
|
||||
for (const target of [self]) {
|
||||
for (const prop in target) {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (!iswindow) return;
|
||||
|
||||
for (const target of [
|
||||
self.Node.prototype,
|
||||
self.MutationObserver.prototype,
|
||||
self.document,
|
||||
]) {
|
||||
for (const prop in target) {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -89,7 +89,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
}
|
||||
}
|
||||
self.$scramerr = function scramerr(e) {
|
||||
// console.error("CAUGHT ERROR", e);
|
||||
// console.warn("CAUGHT ERROR", e);
|
||||
};
|
||||
|
||||
self.$scramdbg = function scramdbg(args, t) {
|
||||
|
|
|
@ -24,15 +24,6 @@ export function createWindowProxy(
|
|||
|
||||
const value = Reflect.get(target, prop);
|
||||
|
||||
// this is bad! i don't know what the right thing to do is
|
||||
if (typeof value === "function") {
|
||||
return new Proxy(value, {
|
||||
apply(_target, thisArg, argArray) {
|
||||
return value.apply(self, argArray);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
|
@ -74,14 +65,6 @@ export function createDocumentProxy(
|
|||
|
||||
const value = Reflect.get(target, prop);
|
||||
|
||||
if (typeof value === "function") {
|
||||
return new Proxy(value, {
|
||||
apply(_target, thisArg, argArray) {
|
||||
return value.apply(self.document, argArray);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
set(target, prop, newValue) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue