]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Apply considerable acrobatics to get the JS/WASM deliverables building to and loadabl...
authorstephan <stephan@noemail.net>
Wed, 19 Oct 2022 04:44:58 +0000 (04:44 +0000)
committerstephan <stephan@noemail.net>
Wed, 19 Oct 2022 04:44:58 +0000 (04:44 +0000)
FossilOrigin-Name: 6d468dab9eb84d4548f68014959f02fe4f66455472ff24fe729382bb2972e3d1

27 files changed:
ext/wasm/GNUmakefile
ext/wasm/api/extern-post-js.js
ext/wasm/api/pre-js.js
ext/wasm/api/sqlite3-api-opfs.js
ext/wasm/api/sqlite3-api-prologue.js
ext/wasm/api/sqlite3-opfs-async-proxy.js [moved from ext/wasm/sqlite3-opfs-async-proxy.js with 100% similarity]
ext/wasm/api/sqlite3-worker1-promiser.js [moved from ext/wasm/sqlite3-worker1-promiser.js with 93% similarity]
ext/wasm/api/sqlite3-worker1.js [moved from ext/wasm/sqlite3-worker1.js with 94% similarity]
ext/wasm/batch-runner.html
ext/wasm/demo-123-worker.html
ext/wasm/demo-123.html
ext/wasm/demo-123.js
ext/wasm/demo-kvvfs1.html
ext/wasm/fiddle.make
ext/wasm/speedtest1-worker.html
ext/wasm/speedtest1-worker.js
ext/wasm/speedtest1.html
ext/wasm/test-opfs-vfs.html
ext/wasm/test-opfs-vfs.js
ext/wasm/tester1-worker.html
ext/wasm/tester1.html
ext/wasm/tester1.js
ext/wasm/testing-worker1-promiser.html
ext/wasm/testing-worker1-promiser.js
ext/wasm/testing2.js
manifest
manifest.uuid

index f461f8b46adae4ff9ba2697ace7cad46a2a73ede..f364e446bcfa063e40c1c659b5900c48beb24198 100644 (file)
@@ -90,7 +90,7 @@ dir.tool := $(dir.top)/tool
 # the loading-from-worker case...
 #
 # dir.dout = output dir for deliverables.
-dir.dout := $(dir.wasm)
+dir.dout := $(dir.wasm)/jswasm
 # dir.tmp = output dir for intermediary build files, as opposed to
 # end-user deliverables.
 dir.tmp := $(dir.wasm)/bld
@@ -218,6 +218,20 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js
 sqlite3-api.jses += $(dir.api)/sqlite3-api-opfs.js
 sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js
 
+# "External" API files which are part of our distribution
+# but not part of the sqlite3-api.js amalgamation.
+SOAP.js := $(dir.api)/sqlite3-opfs-async-proxy.js
+sqlite3-worker1.js := $(dir.api)/sqlite3-worker1.js
+sqlite3-worker1-promiser.js := $(dir.api)/sqlite3-worker1-promiser.js
+define CP_XAPI
+sqlite3-api.ext.jses += $$(dir.dout)/$$(notdir $(1))
+$$(dir.dout)/$$(notdir $(1)): $(1) $$(MAKEFILE)
+       cp $$< $$@
+endef
+$(foreach X,$(SOAP.js) $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js),\
+  $(eval $(call CP_XAPI,$(X))))
+all: $(sqlite3-api.ext.jses)
+
 sqlite3-api.js := $(dir.tmp)/sqlite3-api.js
 $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE)
        @echo "Making $@..."
@@ -384,6 +398,7 @@ sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c
 # difference. Thus we build all binaries against sqlite3-wasm.c
 # instead of building a shared copy of sqlite3-wasm.o.
 $(eval $(call call-make-pre-js,sqlite3))
+$(sqlite3.js):
 $(sqlite3.js): $(MAKEFILE) $(sqlite3.wasm.obj) \
     $(EXPORTED_FUNCTIONS.api) \
     $(pre-post-sqlite3.deps)
index 7dba03b3a729749fc4f7a6494f5d3e5a3fba10e7..5f5f72d4b3a86021e0db6532f083471a6271564c 100644 (file)
   if(!originalInit){
     throw new Error("Expecting self.sqlite3InitModule to be defined by the Emscripten build.");
   }
+  /**
+     We need to add some state which our custom Module.locateFile()
+     can see, but an Emscripten limitation currently prevents us from
+     attaching it to the sqlite3InitModule function object:
+
+     https://github.com/emscripten-core/emscripten/issues/18071
+
+     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),
+    location: self.location,
+    urlParams: new URL(self.location.href).searchParams
+  });
+  if(initModuleState.urlParams.has('sqlite3.dir')){
+    initModuleState.sqlite3Dir = initModuleState.urlParams.get('sqlite3.dir') +'/';
+  };
+
   self.sqlite3InitModule = (...args)=>{
     //console.warn("Using replaced sqlite3InitModule()",self.location);
     return originalInit(...args).then((EmscriptenModule)=>{
@@ -32,6 +53,8 @@
             Emscripten details. */
         return EmscriptenModule;
       }
