diff options
author | stephan <stephan@noemail.net> | 2023-01-29 06:01:32 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2023-01-29 06:01:32 +0000 |
commit | 26c7cff254b09285c41e82656f5fa53cd7ce95f8 (patch) | |
tree | c4f480c910186655eaf380ed2efcad195e2cff1f /ext/wasm/api/sqlite3-worker1.c-pp.js | |
parent | 2f5330036d19b0dcbf82f7a29c6192ce7ca9df93 (diff) | |
download | sqlite-26c7cff254b09285c41e82656f5fa53cd7ce95f8.tar.gz sqlite-26c7cff254b09285c41e82656f5fa53cd7ce95f8.zip |
Two JS file renames which got inadvertently undone while setting up [9062b31174618c0e]. Cosmetic cleanups in ext/wasm/dist.make.
FossilOrigin-Name: 0c2fde767f77d6204e95737edd573f42d72e956a3c20ea7e4daeff906657bbe5
Diffstat (limited to 'ext/wasm/api/sqlite3-worker1.c-pp.js')
-rw-r--r-- | ext/wasm/api/sqlite3-worker1.c-pp.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/ext/wasm/api/sqlite3-worker1.c-pp.js b/ext/wasm/api/sqlite3-worker1.c-pp.js new file mode 100644 index 000000000..9e9c3ac42 --- /dev/null +++ b/ext/wasm/api/sqlite3-worker1.c-pp.js @@ -0,0 +1,50 @@ +/* + 2022-05-23 + + The author disclaims copyright to this source code. In place of a + legal notice, here is a blessing: + + * May you do good and not evil. + * May you find forgiveness for yourself and forgive others. + * May you share freely, never taking more than you give. + + *********************************************************************** + + This is a JS Worker file for the main sqlite3 api. It loads + sqlite3.js, initializes the module, and postMessage()'s a message + after the module is initialized: + + {type: 'sqlite3-api', result: 'worker1-ready'} + + This seemingly superfluous level of indirection is necessary when + loading sqlite3.js via a Worker. Instantiating a worker with new + Worker("sqlite.js") will not (cannot) call sqlite3InitModule() to + initialize the module due to a timing/order-of-operations conflict + (and that symbol is not exported in a way that a Worker loading it + that way can see it). Thus JS code wanting to load the sqlite3 + Worker-specific API needs to pass _this_ file (or equivalent) to the + Worker constructor and then listen for an event in the form shown + above in order to know when the module has completed initialization. + + This file accepts a URL arguments to adjust how it loads sqlite3.js: + + - `sqlite3.dir`, if set, treats the given directory name as the + directory from which `sqlite3.js` will be loaded. +*/ +"use strict"; +(()=>{ +//#if target=es6-bundler-friendly + importScripts('sqlite3.js'); +//#else + const urlParams = new URL(self.location.href).searchParams; + let theJs = 'sqlite3.js'; + if(urlParams.has('sqlite3.dir')){ + theJs = urlParams.get('sqlite3.dir') + '/' + theJs; + } + //console.warn("worker1 theJs =",theJs); + importScripts(theJs); +//#endif + sqlite3InitModule().then((sqlite3)=>{ + sqlite3.initWorker1API(); + }); +})(); |