mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
eval.ts
This commit is contained in:
parent
ecbdb4177c
commit
eaea40bfee
1 changed files with 28 additions and 0 deletions
28
src/client/shared/eval.ts
Normal file
28
src/client/shared/eval.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { rewriteJs } from "../../shared/rewriters/js";
|
||||
import { ScramjetClient } from "../client";
|
||||
import { config } from "../shared";
|
||||
|
||||
export default function (client: ScramjetClient, self: Self) {
|
||||
// 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue