1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Rework the Emscripten-emitted module loader/init function such that it passes on the sqlite3 module, instead of the Emscripten module, to the first then() of sqlite3InitModule()'s returned Promise. This eliminates any need to mention the Emscripten module object in client-side code unless they want to configure it in advance for loading-status reports.

FossilOrigin-Name: 0dbaa0e2b5abf5c23e2039ec90a3055ebb3c063aaf4e556c42546defe6fbb86d
This commit is contained in:
stephan
2022-09-29 13:17:50 +00:00
parent 4b884bb4c7
commit b94a98607a
17 changed files with 127 additions and 100 deletions

View File

@ -0,0 +1,41 @@
/* emscripten-js-addenda.js must be appended to the resulting sqlite3.js
file. */
(function(){
/**
In order to hide the sqlite3InitModule()'s resulting Emscripten
module from downstream clients (and simplify our documentation by
being able to elide those details), we rewrite
sqlite3InitModule() to return the sqlite3 object.
Unfortunately, we cannot modify the module-loader/exporter-based
impls which Emscripten installs at some point in the file above
this.
*/
const originalInit = self.sqlite3InitModule;
if(!originalInit){
throw new Error("Expecting self.sqlite3InitModule to be defined by the Emscripten build.");
}
self.sqlite3InitModule.ready = originalInit.ready;
self.sqlite3InitModule = (...args)=>{
//console.warn("Using replaced sqlite3InitModule()",self.location);
return originalInit(...args).then((EmscriptenModule)=>{
if(self.window!==self &&
(EmscriptenModule['ENVIRONMENT_IS_PTHREAD']
|| EmscriptenModule['_pthread_self']
|| 'function'===typeof threadAlert
|| self.location.pathname.endsWith('.worker.js')
)){
/** Workaround for wasmfs-generated worker, which calls this
routine from each individual thread and requires that its
argument be returned. All of the criteria above are fragile,
based solely on inspection of the offending code, not public
Emscripten details. */
return EmscriptenModule;
}
const f = EmscriptenModule.sqlite3.asyncPostInit;
delete EmscriptenModule.sqlite3.asyncPostInit;
return f();
});
};
//console.warn("Replaced sqlite3InitModule()");
})();