aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-glue.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-25 10:22:27 +0000
committerstephan <stephan@noemail.net>2022-12-25 10:22:27 +0000
commit75c04ba89cee1bb6b7b2b599eeacfbd063c84703 (patch)
tree99b7501c438e08cf75f1badbb789a1f49c7149d1 /ext/wasm/api/sqlite3-api-glue.js
parent4099b3cab3c3451a2d9643738308be0b2d9e44b1 (diff)
downloadsqlite-75c04ba89cee1bb6b7b2b599eeacfbd063c84703.tar.gz
sqlite-75c04ba89cee1bb6b7b2b599eeacfbd063c84703.zip
Simplify the signature for JS functions, as opposed to function pointers, passed to sqlite3_exec(), eliminating the superfluous initial two arguments. Update related tests to demonstrate both function-passing approaches.
FossilOrigin-Name: e7cc70cdda426863f82ebe1305f4c3053824c5a605b1516b0b7f205f1203178b
Diffstat (limited to 'ext/wasm/api/sqlite3-api-glue.js')
-rw-r--r--ext/wasm/api/sqlite3-api-glue.js39
1 files changed, 20 insertions, 19 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js
index 7b5fa1181..0ef796664 100644
--- a/ext/wasm/api/sqlite3-api-glue.js
+++ b/ext/wasm/api/sqlite3-api-glue.js
@@ -234,7 +234,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
optional features into account. */
wasm.bindingSignatures.push(["sqlite3_normalized_sql", "string", "sqlite3_stmt*"]);
}
-
+
/**
Functions which require BigInt (int64) support are separated from
the others because we need to conditionally bind them or apply
@@ -569,7 +569,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}/*sqlite3_create_collation() and friends*/
- if(1){/* Special-case handling of sqlite3_exec() */
+ {/* Special-case handling of sqlite3_exec() */
const __exec = wasm.xWrap("sqlite3_exec", "int",
["sqlite3*", "string:flexible",
new wasm.xWrap.FuncPtrAdapter({
@@ -585,23 +585,23 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}
/* Wrap the callback in a WASM-bound function and convert the callback's
`(char**)` arguments to arrays of strings... */
+ let aNames;
const cbwrap = function(pVoid, nCols, pColVals, pColNames){
let rc = capi.SQLITE_ERROR;
try {
- let aVals = [], aNames = [], i = 0, offset = 0;
- for( ; i < nCols; offset += (wasm.ptrSizeof * ++i) ){
- aVals.push( wasm.cstrToJs(wasm.peekPtr(pColVals + offset)) );
- aNames.push( wasm.cstrToJs(wasm.peekPtr(pColNames + offset)) );
- }
- rc = callback(pVoid, nCols, aVals, aNames) | 0;
- /* The first 2 args of the callback are useless for JS but
- we want the JS mapping of the C API to be as close to the
- C API as possible. */
+ const aVals = wasm.cArgvToJs(nCols, pColVals);
+ if(!aNames) aNames = wasm.cArgvToJs(nCols, pColNames);
+ rc = callback(aVals, aNames) | 0;
}catch(e){
- /* If we set the db error state here, the higher-level exec() call
- replaces it with its own, so we have no way of reporting the
- exception message except the console. We must not propagate
- exceptions through the C API. */
+ /* If we set the db error state here, the higher-level
+ exec() call replaces it with its own, so we have no way
+ of reporting the exception message except the console. We
+ must not propagate exceptions through the C API. Though
+ we make an effort to report OOM here, sqlite3_exec()
+ translates that into SQLITE_ABORT as well. */
+ rc = (e instanceof sqlite3.WasmAllocError)
+ ? capi.SQLITE_NOMEM
+ : (e.resultCode || capi.SQLITE_ERROR);
}
return rc;
};
@@ -616,7 +616,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
};
}/*sqlite3_exec() proxy*/;
- if(1){/* Special-case handling of sqlite3_create_function_v2()
+ {/* Special-case handling of sqlite3_create_function_v2()
and sqlite3_create_window_function() */
/* Maintenance reminder: FuncPtrAdapter is not expressive enough
to be able to perform these mappings. */
@@ -1041,20 +1041,21 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
toss("Maintenance required: increase sqlite3_wasm_enum_json()'s",
"static buffer size!");
}
- wasm.ctype = JSON.parse(wasm.cstrToJs(cJson));
//console.debug('wasm.ctype length =',wasm.cstrlen(cJson));
+ wasm.ctype = JSON.parse(wasm.cstrToJs(cJson));
+ // Groups of SQLITE_xyz macros...
const defineGroups = ['access', 'authorizer',
'blobFinalizers', 'config', 'dataTypes',
'dbConfig', 'dbStatus',
'encodings', 'fcntl', 'flock', 'ioCap',
'limits', 'openFlags',
'prepareFlags', 'resultCodes',
- 'serialize', 'sqlite3Status',
+ 'sqlite3Status',
'stmtStatus', 'syncFlags',
'trace', 'txnState', 'udfFlags',
'version' ];
if(wasm.bigIntEnabled){
- defineGroups.push('vtab');
+ defineGroups.push('serialize', 'vtab');
}
for(const t of defineGroups){
for(const e of Object.entries(wasm.ctype[t])){