diff --git a/ext/wasm/api/sqlite3-api-cleanup.js b/ext/wasm/api/sqlite3-api-cleanup.js index ce24ad0137..d989faccaf 100644 --- a/ext/wasm/api/sqlite3-api-cleanup.js +++ b/ext/wasm/api/sqlite3-api-cleanup.js @@ -11,12 +11,12 @@ *********************************************************************** This file is the tail end of the sqlite3-api.js constellation, - intended to be appended after all other files so that it can clean - up any global systems temporarily used for setting up the API's - various subsystems. + intended to be appended after all other sqlite3-api-*.js files so + that it can finalize any setup and clean up any global symbols + temporarily used for setting up the API's various subsystems. */ 'use strict'; -(function(){ +if('undefined' !== typeof Module){ // presumably an Emscripten build /** Replace sqlite3ApiBootstrap() with a variant which plugs in the Emscripten-based config for all config options which the client @@ -24,7 +24,7 @@ */ const SAB = self.sqlite3ApiBootstrap; self.sqlite3ApiBootstrap = function(apiConfig){ - apiConfig = apiConfig||{}; + apiConfig = apiConfig || {}; const configDefaults = { Module: Module /* ==> Emscripten-style Module object. Currently needs to be exposed here for test code. NOT part @@ -34,18 +34,29 @@ }; const config = {}; Object.keys(configDefaults).forEach(function(k){ - config[k] = Object.prototype.hasOwnProperty.call(apiConfig, k) + config[k] = Object.getOwnPropertyDescriptor(apiConfig, k) ? apiConfig[k] : configDefaults[k]; }); + // Copy over any properties apiConfig defines but configDefaults does not... + Object.keys(apiConfig).forEach(function(k){ + if(!Object.getOwnPropertyDescriptor(config, k)){ + config[k] = apiConfig[k]; + } + }); return SAB(config); }; /** - For current (2022-08-22) purposes, automatically call sqlite3ApiBootstrap(). - That decision will be revisited at some point, as we really want client code - to be able to call this to configure certain parts. - */ - const sqlite3 = self.sqlite3ApiBootstrap(); + For current (2022-08-22) purposes, automatically call + sqlite3ApiBootstrap(). That decision will be revisited at some + point, as we really want client code to be able to call this to + configure certain parts. If the global sqliteApiConfig property + is available, it is assumed to be a config object for + sqlite3ApiBootstrap(). + */ + //console.warn("self.sqlite3ApiConfig = ",self.sqlite3ApiConfig); + const sqlite3 = self.sqlite3ApiBootstrap(self.sqlite3ApiConfig || Object.create(null)); + delete self.sqlite3ApiBootstrap; if(self.location && +self.location.port > 1024){ console.warn("Installing sqlite3 bits as global S for dev-testing purposes."); @@ -53,8 +64,7 @@ } /* Clean up temporary references to our APIs... */ - delete self.sqlite3ApiBootstrap; - Module.sqlite3 = sqlite3 /* Currently needed by test code */; delete sqlite3.capi.util /* arguable, but these are (currently) internal-use APIs */; //console.warn("Module.sqlite3 =",Module.sqlite3); -})(); + Module.sqlite3 = sqlite3 /* Currently needed by test code and sqlite3-worker1.js */; +} diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 87cc40b410..1a38f0343a 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -134,7 +134,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(apiConfig){ return sqlite3ApiBootstrap.sqlite3; } - apiConfig = apiConfig||{}; + apiConfig = apiConfig || {}; const config = Object.create(null); { const configDefaults = { @@ -147,9 +147,15 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(apiConfig){ persistentDirName: '/persistent' }; Object.keys(configDefaults).forEach(function(k){ - config[k] = Object.prototype.hasOwnProperty.call(apiConfig, k) + config[k] = Object.getOwnPropertyDescriptor(apiConfig, k) ? apiConfig[k] : configDefaults[k]; }); + // Copy over any properties apiConfig defines but configDefaults does not... + Object.keys(apiConfig).forEach(function(k){ + if(!Object.getOwnPropertyDescriptor(config, k)){ + config[k] = apiConfig[k]; + } + }); } /** Throws a new Error, the message of which is the concatenation diff --git a/ext/wasm/common/SqliteTestUtil.js b/ext/wasm/common/SqliteTestUtil.js index c7c99240e6..4b4cefbf0c 100644 --- a/ext/wasm/common/SqliteTestUtil.js +++ b/ext/wasm/common/SqliteTestUtil.js @@ -168,6 +168,33 @@ } f.ui.status.classList.add('hidden'); } + }, + /** + Config options used by the Emscripten-dependent initialization + which happens via this.initSqlite3(). This object gets + (indirectly) passed to sqlite3ApiBootstrap() to configure the + sqlite3 API. + */ + sqlite3ApiConfig: { + persistentDirName: "/persistent" + }, + /** + Intended to be called by apps which need to call the + Emscripten-installed sqlite3InitModule() routine. This function + temporarily installs this.sqlite3ApiConfig into the self + object, calls it sqlite3InitModule(), and removes + self.sqlite3ApiConfig after initialization is done. Returns the + promise from sqlite3InitModule(), and the next then() handler + will get the Emscripten module object as its argument. That + module has the sqlite3's main namespace object installed as its + `sqlite3` property. + */ + initSqlite3: function(){ + self.sqlite3ApiConfig = this.sqlite3ApiConfig; + return self.sqlite3InitModule(this).then(function(M){ + delete self.sqlite3ApiConfig; + return M; + }); } }; })(self/*window or worker*/); diff --git a/ext/wasm/demo-oo1.js b/ext/wasm/demo-oo1.js index 1ea7e05c64..4eff51b8e8 100644 --- a/ext/wasm/demo-oo1.js +++ b/ext/wasm/demo-oo1.js @@ -26,8 +26,13 @@ oo = sqlite3.oo1, wasm = capi.wasm; - const dbDir = 1 ? "" : capi.sqlite3_web_persistent_dir(); - const db = new oo.DB(dbDir+"/mydb.sqlite3"); + const dbName = ( + 0 ? "" : capi.sqlite3_web_persistent_dir() + )+"/mydb.sqlite3" + if(0 && capi.sqlite3_web_persistent_dir()){ + capi.sqlite3_wasm_vfs_unlink(dbName); + } + const db = new oo.DB(dbName); log("db =",db.filename); /** Never(!) rely on garbage collection to clean up DBs and @@ -224,7 +229,7 @@ }/*demo1()*/; const runDemos = function(Module){ - //log("Module",Module); + //log("Module.sqlite3",Module); const sqlite3 = Module.sqlite3, capi = sqlite3.capi; log("Loaded module:",capi.sqlite3_libversion(), capi.sqlite3_sourceid()); @@ -237,5 +242,6 @@ } }; - sqlite3InitModule(self.sqlite3TestModule).then(runDemos); + //self.sqlite3TestModule.sqlite3ApiConfig.persistentDirName = "/hi"; + self.sqlite3TestModule.initSqlite3().then(runDemos); })(); diff --git a/ext/wasm/testing1.js b/ext/wasm/testing1.js index 28f2b604b4..4144219527 100644 --- a/ext/wasm/testing1.js +++ b/ext/wasm/testing1.js @@ -1068,13 +1068,7 @@ log('capi.wasm.exports',capi.wasm.exports); }; - sqlite3InitModule(self.sqlite3TestModule).then(function(theModule){ - /** Use a timeout so that we are (hopefully) out from under - the module init stack when our setup gets run. Just on - principle, not because we _need_ to be. */ - //console.debug("theModule =",theModule); - //setTimeout(()=>runTests(theModule), 0); - // ^^^ Chrome warns: "VIOLATION: setTimeout() handler took A WHOLE 50ms!" + self.sqlite3TestModule.initSqlite3().then(function(theModule){ self._MODULE = theModule /* this is only to facilitate testing from the console */ runTests(theModule); }); diff --git a/manifest b/manifest index bab5e7c63d..b297210960 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sin\strunk. -D 2022-08-22T14:03:11.661 +C More\sexperimentation\swith\show\sclient-side\sconfig\sstate\scan\sbe\spassed\son\sto\sinitialize\sthe\sJS-side\ssqlite3\sAPI. +D 2022-08-22T21:37:17.339 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -481,20 +481,20 @@ F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de F ext/wasm/api/README.md d876597edd2b9542b6ea031adaaff1c042076fde7b670b1dc6d8a87b28a6631b F ext/wasm/api/post-js-footer.js b64319261d920211b8700004d08b956a6c285f3b0bba81456260a713ed04900c F ext/wasm/api/post-js-header.js 0e853b78db83cb1c06b01663549e0e8b4f377f12f5a2d9a4a06cb776c003880b -F ext/wasm/api/sqlite3-api-cleanup.js eee5ac931fa0aee2cace52a0dff0cf22ae56a1993a88d911bd0dd384fb380c9a +F ext/wasm/api/sqlite3-api-cleanup.js acf798ce96285c0d52738466a96c9deb9d66647f711a40caecab90b5ce66ac3c F ext/wasm/api/sqlite3-api-glue.js 67ca83974410961953eeaa1dfed3518530d68381729ed1d27f95122f5baeabd3 F ext/wasm/api/sqlite3-api-oo1.js f6dcaac3270182471f97efcfda25bd4a4ac1777b8ec52ebd1c6846721160e54c F ext/wasm/api/sqlite3-api-opfs.js 011799db398157cbd254264b6ebae00d7234b93d0e9e810345f213a5774993c0 -F ext/wasm/api/sqlite3-api-prologue.js 5d1b13b23af48ce952e30a0f2d6dff4bc4b33f2dc36fdcaf69c164fd9a72b60f +F ext/wasm/api/sqlite3-api-prologue.js 6e0e7787ed955ea2b6158e0bb7608f63b54236847700d183e49e1f10d0525b8f F ext/wasm/api/sqlite3-api-worker1.js ceb1fc88d8a3742c069632e88fd05c14d5a79eb86bdb9e12969ec37f64fbf42b F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 F ext/wasm/api/sqlite3-wasm.c 0d81282eaeff2a6e9fc5c28a388c5c5b45cf25a9393992fa511ac009b27df982 -F ext/wasm/common/SqliteTestUtil.js e41a1406f18da9224523fad0c48885caf995b56956a5b9852909c0989e687e90 +F ext/wasm/common/SqliteTestUtil.js 04156a3b714b1b17a7261d21dd51341a8aeb9880a223e1e7519de98c2cceb414 F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/common/testing.css 572cf1ffae0b6eb7ca63684d3392bf350217a07b90e7a896e4fa850700c989b0 F ext/wasm/common/whwasmutil.js 41b8e097e0a9cb07c24c0ede3c81b72470a63f4a4efb07f75586dc131569f5ae F ext/wasm/demo-oo1.html 75646855b38405d82781246fd08c852a2b3bee05dd9f0fe10ab655a8cffb79aa -F ext/wasm/demo-oo1.js 8be9c6be3c8e579eab4e7a5ee720ed122e38275a1f105169c6826193e42cf102 +F ext/wasm/demo-oo1.js 04e947b64a36ed8d6fe6d5e3ccee16ffc8b4461dd186e84f4baf44d53cc3aa72 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js bccf46045be8824752876f3eec01c223be0616ccac184bffd0024cfe7a3262b8 F ext/wasm/fiddle/fiddle.html 550c5aafce40bd218de9bf26192749f69f9b10bc379423ecd2e162bcef885c08 @@ -510,7 +510,7 @@ F ext/wasm/scratchpad-opfs-worker.js 3ec2868c669713145c76eb5877c64a1b20741f74181 F ext/wasm/scratchpad-opfs-worker2.js 5f2237427ac537b8580b1c659ff14ad2621d1694043eaaf41ae18dbfef2e48c0 F ext/wasm/sqlite3-worker1.js e93fe8e5da7cb56dcf4d1bb0aa44bf681b509e1c56f2a75885c0f408f034c42b F ext/wasm/testing1.html 528001c7e32ee567abc195aa071fd9820cc3c8ffc9c8a39a75e680db05f0c409 -F ext/wasm/testing1.js 9a97a7e45ce122b479b4a706ae1024abded67fd5f34a5764e41ff5efde8dfa17 +F ext/wasm/testing1.js 2def7a86c52ff28b145cb86188d5c7a49d5993f9b78c50d140e1c31551220955 F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3 F ext/wasm/testing2.js e16ae385cd24c4a4ec5de6f1c02e621d243e1f179204ac8df31068faa9e31b1a F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x @@ -2006,8 +2006,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 9dbe9a6aecec43b51057375ef1d2d632db0d17eac8b7552c20cc91fc2f1a55d1 e5eaa80e81fdf86f2875a912b880272b8d099b82b08e945a7988c5dd0fe9d6b5 -R 98198d4c07340458e933c1601dce5a74 +P e215d55a97e1ccbca3101621374444d2381d87ef8e8fde5271e31c8b714e43e9 +R 46e3280ce6b3dabfd5a5df8623d5cf20 U stephan -Z cff3826d5874cd44103730340fc5de2d +Z e9aff16acc00367edea41a90ce619433 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 31636b0764..bb6efe14bd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e215d55a97e1ccbca3101621374444d2381d87ef8e8fde5271e31c8b714e43e9 \ No newline at end of file +ea2acc454c012a62556f6d0623d6eff60736d24aa214a64462b423623ef44d47 \ No newline at end of file