--- a/src/js/compat.ts +++ b/src/js/compat.ts @@ -192,9 +192,10 @@ } export async function loadBinaryFile( - path: string, + path: string | Uint8Array, file_sub_resource_hash?: string | undefined, ): Promise { + if (path instanceof Uint8Array) return path; const { response, binary } = getBinaryResponse(path, file_sub_resource_hash); if (binary) { return binary; --- a/src/js/emscripten-settings.ts +++ b/src/js/emscripten-settings.ts @@ -70,7 +70,7 @@ // means dependency resolution has already failed and we want to throw an // error anyways. locateFile: (path: string) => config.indexURL + path, - instantiateWasm: getInstantiateWasmFunc(config.indexURL), + instantiateWasm: getInstantiateWasmFunc(config.indexURL, config.qlcWasmBytes), }; return settings; } @@ -146,7 +146,7 @@ * * @param stdlibURL The URL for the Python standard library */ -function installStdlib(stdlibURL: string): PreRunFunc { +function installStdlib(stdlibURL: string | Uint8Array): PreRunFunc { const stdlibPromise: Promise = loadBinaryFile(stdlibURL); return async (Module: PyodideModule) => { Module.API.pyVersionTuple = computeVersionTuple(Module); @@ -197,6 +197,7 @@ function getInstantiateWasmFunc( indexURL: string, + bytes?: Uint8Array, ): EmscriptenSettings["instantiateWasm"] { // @ts-ignore if (SOURCEMAP || typeof WasmOffsetConverter !== "undefined") { @@ -207,9 +208,12 @@ // https://emscripten.org/docs/api_reference/module.html?highlight=instantiatewasm#Module.instantiateWasm // // typeof WasmOffsetConverter !== "undefined" checks for asan. - return; + throw new Error("Unsupported debug build"); } - const { binary, response } = getBinaryResponse(indexURL + "pyodide.asm.wasm"); + if (!(bytes instanceof Uint8Array) || bytes.byteLength !== 9598218) + throw new Error("Missing pinned Wasm bytes"); + const binary = Promise.resolve(bytes); + const response: undefined = undefined; const jsvErrorImportPromise = getJsvErrorImport(); return function ( imports: { [key: string]: { [key: string]: any } }, --- a/src/js/pyodide.ts +++ b/src/js/pyodide.ts @@ -108,7 +108,9 @@ * file. This URL includes the most of the Python standard library. * Default: ```${indexURL}/python_stdlib.zip``` */ - stdLibURL?: string; + stdLibURL?: string | Uint8Array; + /** Verified Wasm input for the version-specific QLC loader adaptation. */ + qlcWasmBytes?: Uint8Array; /** * Override the standard input callback. Should ask the user for one line of * input. The :js:func:`pyodide.setStdin` function is more flexible and