File size: 1,067 Bytes
bee6636 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import { rewriteJs } from "../../shared/rewriters/js";
import { ScramjetClient, ProxyCtx, Proxy } from "../client";
function rewriteFunction(ctx: ProxyCtx, client: ScramjetClient) {
const stringifiedFunction = ctx.call().toString();
const content = rewriteJs(
stringifiedFunction,
"(function proxy)",
client.meta
);
ctx.return(ctx.fn(`return ${content}`)());
}
export default function (client: ScramjetClient, _self: Self) {
const handler: Proxy = {
apply(ctx: ProxyCtx) {
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
);
*/
}
|