aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-10-20 04:00:05 +0000
committerstephan <stephan@noemail.net>2022-10-20 04:00:05 +0000
commitd89a66ec36491c1d98a1bbeb04dac4e74d66f754 (patch)
tree9a7128a89a35109046bd4a60def4d2f96e3831a4 /ext/wasm
parentbf70f1bd1a24093e8a03549090af7d87ef4e9c8e (diff)
downloadsqlite-d89a66ec36491c1d98a1bbeb04dac4e74d66f754.tar.gz
sqlite-d89a66ec36491c1d98a1bbeb04dac4e74d66f754.zip
Minor internal JS cleanups.
FossilOrigin-Name: 818ef0b5c909e733b643455278f7cc45533178f1cc6617058c00ed64fa44896a
Diffstat (limited to 'ext/wasm')
-rw-r--r--ext/wasm/api/extern-post-js.js19
-rw-r--r--ext/wasm/api/sqlite3-api-prologue.js10
-rw-r--r--ext/wasm/api/sqlite3-worker1.js1
3 files changed, 22 insertions, 8 deletions
diff --git a/ext/wasm/api/extern-post-js.js b/ext/wasm/api/extern-post-js.js
index 5f5f72d4b..768696508 100644
--- a/ext/wasm/api/extern-post-js.js
+++ b/ext/wasm/api/extern-post-js.js
@@ -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. */
})();
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js
index 3980e0ad4..f59d86506 100644
--- a/ext/wasm/api/sqlite3-api-prologue.js
+++ b/ext/wasm/api/sqlite3-api-prologue.js
@@ -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
diff --git a/ext/wasm/api/sqlite3-worker1.js b/ext/wasm/api/sqlite3-worker1.js
index 26c88402c..4cff68b08 100644
--- a/ext/wasm/api/sqlite3-worker1.js
+++ b/ext/wasm/api/sqlite3-worker1.js
@@ -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();