use rewriter wasm directly

This commit is contained in:
Toshit Chawda 2025-02-21 17:24:09 -08:00
parent 1070e68dcf
commit a69755936d
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
7 changed files with 45 additions and 24 deletions

View file

@ -9,11 +9,16 @@ import {
} from "../../../rewriter/wasm/out/wasm.js";
import { $scramjet, flagEnabled } from "../../scramjet";
initSync({
module: new WebAssembly.Module(
Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0))
),
});
if (self.WASM)
self.REAL_WASM = Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0));
// only use in sw
export async function asyncInitRewriter() {
const buf = await fetch($scramjet.config.files.wasm).then((r) =>
r.arrayBuffer()
);
self.REAL_WASM = new Uint8Array(buf);
}
Error.stackTraceLimit = 50;
@ -25,6 +30,10 @@ function rewriteJsWrapper(
meta: URLMeta,
module: boolean
): string | ArrayBuffer {
initSync({
module: new WebAssembly.Module(self.REAL_WASM),
});
let out: RewriterOutput;
const before = performance.now();
try {