+      EmscriptenModule.sqlite3.scriptInfo = initModuleState;
+      //console.warn("sqlite3.scriptInfo =",EmscriptenModule.sqlite3.scriptInfo);
       const f = EmscriptenModule.sqlite3.asyncPostInit;
       delete EmscriptenModule.sqlite3.asyncPostInit;
       return f();
     });
   };
   self.sqlite3InitModule.ready = originalInit.ready;
-  //console.warn("Replaced sqlite3InitModule()");
-})();
 
-if(0){
-  console.warn("self.location.href =",self.location.href);
-  if('undefined' !== typeof document){
-    console.warn("document.currentScript.src =",
-                 document?.currentScript?.src);
+  if(self.sqlite3InitModuleState.moduleScript){
+    const sim = self.sqlite3InitModuleState;
+    let src = sim.moduleScript.src.split('/');
+    src.pop();
+    sim.scriptDir = src.join('/') + '/';
   }
-}
+  if(0){
+    console.warn("Replaced sqlite3InitModule()");
+    console.warn("self.location.href =",self.location.href);
+    if('undefined' !== typeof document){
+      console.warn("document.currentScript.src =",
+                   document?.currentScript?.src);
+    }
+  }
+})();
index b6630416dd35c963dfa46870b13cb65c284d4a60..c07d0373cd82dfecce732a431d9d3b0a54081d8e 100644 (file)
@@ -4,9 +4,49 @@
    This file is intended to be prepended to the sqlite3.js build using
    Emscripten's --pre-js=THIS_FILE flag (or equivalent).
 */
