mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
rest of the function proxies
This commit is contained in:
parent
aafcbeb5e4
commit
ae7acfada2
1 changed files with 23 additions and 6 deletions
|
@ -1,22 +1,39 @@
|
||||||
import { ScramjetClient, ProxyCtx } from "../client";
|
import { ScramjetClient, ProxyCtx, Proxy } from "../client";
|
||||||
import { rewriteJs } from "../shared";
|
import { rewriteJs } from "../shared";
|
||||||
|
|
||||||
function rewriteFunction(ctx: ProxyCtx) {
|
function rewriteFunction(ctx: ProxyCtx) {
|
||||||
const stringifiedFunction = ctx.fn(...ctx.args).toString();
|
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) {
|
export default function (client: ScramjetClient, self: Self) {
|
||||||
client.Proxy("Function", {
|
const handler: Proxy = {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
rewriteFunction(ctx);
|
rewriteFunction(ctx);
|
||||||
},
|
},
|
||||||
|
|
||||||
construct(ctx) {
|
construct(ctx) {
|
||||||
rewriteFunction(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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue