mirror of
https://github.com/sqlite/sqlite.git
synced 2025-10-24 09:53:10 +03:00
Generic cleanups and simplifications in JS code.
FossilOrigin-Name: 074cf4e6c1775900204bb0d920111ee19601d5c63690e79e988e7fe6b040a647
This commit is contained in:
@@ -19,59 +19,51 @@
|
||||
handler.
|
||||
*/
|
||||
'use strict';
|
||||
if('undefined' !== typeof Module){ // presumably an Emscripten build
|
||||
/**
|
||||
The WASM-environment-specific configuration pieces
|
||||
for sqlite3ApiBootstrap().
|
||||
*/
|
||||
const SABC = Object.assign(
|
||||
Object.create(null),
|
||||
globalThis.sqlite3ApiConfig || {}, {
|
||||
exports: ('undefined'===typeof wasmExports)
|
||||
? Module['asm']/* emscripten <=3.1.43 */
|
||||
: wasmExports /* emscripten >=3.1.44 */,
|
||||
memory: Module.wasmMemory /* gets set if built with -sIMPORTED_MEMORY */
|
||||
}
|
||||
);
|
||||
|
||||
/** Figure out if this is a 32- or 64-bit WASM build. */
|
||||
switch( typeof SABC.exports.sqlite3_libversion() ){
|
||||
case 'number':
|
||||
SABC.wasmPtrIR = 'i32';
|
||||
SABC.wasmPtrSize = 4;
|
||||
break;
|
||||
case 'bigint':
|
||||
SABC.wasmPtrIR = 'i64';
|
||||
SABC.wasmPtrSize = 8;
|
||||
break;
|
||||
default:
|
||||
throw new Error("Cannot determine whether this is a 32- or 64-bit build");
|
||||
}
|
||||
|
||||
/**
|
||||
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. Clients may modify
|
||||
globalThis.sqlite3ApiBootstrap.defaultConfig to tweak the default
|
||||
configuration used by a no-args call to sqlite3ApiBootstrap(),
|
||||
but must have first loaded their WASM module in order to be
|
||||
able to provide the necessary configuration state.
|
||||
*/
|
||||
//console.warn("globalThis.sqlite3ApiConfig = ",globalThis.sqlite3ApiConfig);
|
||||
if( 'undefined' !== typeof Module ){ // presumably an Emscripten build
|
||||
try{
|
||||
/**
|
||||
The WASM-environment-dependent configuration for
|
||||
sqlite3ApiBootstrap().
|
||||
*/
|
||||
const SABC = Object.assign(
|
||||
Object.create(null),
|
||||
globalThis.sqlite3ApiConfig || {}, {
|
||||
memory: ('undefined'!==typeof wasmMemory)
|
||||
? wasmMemory
|
||||
: Module['wasmMemory'],
|
||||
exports: ('undefined'!==typeof wasmExports)
|
||||
? wasmExports /* emscripten >=3.1.44 */
|
||||
: (Object.prototype.hasOwnProperty.call(Module,'wasmExports')
|
||||
? Module['wasmExports']
|
||||
: Module['asm']/* emscripten <=3.1.43 */)
|
||||
},
|
||||
);
|
||||
|
||||
/** Figure out if this is a 32- or 64-bit WASM build. */
|
||||
SABC.wasmPtrIR = 'number'===(typeof SABC.exports.sqlite3_libversion())
|
||||
? 'i32' :'i64';
|
||||
|
||||
/**
|
||||
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. Clients may modify
|
||||
globalThis.sqlite3ApiBootstrap.defaultConfig to tweak the default
|
||||
configuration used by a no-args call to sqlite3ApiBootstrap(),
|
||||
but must have first loaded their WASM module in order to be
|
||||
able to provide the necessary configuration state.
|
||||
*/
|
||||
//console.warn("globalThis.sqlite3ApiConfig = ",globalThis.sqlite3ApiConfig);
|
||||
Module.sqlite3 = globalThis.sqlite3ApiBootstrap(SABC)
|
||||
/* Our customized sqlite3InitModule() in extern-post-js.js needs
|
||||
this to be able to pass the sqlite3 object off to the
|
||||
client. */;
|
||||
/* Our customized sqlite3InitModule() in extern-post-js.js needs
|
||||
this to be able to pass the sqlite3 object off to the
|
||||
client. */;
|
||||
delete globalThis.sqlite3ApiBootstrap;
|
||||
delete globalThis.sqlite3ApiConfig;
|
||||
}catch(e){
|
||||
console.error("sqlite3ApiBootstrap() error:",e);
|
||||
throw e;
|
||||
}finally{
|
||||
delete globalThis.sqlite3ApiBootstrap;
|
||||
delete globalThis.sqlite3ApiConfig;
|
||||
}
|
||||
|
||||
}else{
|
||||
console.warn("This is not running in an Emscripten module context, so",
|
||||
"globalThis.sqlite3ApiBootstrap() is _not_ being called due to lack",
|
||||
|
||||
Reference in New Issue
Block a user