mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-12 14:00:01 -04:00
implement direct and indirect eval
This commit is contained in:
parent
e6b237c525
commit
ec8421be8f
12 changed files with 171 additions and 101 deletions
|
@ -24,25 +24,21 @@ export function rewriteJs(js: string | ArrayBuffer, origin?: URL) {
|
|||
if ("window" in globalThis) origin ??= new URL(decodeUrl(location.href));
|
||||
|
||||
const before = performance.now();
|
||||
const cfg = {
|
||||
prefix: self.$scramjet.config.prefix,
|
||||
codec: self.$scramjet.config.codec.encode,
|
||||
wrapfn: self.$scramjet.config.wrapfn,
|
||||
trysetfn: self.$scramjet.config.trysetfn,
|
||||
importfn: self.$scramjet.config.importfn,
|
||||
rewritefn: self.$scramjet.config.rewritefn,
|
||||
};
|
||||
if (typeof js === "string") {
|
||||
js = new TextDecoder().decode(
|
||||
rewrite_js(
|
||||
js,
|
||||
origin.toString(),
|
||||
self.$scramjet.config.prefix,
|
||||
self.$scramjet.config.codec.encode as any,
|
||||
"$scramjet$wrap",
|
||||
"$scramjet$import"
|
||||
)
|
||||
);
|
||||
js = new TextDecoder().decode(rewrite_js(js, origin.toString(), cfg));
|
||||
} else {
|
||||
js = rewrite_js_from_arraybuffer(
|
||||
new Uint8Array(js),
|
||||
origin.toString(),
|
||||
self.$scramjet.config.prefix,
|
||||
self.$scramjet.config.codec.encode as any,
|
||||
"$scramjet$wrap",
|
||||
"$scramjet$import"
|
||||
cfg
|
||||
);
|
||||
}
|
||||
const after = performance.now();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue