summaryrefslogtreecommitdiffstats
path: root/ext/wasm/api/sqlite3-api-prologue.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 05:16:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 05:16:43 +0000
commitfd8f22aa0eaf2a7726a6db288946cd904388ac4e (patch)
tree483f8cace8e3e64c9df42cef34c474bd225209ab /ext/wasm/api/sqlite3-api-prologue.js
parentAdding upstream version 3.45.3. (diff)
downloadsqlite3-fd8f22aa0eaf2a7726a6db288946cd904388ac4e.tar.xz
sqlite3-fd8f22aa0eaf2a7726a6db288946cd904388ac4e.zip
Adding upstream version 3.46.0.upstream/3.46.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ext/wasm/api/sqlite3-api-prologue.js')
-rw-r--r--ext/wasm/api/sqlite3-api-prologue.js84
1 files changed, 62 insertions, 22 deletions
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js
index ef1154f..689c79a 100644
--- a/ext/wasm/api/sqlite3-api-prologue.js
+++ b/ext/wasm/api/sqlite3-api-prologue.js
@@ -37,7 +37,7 @@
This function expects a configuration object, intended to abstract
away details specific to any given WASM environment, primarily so
- that it can be used without any _direct_ dependency on
+ that it can be used without any direct dependency on
Emscripten. (Note the default values for the config object!) The
config object is only honored the first time this is
called. Subsequent calls ignore the argument and return the same
@@ -98,14 +98,37 @@
The returned object is the top-level sqlite3 namespace object.
+
+ Client code may optionally assign sqlite3ApiBootstrap.defaultConfig
+ an object-type value before calling sqlite3ApiBootstrap() (without
+ arguments) in order to tell that call to use this object as its
+ default config value. The intention of this is to provide
+ downstream clients with a reasonably flexible approach for plugging
+ in an environment-suitable configuration without having to define a
+ new global-scope symbol.
+
+ However, because clients who access this library via an
+ Emscripten-hosted module will not have an opportunity to call
+ sqlite3ApiBootstrap() themselves, nor to access it before it is
+ called, an alternative option for setting the configuration is to
+ define globalThis.sqlite3ApiConfig to an object. If it is set, it
+ is used instead of sqlite3ApiBootstrap.defaultConfig if
+ sqlite3ApiBootstrap() is called without arguments.
+
+ Both sqlite3ApiBootstrap.defaultConfig and
+ globalThis.sqlite3ApiConfig get deleted by sqlite3ApiBootstrap()
+ because any changes to them made after that point would have no
+ useful effect.
*/
'use strict';
globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
apiConfig = (globalThis.sqlite3ApiConfig || sqlite3ApiBootstrap.defaultConfig)
){
if(sqlite3ApiBootstrap.sqlite3){ /* already initalized */
- console.warn("sqlite3ApiBootstrap() called multiple times.",
- "Config and external initializers are ignored on calls after the first.");
+ (sqlite3ApiBootstrap.sqlite3.config || console).warn(
+ "sqlite3ApiBootstrap() called multiple times.",
+ "Config and external initializers are ignored on calls after the first."
+ );
return sqlite3ApiBootstrap.sqlite3;
}
const config = Object.assign(Object.create(null),{
@@ -114,8 +137,16 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
bigIntEnabled: (()=>{
if('undefined'!==typeof Module){
/* Emscripten module will contain HEAPU64 when built with
- -sWASM_BIGINT=1, else it will not. */
- return !!Module.HEAPU64;
+ -sWASM_BIGINT=1, else it will not.
+
+ As of emsdk 3.1.55, when building in strict mode, HEAPxyz
+ are only available if _explicitly_ included in the exports,
+ else they are not. We do not (as of 2024-03-04) use -sSTRICT
+ for the canonical builds.
+ */
+ if( !!Module.HEAPU64 ) return true;
+ /* Else fall through and hope for the best. Nobody _really_
+ builds this without BigInt support, do they? */
}
return !!globalThis.BigInt64Array;
})(),
@@ -149,6 +180,15 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
config[k] = config[k]();
}
});
+
+ /**
+ Eliminate any confusion about whether these config objects may
+ be used after library initialization by eliminating the outward-facing
+ objects...
+ */
+ delete globalThis.sqlite3ApiConfig;
+ delete sqlite3ApiBootstrap.defaultConfig;
+
/**
The main sqlite3 binding API gets installed into this object,
mimicking the C API as closely as we can. The numerous members
@@ -205,7 +245,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
The exception's message is created by concatenating its
arguments with a space between each, except for the
- two-args-with-an-objec form and that the first argument will
+ two-args-with-an-object form and that the first argument will
get coerced to a string, as described above, if it's an
integer.
@@ -1061,7 +1101,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
are undefined if the passed-in value did not come from
this.pointer.
*/
- restore: wasm.exports.sqlite3_wasm_pstack_restore,
+ restore: wasm.exports.sqlite3__wasm_pstack_restore,
/**
Attempts to allocate the given number of bytes from the
pstack. On success, it zeroes out a block of memory of the
@@ -1083,7 +1123,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
if('string'===typeof n && !(n = wasm.sizeofIR(n))){
WasmAllocError.toss("Invalid value for pstack.alloc(",arguments[0],")");
}
- return wasm.exports.sqlite3_wasm_pstack_alloc(n)
+ return wasm.exports.sqlite3__wasm_pstack_alloc(n)
|| WasmAllocError.toss("Could not allocate",n,
"bytes from the pstack.");
},
@@ -1163,10 +1203,10 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
*/
pointer: {
configurable: false, iterable: true, writeable: false,
- get: wasm.exports.sqlite3_wasm_pstack_ptr
+ get: wasm.exports.sqlite3__wasm_pstack_ptr
//Whether or not a setter as an alternative to restore() is
//clearer or would just lead to confusion is unclear.
- //set: wasm.exports.sqlite3_wasm_pstack_restore
+ //set: wasm.exports.sqlite3__wasm_pstack_restore
},
/**
sqlite3.wasm.pstack.quota to the total number of bytes
@@ -1175,7 +1215,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
*/
quota: {
configurable: false, iterable: true, writeable: false,
- get: wasm.exports.sqlite3_wasm_pstack_quota
+ get: wasm.exports.sqlite3__wasm_pstack_quota
},
/**
sqlite3.wasm.pstack.remaining resolves to the amount of space
@@ -1183,7 +1223,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
*/
remaining: {
configurable: false, iterable: true, writeable: false,
- get: wasm.exports.sqlite3_wasm_pstack_remaining
+ get: wasm.exports.sqlite3__wasm_pstack_remaining
}
})/*wasm.pstack properties*/;
@@ -1256,14 +1296,14 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
}
try{
if(pdir && 0===wasm.xCallWrapped(
- 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], pdir
+ 'sqlite3__wasm_init_wasmfs', 'i32', ['string'], pdir
)){
return __wasmfsOpfsDir = pdir;
}else{
return __wasmfsOpfsDir = "";
}
}catch(e){
- // sqlite3_wasm_init_wasmfs() is not available
+ // sqlite3__wasm_init_wasmfs() is not available
return __wasmfsOpfsDir = "";
}
};
@@ -1365,7 +1405,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
const zSchema = schema
? (wasm.isPtr(schema) ? schema : wasm.scopedAllocCString(''+schema))
: 0;
- let rc = wasm.exports.sqlite3_wasm_db_serialize(
+ let rc = wasm.exports.sqlite3__wasm_db_serialize(
pDb, zSchema, ppOut, pSize, 0
);
if(rc){
@@ -1391,7 +1431,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
or not provided, then "main" is assumed.
*/
capi.sqlite3_js_db_vfs =
- (dbPointer, dbName=0)=>wasm.sqlite3_wasm_db_vfs(dbPointer, dbName);
+ (dbPointer, dbName=0)=>util.sqlite3__wasm_db_vfs(dbPointer, dbName);
/**
A thin wrapper around capi.sqlite3_aggregate_context() which
@@ -1449,7 +1489,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
if(!util.isInt32(dataLen) || dataLen<0){
SQLite3Error.toss("Invalid 3rd argument for sqlite3_js_posix_create_file().");
}
- const rc = wasm.sqlite3_wasm_posix_create_file(filename, pData, dataLen);
+ const rc = util.sqlite3__wasm_posix_create_file(filename, pData, dataLen);
if(rc) SQLite3Error.toss("Creation of file failed with sqlite3 result code",
capi.sqlite3_js_rc_str(rc));
}finally{
@@ -1551,7 +1591,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
SQLite3Error.toss("Invalid 4th argument for sqlite3_js_vfs_create_file().");
}
try{
- const rc = wasm.sqlite3_wasm_vfs_create_file(vfs, filename, pData, dataLen);
+ const rc = util.sqlite3__wasm_vfs_create_file(vfs, filename, pData, dataLen);
if(rc) SQLite3Error.toss("Creation of file failed with sqlite3 result code",
capi.sqlite3_js_rc_str(rc));
}finally{
@@ -1672,12 +1712,12 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
*/
capi.sqlite3_db_config = function(pDb, op, ...args){
if(!this.s){
- this.s = wasm.xWrap('sqlite3_wasm_db_config_s','int',
+ this.s = wasm.xWrap('sqlite3__wasm_db_config_s','int',
['sqlite3*', 'int', 'string:static']
/* MAINDBNAME requires a static string */);
- this.pii = wasm.xWrap('sqlite3_wasm_db_config_pii', 'int',
+ this.pii = wasm.xWrap('sqlite3__wasm_db_config_pii', 'int',
['sqlite3*', 'int', '*','int', 'int']);
- this.ip = wasm.xWrap('sqlite3_wasm_db_config_ip','int',
+ this.ip = wasm.xWrap('sqlite3__wasm_db_config_ip','int',
['sqlite3*', 'int', 'int','*']);
}
switch(op){
@@ -1798,7 +1838,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
/**
Calls either sqlite3_result_error_nomem(), if e is-a
WasmAllocError, or sqlite3_result_error(). In the latter case,
- the second arugment is coerced to a string to create the error
+ the second argument is coerced to a string to create the error
message.
The first argument is a (sqlite3_context*). Returns void.