1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-12-20 23:18:57 +00:00

test wasm

This commit is contained in:
c-basalt
2025-01-02 00:17:10 -05:00
parent e8eb983583
commit e0697299b6
4 changed files with 303 additions and 18 deletions

View File

@@ -109,3 +109,26 @@ def extract_script_tags(html: str) -> tuple[str, list[str]]:
html = html[:start] + html[end:]
return html, inline_scripts
def prepare_wasm_jsmodule(js_mod: str, wasm: bytes) -> str:
"""
Prepare wasm init for js wrapper module generated by rust wasm-pack
removes export and import.meta and inlines wasm binary as Uint8Array
See test/test_data/jsi_external/hello_wasm.js for example
@param {str} js_mod: js wrapper module generated by rust wasm-pack
@param {bytes} wasm: wasm binary
"""
js_mod = re.sub(r'export(?:\s+default)?([\s{])', r'\1', js_mod)
js_mod = js_mod.replace('import.meta', '{}')
return js_mod + ''';
await (async () => {
const t = __wbg_get_imports();
__wbg_init_memory(t);
const {module, instance} = await WebAssembly.instantiate(Uint8Array.from(%s), t);
__wbg_finalize_init(instance, module);
})();
''' % list(wasm)