mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-12 22:10:01 -04:00
40 lines
962 B
TypeScript
40 lines
962 B
TypeScript
import { ScramjetClient, ProxyCtx, Proxy } from "../client";
|
|
import { rewriteJs } from "../../shared";
|
|
|
|
function rewriteFunction(ctx: ProxyCtx, client: ScramjetClient) {
|
|
const stringifiedFunction = ctx.call().toString();
|
|
|
|
const content = rewriteJs(`return ${stringifiedFunction}`, client.meta);
|
|
ctx.return(ctx.fn(content)());
|
|
}
|
|
|
|
export default function (client: ScramjetClient, self: Self) {
|
|
const handler: Proxy = {
|
|
apply(ctx) {
|
|
rewriteFunction(ctx, client);
|
|
},
|
|
construct(ctx) {
|
|
rewriteFunction(ctx, client);
|
|
},
|
|
};
|
|
|
|
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
|
|
);
|
|
}
|