mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
rename eval.ts to function.ts
This commit is contained in:
parent
ab7d18f104
commit
ecbdb4177c
2 changed files with 22 additions and 45 deletions
|
@ -1,45 +0,0 @@
|
||||||
import { ScramjetClient, ProxyCtx } from "../client";
|
|
||||||
import { config, rewriteJs } from "../shared";
|
|
||||||
|
|
||||||
function rewriteFunction(ctx: ProxyCtx) {
|
|
||||||
const stringifiedFunction = ctx.fn(...ctx.args).toString();
|
|
||||||
|
|
||||||
ctx.return(ctx.fn(`return ${rewriteJs(stringifiedFunction)}`)());
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function (client: ScramjetClient, self: Self) {
|
|
||||||
client.Proxy("Function", {
|
|
||||||
apply(ctx) {
|
|
||||||
rewriteFunction(ctx);
|
|
||||||
},
|
|
||||||
|
|
||||||
construct(ctx) {
|
|
||||||
rewriteFunction(ctx);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
Function.prototype.constructor = Function;
|
|
||||||
|
|
||||||
// used for proxying *direct eval*
|
|
||||||
// eval("...") -> eval($scramjet$rewrite("..."))
|
|
||||||
Object.defineProperty(self, config.rewritefn, {
|
|
||||||
value: function (js: any) {
|
|
||||||
if (typeof js !== "string") return js;
|
|
||||||
|
|
||||||
const rewritten = rewriteJs(js, client.url);
|
|
||||||
|
|
||||||
return rewritten;
|
|
||||||
},
|
|
||||||
writable: false,
|
|
||||||
configurable: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function indirectEval(this: ScramjetClient, js: any) {
|
|
||||||
// > If the argument of eval() is not a string, eval() returns the argument unchanged
|
|
||||||
if (typeof js !== "string") return js;
|
|
||||||
|
|
||||||
const indirection = this.global.eval;
|
|
||||||
|
|
||||||
return indirection(rewriteJs(js, this.url) as string);
|
|
||||||
}
|
|
22
src/client/shared/function.ts
Normal file
22
src/client/shared/function.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { ScramjetClient, ProxyCtx } from "../client";
|
||||||
|
import { rewriteJs } from "../shared";
|
||||||
|
|
||||||
|
function rewriteFunction(ctx: ProxyCtx) {
|
||||||
|
const stringifiedFunction = ctx.fn(...ctx.args).toString();
|
||||||
|
|
||||||
|
ctx.return(ctx.fn(`return ${rewriteJs(stringifiedFunction)}`)());
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function (client: ScramjetClient, self: Self) {
|
||||||
|
client.Proxy("Function", {
|
||||||
|
apply(ctx) {
|
||||||
|
rewriteFunction(ctx);
|
||||||
|
},
|
||||||
|
|
||||||
|
construct(ctx) {
|
||||||
|
rewriteFunction(ctx);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Function.prototype.constructor = Function;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue