mirror of
https://github.com/sqlite/sqlite.git
synced 2025-04-28 06:25:11 +03:00
41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
Module['locateFile'] = function(path, prefix) {
|
|
return prefix + path;
|
|
};
|
|
|
|
/**
|
|
Bug warning: this xInstantiateWasm bit must remain disabled
|
|
until this bug is resolved or wasmfs won't work:
|
|
|
|
https://github.com/emscripten-core/emscripten/issues/17951
|
|
*/
|
|
const xInstantiateWasm = 1
|
|
? 'emscripten-bug-17951'
|
|
: 'instantiateWasm';
|
|
Module[xInstantiateWasm] = function callee(imports,onSuccess){
|
|
imports.foo = function(){};
|
|
console.warn("instantiateWasm() uri =",callee.uri, self.location.href);
|
|
const wfetch = ()=>fetch(callee.uri, {credentials: 'same-origin'});
|
|
const loadWasm = WebAssembly.instantiateStreaming
|
|
? function loadWasmStreaming(){
|
|
return WebAssembly.instantiateStreaming(wfetch(), imports)
|
|
.then((arg)=>onSuccess(arg.instance, arg.module));
|
|
}
|
|
: function loadWasmOldSchool(){ // Safari < v15
|
|
return wfetch()
|
|
.then(response => response.arrayBuffer())
|
|
.then(bytes => WebAssembly.instantiate(bytes, imports))
|
|
.then((arg)=>onSuccess(arg.instance, arg.module));
|
|
};
|
|
loadWasm();
|
|
return {};
|
|
};
|
|
/*
|
|
It is literally impossible to get the name of a Worker's own script,
|
|
so impossible to derive X.wasm from script name X.js. Thus we need,
|
|
at build-time, to redifine Module['instantiateWasm'].uri by
|
|
appending it to a build-specific copy of this file with the name of
|
|
the wasm file. This is apparently why Emscripten hard-codes the name of
|
|
the wasm file into their glue scripts.
|
|
*/
|
|
Module[xInstantiateWasm].uri = 'sqlite3.wasm';
|