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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user