diff options
author | stephan <stephan@noemail.net> | 2022-08-22 21:37:17 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-08-22 21:37:17 +0000 |
commit | ae708b2b018ac558b2f5c7626269415c86e85382 (patch) | |
tree | a1fafc97f0ae6b2c64349ddef9a09da0790d2adb /ext/wasm/api/sqlite3-api-cleanup.js | |
parent | 7a8a0fceeca3ae88595c539bc2394ea8c74cf793 (diff) | |
download | sqlite-ae708b2b018ac558b2f5c7626269415c86e85382.tar.gz sqlite-ae708b2b018ac558b2f5c7626269415c86e85382.zip |
More experimentation with how client-side config state can be passed on to initialize the JS-side sqlite3 API.
FossilOrigin-Name: ea2acc454c012a62556f6d0623d6eff60736d24aa214a64462b423623ef44d47
Diffstat (limited to 'ext/wasm/api/sqlite3-api-cleanup.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-cleanup.js | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/ext/wasm/api/sqlite3-api-cleanup.js b/ext/wasm/api/sqlite3-api-cleanup.js index ce24ad013..d989facca 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 */; +} |