+
+// See notes in extern-post-js.js
+const sqlite3InitModuleState = self.sqlite3InitModuleState || Object.create(null);
+delete self.sqlite3InitModuleState;
+
+/**
+   This custom locateFile() tries to figure out where to load `path`
+   from. The intent is to provide a way for foo/bar/X.js loaded from a
+   Worker constructor or importScripts() to be able to resolve
+   foo/bar/X.wasm (in the latter case, with some help):
+
+   1) If URL param named the same as `path` is set, it is returned.
+
+   2) If sqlite3InitModuleState.sqlite3Dir is set, then (thatName + path)
+      is returned (note that it's assumed to end with '/').
+
+   3) If this code is running in the main UI thread AND it was loaded
+      from a SCRIPT tag, the directory part of that URL is used
+      as the prefix. (This form of resolution unfortunately does not
+      function for scripts loaded via importScripts().)
+
+   4) If none of the above apply, (prefix+path) is returned.
+*/
 Module['locateFile'] = function(path, prefix) {
-  return prefix + path;
-};
+  let theFile;
+  const up = this.urlParams;
+  if(0){
+    console.warn("locateFile(",arguments[0], ',', arguments[1],")",
+                 'self.location =',self.location,
+                 'sqlite3InitModuleState.scriptDir =',this.scriptDir,
+                 'up.entries() =',Array.from(up.entries()));
+  }
+  if(up.has(path)){
+    theFile = up.get(path);
+  }else if(this.sqlite3Dir){
+    theFile = this.sqlite3Dir + path;
+  }else if(this.scriptDir){
+    theFile = this.scriptDir + path;
+  }else{
+    theFile = prefix + path;
+  }
+  return theFile;
+}.bind(sqlite3InitModuleState);
 
 /**
    Bug warning: this xInstantiateWasm bit must remain disabled
index 98defe4fbc3e4b8d2590b4d97c6a826174ddc8c5..9f530245484c61b9a180552fbd0aac0dab2c803c 100644 (file)
@@ -98,6 +98,9 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
     options.proxyUri = callee.defaultProxyUri;
   }
 
+  if('function' === typeof options.proxyUri){
+    options.proxyUri = options.proxyUri();
+  }
   const thePromise = new Promise(function(promiseResolve, promiseReject_){
     const loggers = {
       0:console.error.bind(console),
@@ -1092,9 +1095,18 @@ installOpfsVfs.defaultProxyUri =
   "sqlite3-opfs-async-proxy.js";
 //console.warn("sqlite3.installOpfsVfs.defaultProxyUri =",sqlite3.installOpfsVfs.defaultProxyUri);
 self.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
+  if(sqlite3.scriptInfo && !sqlite3.scriptInfo.isWorker){
+    return;
+  }
   try{
+    let proxyJs = installOpfsVfs.defaultProxyUri;
+    if(sqlite3.scriptInfo.sqlite3Dir){
+      installOpfsVfs.defaultProxyUri =
+        sqlite3.scriptInfo.sqlite3Dir + proxyJs;
+      //console.warn("installOpfsVfs.defaultProxyUri =",installOpfsVfs.defaultProxyUri);
+    }
     return installOpfsVfs().catch((e)=>{
-      console.warn("Ignoring inability to install OPFS sqlite3_vfs:",e);
+      console.warn("Ignoring inability to install OPFS sqlite3_vfs:",e.message);
     });
   }catch(e){
     console.error("installOpfsVfs() exception:",e);
index f8c0f024e64d3b972df52884f4e5b597da80f580..3980e0ad42a4581ee8d211448b71f9ee9a128a02 100644 (file)
@@ -1334,7 +1334,20 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
       //while(lip.length) p = p.then(lip.shift());
       //return p.then(()=>sqlite3);
       return Promise.all(lip).then(()=>sqlite3);
-    }
+    },
+    /**
+       scriptInfo ideally gets injected into this object by the
+       infrastructure which assembles the JS/WASM module. It contains
+       state which must be collected before sqlite3ApiBootstrap() can
+       be declared. It is not necessarily available to any
+       sqlite3ApiBootstrap.initializers but "should" be in place (if
+       it's added at all) by the time that
+       sqlite3ApiBootstrap.initializersAsync is processed.
+
+       This state is not part of the public API, only intended for use
+       with the sqlite3 API bootstrapping and wasm-loading process.
+    */
+    scriptInfo: undefined
   };
   try{
     sqlite3ApiBootstrap.initializers.forEach((f)=>{
@@ -1410,3 +1423,4 @@ self.sqlite3ApiBootstrap.defaultConfig = Object.create(null);
    value which will be stored here.
 */
 self.sqlite3ApiBootstrap.sqlite3 = undefined;
+
similarity index 93%
rename from ext/wasm/sqlite3-worker1-promiser.js
rename to ext/wasm/api/sqlite3-worker1-promiser.js
index 71e2e331350a6013476a2fedc96f60dc90a5ca6e..a77b0126dfffb211be42dc27fda57410e798667e 100644 (file)
@@ -237,6 +237,23 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
   };
 }/*sqlite3Worker1Promiser()*/;
 self.sqlite3Worker1Promiser.defaultConfig = {
-  worker: ()=>new Worker("sqlite3-worker1.js"+self.location.search),
+  worker: function(){
+    let theJs = "sqlite3-worker1.js";
+    if(this.currentScript){
+      const src = this.currentScript.src.split('/');
+      src.pop();
+      theJs = src.join('/')+'/' + theJs;
+      //console.warn("promiser currentScript, theJs =",this.currentScript,theJs);
+    }else{
+      //console.warn("promiser self.location =",self.location);
+      const urlParams = new URL(self.location.href).searchParams;
+      if(urlParams.has('sqlite3.dir')){
+        theJs = urlParams.get('sqlite3.dir') + '/' + theJs;
+      }
+    }
+    return new Worker(theJs + self.location.search);
+  }.bind({
+    currentScript: self?.document?.currentScript
+  }),
   onerror: (...args)=>console.error('worker1 promiser error',...args)
 };
similarity index 94%
rename from ext/wasm/sqlite3-worker1.js
rename to ext/wasm/api/sqlite3-worker1.js
index fef155e1f840e6cf35b0f47da8467b86f79ae45f..bc860300bb9f74154ef25672ca673d76bce0c114 100644 (file)
   This file accepts a couple of 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.
   - `sqlite3.js`, if set, is used as the URI to `sqlite3.js` and it
     may contain path elements, e.g. `sqlite3.js=foo/bar/my-sqlite3.js`.
+  - `sqlite3.dir`, if set, treats the given directory name as the
+    directory from which `sqlite3.js` will be loaded.
 
   By default is loads 'sqlite3.js'.
 */
 "use strict";
 (()=>{
   const urlParams = new URL(self.location.href).searchParams;
-  let theJs;
+  let theJs = 'sqlite3.js';
   if(urlParams.has('sqlite3.js')){
     theJs = urlParams.get('sqlite3.js');
   }else if(urlParams.has('sqlite3.dir')){
-    theJs = urlParams.get('sqlite3.dir')+'/sqlite3.js';
-  }else{
-    theJs = 'sqlite3.js';
+    theJs = urlParams.get('sqlite3.dir') + '/' + theJs;
   }
   importScripts(theJs);
   sqlite3InitModule().then((sqlite3)=>{
index e7a2b1e0824e78399627f6bf7146be5634540ea1..5258f9597e34c263655c004b50e8eb5cd17af27d 100644 (file)
@@ -69,7 +69,7 @@
         <label for='cb-reverse-log-order'>Reverse log order (newest first)</label>
       </span>
     <div id='test-output'></div>
-    <script src="sqlite3-wasmfs.js"></script>
+    <script src="jswasm/sqlite3.js"></script>
     <script src="common/SqliteTestUtil.js"></script>
     <script src="batch-runner.js"></script>
     <style>
index f632e3951545f789102f5fc7e418b27a40ab2806..692203d71e5e0bd3ec39df6d1c69f9915a33f88d 100644 (file)
         ln.append(document.createTextNode(args.join(' ')));
         document.body.append(ln);
       };
-      const w = new Worker("demo-123.js");
+      const w = new Worker("demo-123.js?sqlite3.dir=jswasm"
+                           /* Note the URL argument on that name. See
+                              the notes in demo-123.js (search for
+                              "importScripts") for why we need
+                              that. */);
       w.onmessage = function({data}){
         switch(data.type){
             case 'log':
index 0771990c7089d14f9c5d07bb5e1981c54590948e..2046b076d4753aa39553efb811c820f6a7f80f04 100644 (file)
@@ -18,7 +18,7 @@
   </head>
   <body>
     <h1>1-2-sqlite3 demo</h1>
-    <script src="sqlite3.js"></script>
+    <script src="jswasm/sqlite3.js"></script>
     <script src="demo-123.js"></script>
   </body>
 </html>
index 04a999488a2c337f41c26bc84763360232f607ed..311afcc8270047bcd88debd055f9ee1ccf8e2507 100644 (file)
 
   log("Loading and initializing sqlite3 module...");
   if(self.window!==self) /*worker thread*/{
-    importScripts("sqlite3.js");
+    /*
+      If sqlite3.js is in a directory other than this script, in order
+      to get sqlite3.js to resolve sqlite3.wasm properly, we have to
+      explicitly tell it where sqlite3.js is being loaded from. We do
+      that by passing the `sqlite3.dir=theDirName` URL argument to
+      _this_ script. That URL argument will be seen by the JS/WASM
+      loader and it will adjust the sqlite3.wasm path accordingly. If
+      sqlite3.js/.wasm are in the same directory as this script then
+      that's not needed.
+
+      URL arguments passed as part of the filename via importScripts()
+      are simply lost, and such scripts see the self.location of
+      _this_ script.
+    */
+    let sqlite3Js = 'sqlite3.js';
+    const urlParams = new URL(self.location.href).searchParams;
+    if(urlParams.has('sqlite3.dir')){
+      sqlite3Js = urlParams.get('sqlite3.dir') + '/' + sqlite3Js;
+    }
+    importScripts(sqlite3Js);
   }
   self.sqlite3InitModule({
     // We can redirect any stdout/stderr from the module
index caa3cdec85bbfd3c5070ff36663c3e6802401d46..b79ef1157bfd9ecb2dbccf4f47400ab8b2666407 100644 (file)
@@ -42,7 +42,7 @@
       .toolbar > * { margin: 0.25em; }
       fieldset { border-radius: 0.5em; }
     </style>
-    <script src="sqlite3.js"></script>
+    <script src="jswasm/sqlite3.js"></script>
     <script src="common/SqliteTestUtil.js"></script>
     <script src="demo-kvvfs1.js"></script>
   </body>
index 84cc6b298a48b5ca74327845bc450b557ee9806f..f669efd92c060bf789e3bd117b11d6a6c1453e8a 100644 (file)
@@ -53,14 +53,14 @@ fiddle-module.js := $(dir.fiddle)/fiddle-module.js
 fiddle-module.wasm := $(subst .js,.wasm,$(fiddle-module.js))
 fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c)
 
-SOAP.js := sqlite3-opfs-async-proxy.js
-$(dir.fiddle)/$(SOAP.js): $(SOAP.js)
+fiddle.SOAP.js := $(dir.fiddle)/$(notdir $(SOAP.js))
+$(fiddle.SOAP.js): $(SOAP.js)
        cp $< $@
 
 $(eval $(call call-make-pre-js,fiddle-module))
 $(fiddle-module.js): $(MAKEFILE) $(MAKEFILE.fiddle) \
     $(EXPORTED_FUNCTIONS.fiddle) \
-    $(fiddle.cses) $(pre-post-fiddle-module.deps) $(dir.fiddle)/$(SOAP.js)
+    $(fiddle.cses) $(pre-post-fiddle-module.deps) $(fiddle.SOAP.js)
        $(emcc.bin) -o $@ $(fiddle.emcc-flags) \
     $(pre-post-common.flags) $(pre-post-fiddle-module.flags) \
     $(fiddle.cses)
index 2e9ea2c34331eac2c36804c266954fea47e43741..56b6913352ad54b1f59fc9071f723d3b1f0a2776 100644 (file)
         return str+a.join('&nbsp;');
     };
 
-    const W = new Worker("speedtest1-worker.js"+self.location.search);
+    const W = new Worker("speedtest1-worker.js?sqlite3.dir=jswasm");
     const mPost = function(msgType,payload){
         W.postMessage({type: msgType, data: payload});
     };
index 1f421b0b869c9490b6dc0b5a7840eab5b1c3287b..81a40e2b7808008eacd401f8ecf72586df0f8bd1 100644 (file)
@@ -1,6 +1,11 @@
 'use strict';
 (function(){
-  importScripts('common/whwasmutil.js','speedtest1.js');
+  let speedtestJs = 'speedtest1.js';
+  const urlParams = new URL(self.location.href).searchParams;
+  if(urlParams.has('sqlite3.dir')){
+    speedtestJs = urlParams.get('sqlite3.dir') + '/' + speedtestJs;
+  }
+  importScripts('common/whwasmutil.js', speedtestJs);
   /**
      If this environment contains OPFS, this function initializes it and
      returns the name of the dir on which OPFS is mounted, else it returns
index 358d8ba79eb0d81c4d8b10807476a2840956e221..a53b24c6df610f362ffdd3f078a0b56ecb707044 100644 (file)
@@ -37,7 +37,7 @@
       speedtest is running. Output will appear below when ready...
     <div id='test-output'></div>
     <script src="common/SqliteTestUtil.js"></script>
-    <script src="speedtest1.js"></script>
+    <script src="jswasm/speedtest1.js"></script>
     <script>(function(){
     /**
        If this environment contains OPFS, this function initializes it and
index 41b278c2894f9e84db200480475e2f74eab9ac95..235ef51e9f0df1e3cc51c8665e52f8a40d355f75 100644 (file)
@@ -9,16 +9,18 @@
     <title>Async-behind-Sync experiment</title>
   </head>
   <body>
-    <header id='titlebar'><span>Async-behind-Sync Experiment</span></header>
-    <div>This is an experiment in wrapping the
-      asynchronous OPFS APIs behind a fully synchronous proxy. It is
-      very much incomplete, under construction, and experimental.
+    <header id='titlebar'><span>Async-behind-Sync sqlite3_vfs</span></header>
+    <div>This performs a sanity test of the "opfs" sqlite3_vfs.
       <strong>See the dev console for all output.</strong>
     </div>
     <div>
       <a href='?delete'>Use this link</a> to delete the persistent OPFS-side db (if any).
     </div>
     <div id='test-output'></div>
-    <script>new Worker("test-opfs-vfs.js"+self.location.search);</script>
+    <script>
+      new Worker(
+          "test-opfs-vfs.js?sqlite3.dir=jswasm&"+self.location.search.substr(1)
+      );
+    </script>
   </body>
 </html>
index 583871b7d11a0f576bf210b137a4812975b5dc8e..e22acc0e3d9b401c138cc1c9483947823be0f6c6 100644 (file)
@@ -76,7 +76,7 @@ const tryOpfsVfs = async function(sqlite3){
   log("Done!");
 }/*tryOpfsVfs()*/;
 
-importScripts('sqlite3.js');
+importScripts('jswasm/sqlite3.js');
 self.sqlite3InitModule()
   .then((sqlite3)=>tryOpfsVfs(sqlite3))
   .catch((e)=>{
index bb5de0762f00a9d2641f5f60a6c9af7d129a6983..e127cffdca01ec53a13d1af01c32c5659d8643d2 100644 (file)
@@ -24,7 +24,7 @@
         ln.append(document.createTextNode(args.join(' ')));
         logTarget.append(ln);
       };
-      const w = new Worker("tester1.js");
+      const w = new Worker("tester1.js?sqlite3.dir=jswasm");
       w.onmessage = function({data}){
         switch(data.type){
             case 'log':
index 9cf0bee0a358d20a92b792d25ff439f5fe49213e..c16315127800e48de279119d0d83ef24470a84a7 100644 (file)
@@ -16,7 +16,7 @@
   <body>
     <h1>sqlite3 WASM/JS tester #1 (UI thread)</h1>
     <div id='test-output'></div>
-    <script src="sqlite3.js"></script>
+    <script src="jswasm/sqlite3.js"></script>
     <script src="tester1.js"></script>
   </body>
 </html>
index aef9d2301b8fb5078cc7945d40582d5b550246f7..c8808c9137a4660a5b2c82949125ade7fa940fda 100644 (file)
@@ -65,7 +65,7 @@
   };
   const normalizeArgs = (args)=>args.map(mapToString);
   if( isUIThread() ){
-    console.log("Running in UI thread.");
+    console.log("Running in the UI thread.");
     const logTarget = document.querySelector('#test-output');
     logClass = function(cssClass,...args){
       const ln = document.createElement('div');
@@ -74,7 +74,7 @@
       logTarget.append(ln);
     };
   }else{ /* Worker thread */
-    console.log("Running Worker thread.");
+    console.log("Running in a Worker thread.");
     logClass = function(cssClass,...args){
       postMessage({
         type:'log',
   ////////////////////////////////////////////////////////////////////////
   log("Loading and initializing sqlite3 WASM module...");
   if(!isUIThread()){
-    importScripts("sqlite3.js");
+    /*
+      If sqlite3.js is in a directory other than this script, in order
+      to get sqlite3.js to resolve sqlite3.wasm properly, we have to
+      explicitly tell it where sqlite3.js is being loaded from. We do
+      that by passing the `sqlite3.dir=theDirName` URL argument to
+      _this_ script. That URL argument will be seen by the JS/WASM
+      loader and it will adjust the sqlite3.wasm path accordingly. If
+      sqlite3.js/.wasm are in the same directory as this script then
+      that's not needed.
+
+      URL arguments passed as part of the filename via importScripts()
+      are simply lost, and such scripts see the self.location of
+      _this_ script.
+    */
+    let sqlite3Js = 'sqlite3.js';
+    const urlParams = new URL(self.location.href).searchParams;
+    if(urlParams.has('sqlite3.dir')){
+      sqlite3Js = urlParams.get('sqlite3.dir') + '/' + sqlite3Js;
+    }
+    importScripts(sqlite3Js);
   }
   self.sqlite3InitModule({
     print: log,
index 9af809d9ed583519c400cbc4f5e518ecd52162bb..4b35ca82c0a790460d5a6089f80cb9a89c0403e3 100644 (file)
@@ -28,7 +28,7 @@
     <hr>
     <div id='test-output'></div>
     <script src="common/SqliteTestUtil.js"></script>
-    <script src="sqlite3-worker1-promiser.js"></script>
+    <script src="jswasm/sqlite3-worker1-promiser.js"></script>
     <script src="testing-worker1-promiser.js"></script>
   </body>
 </html>
index 259d20fddc61ce9071a5d8b25bad80ffeba867ab..855643b2d28bfa7dc8bdf00d4a513c1f8ac8d4ee 100644 (file)
@@ -40,7 +40,7 @@
 
   const promiserConfig = {
     worker: ()=>{
-      const w = new Worker("sqlite3-worker1.js");
+      const w = new Worker("jswasm/sqlite3-worker1.js");
       w.onerror = (event)=>error("worker.onerror",event);
       return w;
     },
index 7163fe120430baca7dd7833f4948c11c6bf15556..5ea48db6b62893d351425320335f3192f16e0182 100644 (file)
@@ -19,7 +19,7 @@
 'use strict';
 (function(){
   const T = self.SqliteTestUtil;
-  const SW = new Worker("sqlite3-worker1.js");
+  const SW = new Worker("jswasm/sqlite3-worker1.js");
   const DbState = {
     id: undefined
   };
index f50dd6aef72a342f5a8e9886fd8407f22c7e641b..f141d54ba20482b68d9e1b34c1d1fad5cf1ee2d5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Considerable\swasm/js\sbuild\scleanups\sand\sreworking.\sRemove\swasmfs\sbuilds\sfrom\sthe\send-user\sdeliverables\sand\sdisable\sthe\swasmfs\sbuild\sby\sdefault,\sper\s/chat\sdiscussion,\sas\sit\sdoubles\sour\sdeliverable\scount\sfor\sonly\smarginal\sgain.\sAttempt\sto\smove\sthe\ssqlite3.js/wasm\sfiles\sinto\ssubdirectories\sbut\srediscovered\sthat\sthat\sbreaks\sloading\sin\sWorker\smode\sbecause\sURI\sresolution\sof\sthe\swasm\sfiles\sdiffers\sdepending\son\swhether\sthe\smain\sscript\sis\sloaded\sfrom\sa\sscript\stag\sor\sa\sWorker.
-D 2022-10-19T01:07:30.150
+C Apply\sconsiderable\sacrobatics\sto\sget\sthe\sJS/WASM\sdeliverables\sbuilding\sto\sand\sloadable\sfrom\sa\sdirectory\sother\sthan\sthe\sone\swhich\scontains\sthe\sapp-level\scode.\sRequires\san\sonly-slightly-leaky\sabstraction\sof\spassing\sa\sURL\sargument\swhen\sloading\ssqlite3.js\sbut\sprovides\smuch\sgreater\sflexibility\sin\swhere\sthe\sJS/WASM\sfiles\sare\slocated.
+D 2022-10-19T04:44:58.210
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -472,39 +472,42 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3
 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb
 F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
-F ext/wasm/GNUmakefile d5a39121aeb316562895889c6b27f9ec11e9cae2f844b23d5c7d04479a3bec2a
+F ext/wasm/GNUmakefile e9686a03f201a16786783964d0f2fcf4d9af8a9aee6e3ce5b6c3ee5d7750842f
 F ext/wasm/README-dist.txt 13438bafe5fab1eca223be91459e757e6e67248fc959b9ae0ffb5808fd0a1610
 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066
 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a
 F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287
 F ext/wasm/api/README.md 946398dd80bfd673f098b9d6ca3564e1fc77b03e660274d132f267c407b8703c
-F ext/wasm/api/extern-post-js.js b3d14b7d5880e70caec2feae2ab2f31ccb3af67d200e4a9fd58dcc0c4b401bf1
+F ext/wasm/api/extern-post-js.js 4bba34d8301f6058abd8ee24d2778b7360c5c3679217b38f5670e97a5ba7a3ec
 F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41
 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1
 F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1ecc5ba9e64ef90a8b
-F ext/wasm/api/pre-js.js 5b550904322d73127badd4347ca967ea525b901573559736f92d326ad9b7bb76
+F ext/wasm/api/pre-js.js 151e0616614a49f3db19ed544fa13b38c87c108959fbcd4029ea8399a562d94f
 F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383bd7ee0de0178b1b3e988588
 F ext/wasm/api/sqlite3-api-glue.js 05eb701460bb72edbe3bf923bd51262551614612c37802fc597eabb4c6b83232
 F ext/wasm/api/sqlite3-api-oo1.js 9a5f0c00d476c504f16dcd456e1743dbc2826ca3d10645dfa62663a39e3ed0d8
-F ext/wasm/api/sqlite3-api-opfs.js 5a8ab3b76880c8ada8710ca9ba1ca5b160872edfd8bd5322e4f179a7f41cc616
-F ext/wasm/api/sqlite3-api-prologue.js f6ae0da8de61f8d550b0bb8e486e5edd38129005c2bb2a448f6bf30dbf8b723b
+F ext/wasm/api/sqlite3-api-opfs.js 22d60ba956e873b65e2e0591e239178082bd53a6d563c3c58db7dc03e562e8f7
+F ext/wasm/api/sqlite3-api-prologue.js bdcd1f636e5ef0622f99b753aff0d26cc250bcd3a17923771e335ec73059b073
 F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8
 F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3
+F ext/wasm/api/sqlite3-opfs-async-proxy.js 206ce6bbc3c30ad51a37d9c25e3a2712e70b586e0f9a2cf8cb0b9619017c2671 w ext/wasm/sqlite3-opfs-async-proxy.js
 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
 F ext/wasm/api/sqlite3-wasm.c 84d410a2b9defdac85e6a421736307ff3a3eed3c1b0ae3b7b140edbc6ad81a8f
-F ext/wasm/batch-runner.html cf1a410c92bad50fcec2ddc71390b4e9df63a6ea1bef12a5163a66a0af4d78d9
+F ext/wasm/api/sqlite3-worker1-promiser.js f0aa93db62903f4006428cbcd2209a765655ec69a0e57247baba0fc94d745987 w ext/wasm/sqlite3-worker1-promiser.js
+F ext/wasm/api/sqlite3-worker1.js 59fd89ee42bc380a053a848d35806177c27eb82684ef152a34c65c7ce1b5d233 w ext/wasm/sqlite3-worker1.js
+F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8
 F ext/wasm/batch-runner.js 5bae81684728b6be157d1f92b39824153f0fd019345b39f2ab8930f7ee2a57d8
 F ext/wasm/common/SqliteTestUtil.js 647bf014bd30bdd870a7e9001e251d12fc1c9ec9ce176a1004b838a4b33c5c05
 F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
 F ext/wasm/common/testing.css 53394885077edd3db22d2a0896192334dfc06fb3d1da0b646eb12a332d22f18e
 F ext/wasm/common/whwasmutil.js 50d2ede0b0fa01c1d467e1801fab79f5e46bb02bcbd2b0232e4fdc6090a47818
-F ext/wasm/demo-123-worker.html e50b51dc7271b9d3cc830cb7c2fba294d622f56b7acb199f7257d11195a63d49
-F ext/wasm/demo-123.html 7c239c9951d1b113f9f532969ac039294cf1dcfee2b3ae0a2c1ed2b3d59f8dfa
-F ext/wasm/demo-123.js e0cbeb3495e14103763d5c49794a24d67cf3d78e0ed5b82843be70c0c2ee4b3b
-F ext/wasm/demo-kvvfs1.html 7d4f28873de67f51ac18c584b7d920825139866a96049a49c424d6f5a0ea5e7f
+F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed
+F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508
+F ext/wasm/demo-123.js ebae30756585bca655b4ab2553ec9236a87c23ad24fc8652115dcedb06d28df6
+F ext/wasm/demo-kvvfs1.html c4a69d2ded9cabad3e2eea75cd2936d9a13002ab4f10b9f1bac6130a0dee84dd
 F ext/wasm/demo-kvvfs1.js 105596bd2ccd0b1deb5fde8e99b536e8242d4bb5932fac0c8403ff3a6bc547e8
 F ext/wasm/dist.make 2015746f6cd37ed17fadb14dba45d41ac6db727917d04f9b9aa431a816c5e54d
-F ext/wasm/fiddle.make a87250f6f973d9632818b9d2396c59e6542da180f8f10b164665a6fc04d239bc
+F ext/wasm/fiddle.make e5a8966be370bf8592cdffb2520ad8c3bf6a64d08ea91c8ed17dc88624967697
 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
 F ext/wasm/fiddle/fiddle-worker.js 531859a471924a0ea48afa218e6877f0c164ca324d51e15843ed6ecc1c65c7ee
 F ext/wasm/fiddle/fiddle.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2
@@ -515,24 +518,21 @@ F ext/wasm/jaccwabyt/jaccwabyt.md 9aa6951b529a8b29f578ec8f0355713c39584c92cf1708
 F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e1029186d836d14b83845fbe06
 F ext/wasm/scratchpad-wasmfs-main.js 1aa32c1035cf1440a226a28fefcbb5762fbbcb020ccbe5895f8736d701695c63
 F ext/wasm/speedtest1-wasmfs.html bc28eb29b69a73864b8d7aae428448f8b7e1de81d8bfb9bba99541322054dbd0
-F ext/wasm/speedtest1-worker.html 17f5b3f0ddb361ea0fdfd58703e42d65b1564c297930ec5fff2cd267e6e252d9
-F ext/wasm/speedtest1-worker.js a9e3d052dd1d8016d6e9a641e596e6d99aec04ef8995d7ee9a85a9964eed771a
-F ext/wasm/speedtest1.html e4cb5d722b494104fc1249e7c008ca018f820a784833c51004c958c71038c80f
+F ext/wasm/speedtest1-worker.html 7b0cceab6a68b2883738e19f61d21620fe1244ba36c1b2e38d0efde57ecce86d
+F ext/wasm/speedtest1-worker.js 3fce67c7d00c9fc42591835a2014520997630e51189f98ca47f706b55cdce8bc
+F ext/wasm/speedtest1.html 00102689678b3c09ae6f5e4b3782e95f448e943a3491246e7be9ee349049bcaf
 F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x
 F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0
 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
-F ext/wasm/sqlite3-opfs-async-proxy.js 206ce6bbc3c30ad51a37d9c25e3a2712e70b586e0f9a2cf8cb0b9619017c2671
-F ext/wasm/sqlite3-worker1-promiser.js 307d7837420ca6a9d3780dfc81194f1c0715637e6d9540e935514086b96913d8
-F ext/wasm/sqlite3-worker1.js 25b29ff23958883e0a772bc835f4f4eb7e1714d7310385ed27106525930c2530
-F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5
-F ext/wasm/test-opfs-vfs.js 56c3d725044c668fa7910451e96c1195d25ad95825f9ac79f747a7759d1973d0
-F ext/wasm/tester1-worker.html 0af7a22025ff1da72a84765d64f8f221844a57c6e6e314acf3a30f176101fd3f
-F ext/wasm/tester1.html fde0e0bdeaaa2c39877c749dc86a8c1c306f771c3d75b89a6289a5ed11243e9d
-F ext/wasm/tester1.js 8161dcc4b21902dadec2d3a5dc5700cab9c1641db0603e2ea56ea2a8de6cbab3
-F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893
-F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9dd8ae2cc8719b506b6e013e
+F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555e685bce3da8c3f
+F ext/wasm/test-opfs-vfs.js 48fc59110e8775bb43c9be25b6d634fc07ebadab7da8fbd44889e8129c6e2548
+F ext/wasm/tester1-worker.html 048c341f124fdb61ca14dfd1bd1f78742490f208aa3bb1e84399f83f1e7e6a74
+F ext/wasm/tester1.html 66b71e2accdcbedae2593c72d2a69f906757707394dc014c2253102f0838cf57
+F ext/wasm/tester1.js 44d71175e2941bf1d7c27afa0c395fe81c83cbd74cd10e34e0688dd833042f1e
+F ext/wasm/testing-worker1-promiser.html 88c6ff8a7be351abef219639cd684c5c3e0c649c1dc07b10a5bd59939e7bb4b5
+F ext/wasm/testing-worker1-promiser.js f68ffbbe1c6086e18ce7961b8fc2b40dd88db174f59052e228c06b07484945ca
 F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3
-F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494
+F ext/wasm/testing2.js 90dc901a54ecc319d09356de2f8c21f53e7f61f2914445e6b176e1bcad12ba8b
 F ext/wasm/version-info.c 5fa356d38859d71a0369b5c37e1935def7413fcc8a4e349a39d9052c1d0479f4
 F ext/wasm/wasmfs.make ee0004813e16c283ff633e08b482008d56adf9b7d42f6c5612f7ab002b924f69
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
@@ -2035,8 +2035,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 2156f0744acfe425457430a0f6a7e02de907de85edba81a6d4eef40293e561c8
-R ee0ece99cec342c109cdb62c53280a5b
+P 5b23e0675efdd2f1ea7b4f5836a579e8d6aa8a25b3f1a6a950520ad845ff01bb
+R 120493b0bac13d94c837a00d100ef2e2
 U stephan
-Z 86621ae22c81858679965e272da6ace1
+Z 1f6ca89c3f0ab931ccb09f09451983aa
 # Remove this line to create a well-formed Fossil manifest.
index 38a86ebeb05a88624a3eae673f76d7c8afcca219..cb6b4b3768bbe7c27c4c60c8ebaa1d3a55b55ea4 100644 (file)
@@ -1 +1 @@
-5b23e0675efdd2f1ea7b4f5836a579e8d6aa8a25b3f1a6a950520ad845ff01bb
\ No newline at end of file
+6d468dab9eb84d4548f68014959f02fe4f66455472ff24fe729382bb2972e3d1
\ No newline at end of file