1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Minor internal JS cleanups.

FossilOrigin-Name: 818ef0b5c909e733b643455278f7cc45533178f1cc6617058c00ed64fa44896a
This commit is contained in:
stephan
2022-10-20 04:00:05 +00:00
parent bf70f1bd1a
commit d89a66ec36
5 changed files with 32 additions and 18 deletions

View File

@ -23,19 +23,24 @@
https://github.com/emscripten-core/emscripten/issues/18071
The only current workaround is to temporarily stash this state
The only(?) current workaround is to temporarily stash this state
into the global scope and delete it when sqlite3InitModule()
is called.
*/
const initModuleState = self.sqlite3InitModuleState = Object.assign(Object.create(null),{
moduleScript: self?.document?.currentScript,
isWorker: (!self.document && self.window !== self),
isWorker: ('undefined' !== typeof WorkerGlobalScope),
location: self.location,
urlParams: new URL(self.location.href).searchParams
});
if(initModuleState.urlParams.has('sqlite3.dir')){
initModuleState.sqlite3Dir = initModuleState.urlParams.get('sqlite3.dir') +'/';
};
}else if(initModuleState.moduleScript){
const li = initModuleState.moduleScript.src.split('/');
li.pop();
initModuleState.sqlite3Dir = li.join('/') + '/';
}
//console.warn("initModuleState =",initModuleState);
self.sqlite3InitModule = (...args)=>{
//console.warn("Using replaced sqlite3InitModule()",self.location);
@ -79,4 +84,12 @@
document?.currentScript?.src);
}
}
/* Replace the various module exports performed by the Emscripten
glue... */
if (typeof exports === 'object' && typeof module === 'object')
module.exports = sqlite3InitModule;
else if (typeof exports === 'object')
exports["sqlite3InitModule"] = sqlite3InitModule;
/* AMD modules get injected in a way we cannot override,
so we can't handle those here. */
})();