rest of the function proxies

This commit is contained in:
velzie 2024-07-31 14:05:33 -04:00
parent aafcbeb5e4
commit ae7acfada2
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F

View file

@ -1,22 +1,39 @@
import { ScramjetClient, ProxyCtx } from "../client";
import { ScramjetClient, ProxyCtx, Proxy } from "../client";
import { rewriteJs } from "../shared";
function rewriteFunction(ctx: ProxyCtx) {
const stringifiedFunction = ctx.fn(...ctx.args).toString();
ctx.return(ctx.fn(`return ${rewriteJs(stringifiedFunction)}`)());
ctx.return(Function(`return ${rewriteJs(stringifiedFunction)}`)());
}
export default function (client: ScramjetClient, self: Self) {
client.Proxy("Function", {
const handler: Proxy = {
apply(ctx) {
rewriteFunction(ctx);
},
construct(ctx) {
rewriteFunction(ctx);
},
});
};
Function.prototype.constructor = Function;
client.Proxy("Function", handler);
// god i love javascript
client.RawProxy(function () {}.constructor.prototype, "constructor", handler);
client.RawProxy(
async function () {}.constructor.prototype,
"constructor",
handler
);
client.RawProxy(
function* () {}.constructor.prototype,
"constructor",
handler
);
client.RawProxy(
async function* () {}.constructor.prototype,
"constructor",
handler
);
}