From ae7acfada2dc786fed683712746bad90e58a9895 Mon Sep 17 00:00:00 2001 From: velzie Date: Wed, 31 Jul 2024 14:05:33 -0400 Subject: [PATCH] rest of the function proxies --- src/client/shared/function.ts | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/client/shared/function.ts b/src/client/shared/function.ts index c85866f..df07410 100644 --- a/src/client/shared/function.ts +++ b/src/client/shared/function.ts @@ -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 + ); }