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