]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Generic cleanups in the OPFS VFS proxies.
authorstephan <stephan@noemail.net>
Mon, 19 Sep 2022 09:58:01 +0000 (09:58 +0000)
committerstephan <stephan@noemail.net>
Mon, 19 Sep 2022 09:58:01 +0000 (09:58 +0000)
FossilOrigin-Name: 7d5f6adc3b964413fc96ad8d2735312c3e58348024cabdd2099682cbf696eaf7

ext/wasm/api/sqlite3-api-opfs.js
ext/wasm/sqlite3-opfs-async-proxy.js
manifest
manifest.uuid

index 6446f2fb35ff56d605ec2dbe43a87d75f726bb27..e0554e8c0ca2cc543f32ee465398a31840034647 100644 (file)
@@ -76,51 +76,46 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
    `opfs` property, containing several OPFS-specific utilities.
 */
 sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
+  delete sqlite3.installOpfsVfs;
+  if(self.window===self ||
+     !self.SharedArrayBuffer ||
+     !self.FileSystemHandle ||
+     !self.FileSystemDirectoryHandle ||
+     !self.FileSystemFileHandle ||
+     !self.FileSystemFileHandle.prototype.createSyncAccessHandle ||
+     !navigator.storage.getDirectory){
+    return Promise.reject(
+      new Error("This environment does not have OPFS support.")
+    );
+  }
   const options = (asyncProxyUri && 'object'===asyncProxyUri) ? asyncProxyUri : {
     proxyUri: asyncProxyUri
   };
-  const thisUrl = new URL(self.location.href);
+  const urlParams = new URL(self.location.href).searchParams;
   if(undefined===options.verbose){
-    options.verbose = thisUrl.searchParams.has('opfs-verbose') ? 3 : 2;
+    options.verbose = urlParams.has('opfs-verbose') ? 3 : 2;
   }
   if(undefined===options.sanityChecks){
-    options.sanityChecks = thisUrl.searchParams.has('opfs-sanity-check');
+    options.sanityChecks = urlParams.has('opfs-sanity-check');
   }
   if(undefined===options.proxyUri){
     options.proxyUri = callee.defaultProxyUri;
   }
