| 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'; |
| 19 |
if('undefined' !== typeof Module){ // presumably an Emscripten build |
| 20 |
/** |
| 21 |
Install a suitable default configuration for sqlite3ApiBootstrap(). |
| 22 |
*/ |
| 23 |
const SABC = Object.assign( |
| 24 |
Object.create(null), { |
| 25 |
exports: ('undefined'===typeof wasmExports) |
| 26 |
? Module['asm']/* emscripten <=3.1.43 */ |
| 27 |
: wasmExports /* emscripten >=3.1.44 */, |
| 28 |
memory: Module.wasmMemory /* gets set if built with -sIMPORTED_MEMORY */ |
| 29 |
}, |
| 30 |
globalThis.sqlite3ApiConfig || {} |
| 31 |
); |
| 32 |
|
| 33 |
/** |
| 34 |
For current (2022-08-22) purposes, automatically call |
| 35 |
sqlite3ApiBootstrap(). That decision will be revisited at some |
| 36 |
point, as we really want client code to be able to call this to |
| 37 |
configure certain parts. Clients may modify |
| 38 |
globalThis.sqlite3ApiBootstrap.defaultConfig to tweak the default |
| 39 |
configuration used by a no-args call to sqlite3ApiBootstrap(), |
| 40 |
but must have first loaded their WASM module in order to be |
| 41 |
able to provide the necessary configuration state. |
| 42 |
*/ |
| 43 |
//console.warn("globalThis.sqlite3ApiConfig = ",globalThis.sqlite3ApiConfig); |
| 44 |
globalThis.sqlite3ApiConfig = SABC; |
| 45 |
let sqlite3; |
| 46 |
try{ |
| 47 |
sqlite3 = globalThis.sqlite3ApiBootstrap(); |
| 48 |
}catch(e){ |
| 49 |
console.error("sqlite3ApiBootstrap() error:",e); |
| 50 |
throw e; |
| 51 |
}finally{ |
| 52 |
delete globalThis.sqlite3ApiBootstrap; |
| 53 |
delete globalThis.sqlite3ApiConfig; |
| 54 |
} |
| 55 |
|
| 56 |
Module.sqlite3 = sqlite3 /* Needed for customized sqlite3InitModule() to be able to |
| 57 |
pass the sqlite3 object off to the client. */; |
| 58 |
}else{ |
| 59 |
console.warn("This is not running in an Emscripten module context, so", |
| 60 |
"globalThis.sqlite3ApiBootstrap() is _not_ being called due to lack", |
| 61 |
"of config info for the WASM environment.", |
| 62 |
"It must be called manually."); |
| 63 |
} |