diff options
author | stephan <stephan@noemail.net> | 2022-08-22 13:34:13 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-08-22 13:34:13 +0000 |
commit | e3cd67603dc30d00e998bc9fb3183d49f43b830b (patch) | |
tree | 801653805886fe47c165b8f8ad83cf5b58cbbfc5 /ext/wasm/api/sqlite3-api-cleanup.js | |
parent | 64d04a8d9fc15496ebab111972f4b3ae1578148a (diff) | |
download | sqlite-e3cd67603dc30d00e998bc9fb3183d49f43b830b.tar.gz sqlite-e3cd67603dc30d00e998bc9fb3183d49f43b830b.zip |
Refactor JS API amalgamation such that the bootstrapping/configuration is deferred until the whole amalgamation is available, to facilitate providing clients with a way to initialize the API with their own config (noting that we're still one small level of refactoring away from being able to actually do that).
FossilOrigin-Name: 9dbe9a6aecec43b51057375ef1d2d632db0d17eac8b7552c20cc91fc2f1a55d1
Diffstat (limited to 'ext/wasm/api/sqlite3-api-cleanup.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-cleanup.js | 68 |
1 files changed, 42 insertions, 26 deletions
diff --git a/ext/wasm/api/sqlite3-api-cleanup.js b/ext/wasm/api/sqlite3-api-cleanup.js index a2f921a5d..ce24ad013 100644 --- a/ext/wasm/api/sqlite3-api-cleanup.js +++ b/ext/wasm/api/sqlite3-api-cleanup.js @@ -16,29 +16,45 @@ various subsystems. */ 'use strict'; -self.sqlite3.postInit.forEach( - self.importScripts/*global is a Worker*/ - ? function(f){ - /** We try/catch/report for the sake of failures which happen in - a Worker, as those exceptions can otherwise get completely - swallowed, leading to confusing downstream errors which have - nothing to do with this failure. */ - try{ f(self, self.sqlite3) } - catch(e){ - console.error("Error in postInit() function:",e); - throw e; - } - } - : (f)=>f(self, self.sqlite3) -); -delete self.sqlite3.postInit; -if(self.location && +self.location.port > 1024){ - console.warn("Installing sqlite3 bits as global S for dev-testing purposes."); - self.S = self.sqlite3; -} -/* Clean up temporary global-scope references to our APIs... */ -self.sqlite3.config.Module.sqlite3 = self.sqlite3 -/* ^^^^ Currently needed by test code and Worker API setup */; -delete self.sqlite3.capi.util /* arguable, but these are (currently) internal-use APIs */; -delete self.sqlite3 /* clean up our global-scope reference */; -//console.warn("Module.sqlite3 =",Module.sqlite3); +(function(){ + /** + Replace sqlite3ApiBootstrap() with a variant which plugs in the + Emscripten-based config for all config options which the client + does not provide. + */ + const SAB = self.sqlite3ApiBootstrap; + self.sqlite3ApiBootstrap = function(apiConfig){ + apiConfig = apiConfig||{}; + const configDefaults = { + Module: Module /* ==> Emscripten-style Module object. Currently + needs to be exposed here for test code. NOT part + of the public API. */, + exports: Module['asm'], + memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */ + }; + const config = {}; + Object.keys(configDefaults).forEach(function(k){ + config[k] = Object.prototype.hasOwnProperty.call(apiConfig, k) + ? apiConfig[k] : configDefaults[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(); + + if(self.location && +self.location.port > 1024){ + console.warn("Installing sqlite3 bits as global S for dev-testing purposes."); + self.S = sqlite3; + } + + /* 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); +})(); |