-  delete sqlite3.installOpfsVfs;
-
-  /**
-     Generic utilities for working with OPFS. This will get filled out
-     by the Promise setup and, on success, installed as sqlite3.opfs.
-  */
-  const opfsUtil = Object.create(null);
 
   const thePromise = new Promise(function(promiseResolve, promiseReject){
-    const logPrefix = "OPFS syncer:";
-    const warn =  (...args)=>{
-      if(options.verbose>1) console.warn(logPrefix,...args);
+    const loggers = {
+      0:console.error.bind(console),
+      1:console.warn.bind(console),
+      2:console.log.bind(console)
     };
-    if(self.window===self ||
-       !self.SharedArrayBuffer ||
-       !self.FileSystemHandle ||
-       !self.FileSystemDirectoryHandle ||
-       !self.FileSystemFileHandle ||
-       !self.FileSystemFileHandle.prototype.createSyncAccessHandle ||
-       !navigator.storage.getDirectory){
-      warn("This environment does not have OPFS support.");
-      promiseReject(new Error("This environment does not have OPFS support."));
-      return;
-    }
+    const logImpl = (level,...args)=>{
+      if(options.verbose>level) loggers[level]("OPFS syncer:",...args);
+    };
+    const log =    (...args)=>logImpl(2, ...args);
+    const warn =   (...args)=>logImpl(1, ...args);
+    const error =  (...args)=>logImpl(0, ...args);
     warn("The OPFS VFS feature is very much experimental and under construction.");
     const toss = function(...args){throw new Error(args.join(' '))};
-    const log = (...args)=>{
-      if(options.verbose>2) console.log(logPrefix,...args);
-    };
-    const error =  (...args)=>{
-      if(options.verbose>0) console.error(logPrefix,...args);
-    };
     const capi = sqlite3.capi;
     const wasm = capi.wasm;
     const sqlite3_vfs = capi.sqlite3_vfs;
@@ -129,9 +124,16 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri)
     const W = new Worker(options.proxyUri);
     W._originalOnError = W.onerror /* will be restored later */;
     W.onerror = function(err){
+      // The error object doesn't contain any useful info when the
+      // failure is, e.g., that the remote script is 404.
       promiseReject(new Error("Loading OPFS async Worker failed for unknown reasons."));
     };
     const wMsg = (type,payload)=>W.postMessage({type,payload});
+    /**
+       Generic utilities for working with OPFS. This will get filled out
+       by the Promise setup and, on success, installed as sqlite3.opfs.
+    */
+    const opfsUtil = Object.create(null);
 
     /**
        State which we send to the async-api Worker or share with it.
@@ -625,7 +627,8 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri)
         log("xAccess(",dbFile,") exists ?=",rc);
         rc = vfsSyncWrappers.xOpen(opfsVfs.pointer, zDbFile,
                                    fid, openFlags, pOut);
-        log("open rc =",rc,"state.opSABView[xOpen] =",state.opSABView[state.opIds.xOpen]);
+        log("open rc =",rc,"state.opSABView[xOpen] =",
+            state.opSABView[state.opIds.xOpen]);
         if(isWorkerErrCode(rc)){
           error("open failed with code",rc);
           return;
@@ -696,8 +699,8 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri)
               W.onerror = W._originalOnError;
               delete W._originalOnError;
               sqlite3.opfs = opfsUtil;
-              promiseResolve(sqlite3);
               log("End of OPFS sqlite3_vfs setup.", opfsVfs);
+              promiseResolve(sqlite3);
             }catch(e){
               error(e);
               promiseReject(e);
index 3ae6af043ada68513f9717a4836586b89f597549..7eb12425ccd72a01670039423adc624b54e6f7ba 100644 (file)
@@ -49,18 +49,20 @@ const state = Object.create(null);
 */
 state.verbose = 2;
 
-const __logPrefix = "OPFS asyncer:";
-const log = (...args)=>{
-  if(state.verbose>2) console.log(__logPrefix,...args);
+const loggers = {
+  0:console.error.bind(console),
+  1:console.warn.bind(console),
+  2:console.log.bind(console)
 };
-const warn =  (...args)=>{
-  if(state.verbose>1) console.warn(__logPrefix,...args);
-};
-const error =  (...args)=>{
-  if(state.verbose) console.error(__logPrefix,...args);
+const logImpl = (level,...args)=>{
+  if(state.verbose>level) loggers[level]("OPFS asyncer:",...args);
 };
+const log =    (...args)=>logImpl(2, ...args);
+const warn =   (...args)=>logImpl(1, ...args);
+const error =  (...args)=>logImpl(0, ...args);
 
-warn("This file is very much experimental and under construction.",self.location.pathname);
+warn("This file is very much experimental and under construction.",
+     self.location.pathname);
 
 /**
    Map of sqlite3_file pointers (integers) to metadata related to a
@@ -82,7 +84,7 @@ const getResolvedPath = function(filename,splitIt){
     filename, 'file://irrelevant'
   ).pathname;
   return splitIt ? p.split('/').filter((v)=>!!v) : p;
-}
+};
 
 /**
    Takes the absolute path to a filesystem element. Returns an array
index c678bc0b2d346b7f964bcd15026954711b38b9d1..46fcb98d2fb0cd827234d2dddd5e8116ad7b476e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Correct\sOPFS\sVFS\sxRead()\sto\scopy\sthe\sresult\sbuffer\sif\sthe\sresult\scode\sis\sSQLITE_IOERR_SHORT_READ.
-D 2022-09-19T09:25:25.676
+C Generic\scleanups\sin\sthe\sOPFS\sVFS\sproxies.
+D 2022-09-19T09:58:01.741
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -484,7 +484,7 @@ F ext/wasm/api/post-js-header.js 0e853b78db83cb1c06b01663549e0e8b4f377f12f5a2d9a
 F ext/wasm/api/sqlite3-api-cleanup.js 8564a6077cdcaea9a9f428a019af8a05887f0131e6a2a1e72a7ff1145fadfe77
 F ext/wasm/api/sqlite3-api-glue.js 366d580c8e5bf7fcf4c6dee6f646c31f5549bd417ea03a59a0acca00e8ecce30
 F ext/wasm/api/sqlite3-api-oo1.js 2d13dddf0d2b4168a9249f124134d37924331e5b55e05dba18b6d661fbeefe48
-F ext/wasm/api/sqlite3-api-opfs.js 6a48568014dcadee22ff8eaa13deab573fbae362a71194efb6c1214d41d6b48d
+F ext/wasm/api/sqlite3-api-opfs.js 580be306be7301fa0b3cb2abd5765561a3d7f4746a7679f95394af50a14671bb
 F ext/wasm/api/sqlite3-api-prologue.js 4e3e26880d444000cca1b4f3ddfa9d49581dfecd1de9426080239ecc208c447d
 F ext/wasm/api/sqlite3-api-worker1.js ee4cf149cbacb63d06b536674f822aa5088b7e022cdffc69f1f36cebe2f9fea0
 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
@@ -521,7 +521,7 @@ F ext/wasm/speedtest1.html fbb8e4d1639028443f3687a683be660beca6927920545cf6b1fdf
 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 7806909f6957c6173843b53087b7f01fb41fb27f52bdad250fe2081d0fa44f9e
+F ext/wasm/sqlite3-opfs-async-proxy.js 2e9a95fc6204f53ed871d04bdd0341d1c0d1a49c22d43b38144a5319f865930a
 F ext/wasm/sqlite3-worker1-promiser.js 4fd0465688a28a75f1d4ee4406540ba494f49844e3cad0670d0437a001943365
 F ext/wasm/sqlite3-worker1.js 0c1e7626304543969c3846573e080c082bf43bcaa47e87d416458af84f340a9e
 F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5
@@ -2028,8 +2028,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 b9773f164878b0a1b7c88cc7a6d1374ea95f64920065e8b2b178a1afffd82fe5
-R a6befd159a478cdd8d3c42193659027b
+P 56668f9902c6e896b6c63621a444444c6f58ee20f88a5feae97f1699be35892d
+R b87c8cb1e595f1f55de64a473bfd1ee8
 U stephan
-Z 2c8c2a7ce6b266c9bc7d1baf57207e7e
+Z 85b747fc9dead0d23b6c33a91c074db8
 # Remove this line to create a well-formed Fossil manifest.
index e3f6dd88b583ad794f7152759f24942e340224d6..f69e6b9a415e751dd09fa2fcf89f24f262ac7166 100644 (file)
@@ -1 +1 @@
-56668f9902c6e896b6c63621a444444c6f58ee20f88a5feae97f1699be35892d
\ No newline at end of file
+7d5f6adc3b964413fc96ad8d2735312c3e58348024cabdd2099682cbf696eaf7
\ No newline at end of file