mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
Function constructor proxy
This commit is contained in:
parent
c2d147442e
commit
d043ad0032
2 changed files with 23 additions and 37 deletions
|
@ -1,38 +1,24 @@
|
|||
export default function (client, self) {}
|
||||
|
||||
/*
|
||||
import { ScramjetClient, ProxyCtx } from "../client";
|
||||
import { rewriteJs } from "../shared";
|
||||
|
||||
const FunctionProxy = new Proxy(Function, {
|
||||
construct(target, argArray) {
|
||||
if (argArray.length === 1) {
|
||||
return Reflect.construct(target, rewriteJs(argArray[0]));
|
||||
} else {
|
||||
return Reflect.construct(
|
||||
target,
|
||||
rewriteJs(argArray[argArray.length - 1])
|
||||
);
|
||||
function rewriteFunction(ctx: ProxyCtx) {
|
||||
for (const i in ctx.args) {
|
||||
ctx.args[i] = rewriteJs(ctx.args[i]);
|
||||
}
|
||||
},
|
||||
apply(target, thisArg, argArray) {
|
||||
if (argArray.length === 1) {
|
||||
return Reflect.apply(target, undefined, [rewriteJs(argArray[0])]);
|
||||
} else {
|
||||
return Reflect.apply(target, undefined, [
|
||||
...argArray.map((x, index) => index === argArray.length - 1),
|
||||
rewriteJs(argArray[argArray.length - 1]),
|
||||
]);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
delete window.Function;
|
||||
ctx.return(ctx.fn(...ctx.args));
|
||||
}
|
||||
|
||||
window.Function = FunctionProxy;
|
||||
export default function (client: ScramjetClient, self: Self) {
|
||||
client.Proxy("Function", {
|
||||
apply(ctx) {
|
||||
rewriteFunction(ctx);
|
||||
},
|
||||
|
||||
window.eval = new Proxy(window.eval, {
|
||||
apply(target, thisArg, argArray) {
|
||||
return Reflect.apply(target, thisArg, [rewriteJs(argArray[0])]);
|
||||
},
|
||||
});
|
||||
*/
|
||||
construct(ctx) {
|
||||
rewriteFunction(ctx);
|
||||
},
|
||||
});
|
||||
|
||||
Function.prototype.constructor = Function;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue