mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-27 20:41:58 +03:00
Minor internal JS cleanups.
FossilOrigin-Name: 818ef0b5c909e733b643455278f7cc45533178f1cc6617058c00ed64fa44896a
This commit is contained in:
@ -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. */
|
||||
})();
|
||||
|
@ -522,7 +522,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
isInt32, isSQLableTypedArray, isTypedArray,
|
||||
typedArrayToString,
|
||||
isMainWindow: ()=>{
|
||||
return self.window===self && self.document;
|
||||
return 'undefined' === typeof WorkerGlobalScope
|
||||
}
|
||||
},
|
||||
|
||||
@ -904,8 +904,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
*/
|
||||
wasm.pstack = Object.assign(Object.create(null),{
|
||||
/**
|
||||
Sets the current ppstack position to the given pointer.
|
||||
Results are undefined if the passed-in value did not come from
|
||||
Sets the current pstack position to the given pointer. Results
|
||||
are undefined if the passed-in value did not come from
|
||||
this.pointer.
|
||||
*/
|
||||
restore: wasm.exports.sqlite3_wasm_pstack_restore,
|
||||
@ -927,7 +927,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
"bytes from the pstack.");
|
||||
},
|
||||
/**
|
||||
Allocates n chunks, each sz bytes, as a single memory block and
|
||||
alloc()'s n chunks, each sz bytes, as a single memory block and
|
||||
returns the addresses as an array of n element, each holding
|
||||
the address of one chunk.
|
||||
|
||||
@ -965,7 +965,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
will corrupt or read neighboring memory.
|
||||
|
||||
However, when all pointers involved point to "small" data, it
|
||||
is safe to pass a falsy value to save to memory.
|
||||
is safe to pass a falsy value to save a tiny bit of memory.
|
||||
*/
|
||||
allocPtr: (n=1,safePtrSize=true)=>{
|
||||
return 1===n
|
||||
|
@ -40,6 +40,7 @@
|
||||
if(urlParams.has('sqlite3.dir')){
|
||||
theJs = urlParams.get('sqlite3.dir') + '/' + theJs;
|
||||
}
|
||||
//console.warn("worker1 theJs =",theJs);
|
||||
importScripts(theJs);
|
||||
sqlite3InitModule().then((sqlite3)=>{
|
||||
sqlite3.capi.sqlite3_wasmfs_opfs_dir();
|
||||
|
Reference in New Issue
Block a user