1/* 2 2022-07-22 3 4 The author disclaims copyright to this source code. In place of a 5 legal notice, here is a blessing: 6 7 * May you do good and not evil. 8 * May you find forgiveness for yourself and forgive others. 9 * May you share freely, never taking more than you give. 10 11 *********************************************************************** 12 13 This file is the tail end of the sqlite3-api.js constellation, 14 intended to be appended after all other sqlite3-api-*.js files so 15 that it can finalize any setup and clean up any global symbols 16 temporarily used for setting up the API's various subsystems. 17*/ 18'use strict'; 19if('undefined' !== typeof Module){ // presumably an Emscripten build 20 /** 21 Replace sqlite3ApiBootstrap() with a variant which plugs in the 22 Emscripten-based config for all config options which the client 23 does not provide. 24 */ 25 const SAB = self.sqlite3ApiBootstrap; 26 self.sqlite3ApiBootstrap = function(apiConfig){ 27 apiConfig = apiConfig || {}; 28 const configDefaults = { 29 Module: Module /* ==> Emscripten-style Module object. Currently 30 needs to be exposed here for test code. NOT part 31 of the public API. */, 32 exports: Module['asm'], 33 memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */ 34 }; 35 const config = {}; 36 Object.keys(configDefaults).forEach(function(k){ 37 config[k] = Object.getOwnPropertyDescriptor(apiConfig, k) 38 ? apiConfig[k] : configDefaults[k]; 39 }); 40 // Copy over any properties apiConfig defines but configDefaults does not... 41 Object.keys(apiConfig).forEach(function(k){ 42 if(!Object.getOwnPropertyDescriptor(config, k)){ 43 config[k] = apiConfig[k]; 44 } 45 }); 46 return SAB(config); 47 }; 48 49 /** 50 For current (2022-08-22) purposes, automatically call 51 sqlite3ApiBootstrap(). That decision will be revisited at some 52 point, as we really want client code to be able to call this to 53 configure certain parts. If the global sqliteApiConfig property 54 is available, it is assumed to be a config object for 55 sqlite3ApiBootstrap(). 56 */ 57 //console.warn("self.sqlite3ApiConfig = ",self.sqlite3ApiConfig); 58 const sqlite3 = self.sqlite3ApiBootstrap(self.sqlite3ApiConfig || Object.create(null)); 59 delete self.sqlite3ApiBootstrap; 60 61 if(self.location && +self.location.port > 1024){ 62 console.warn("Installing sqlite3 bits as global S for dev-testing purposes."); 63 self.S = sqlite3; 64 } 65 66 /* Clean up temporary references to our APIs... */ 67 delete sqlite3.capi.util /* arguable, but these are (currently) internal-use APIs */; 68 //console.warn("Module.sqlite3 =",Module.sqlite3); 69 Module.sqlite3 = sqlite3 /* Currently needed by test code and sqlite3-worker1.js */; 70} 71