diff options
author | stephan <stephan@noemail.net> | 2022-12-01 03:55:28 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-01 03:55:28 +0000 |
commit | 2b2199570da5d8e3e6a5cf1caae97a66b705124f (patch) | |
tree | bb2074189e99113a35d32bd25f4c2d92cac68a6d /ext/wasm/api/sqlite3-api-glue.js | |
parent | 85ec20ac66d0a5fe8d6ae4769216bd06338d9a9f (diff) | |
download | sqlite-2b2199570da5d8e3e6a5cf1caae97a66b705124f.tar.gz sqlite-2b2199570da5d8e3e6a5cf1caae97a66b705124f.zip |
Expand "sqlite3_vfs*" JS-to-WASM function argument conversions to accept VFS names (JS strings) and capi.sqlite3_vfs instances. Implement sqlite3_js_vfs_create_file() to facilitate creation of file-upload features which store the file in VFS-specific storage (where possible, e.g. "unix" and "opfs" VFSes). Correct an argument type check in the SQLite3Error and WasmAllocError constructors.
FossilOrigin-Name: e1009b16d351b23676ad7bffab0c91b373a92132eb855c9af61991b50cd237ed
Diffstat (limited to 'ext/wasm/api/sqlite3-api-glue.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-glue.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index 6c1fcae82..aa0d48af5 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -73,8 +73,27 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ('sqlite3_stmt*', aPtr) ('sqlite3_context*', aPtr) ('sqlite3_value*', aPtr) - ('sqlite3_vfs*', aPtr) - ('void*', aPtr); + ('void*', aPtr) + /** + `sqlite3_vfs*`: + + - v is-a string: use the result of sqlite3_vfs_find(v) but + throw if it returns 0. + - v is-a capi.sqlite3_vfs: use v.pointer. + - Else return the same as the `'*'` argument conversion. + */ + ('sqlite3_vfs*', (v)=>{ + if('string'===typeof v){ + const x = capi.sqlite3_vfs_find(v); + /* A NULL sqlite3_vfs pointer will be treated as the default + VFS in many contexts. We specifically do not want that + behavior here. */ + if(!x) sqlite3.SQLite3Error.toss("Unknown sqlite3_vfs name:",v); + return x; + }else if(v instanceof sqlite3.capi.sqlite3_vfs) v = v.pointer; + return aPtr(v); + }); + wasm.xWrap.resultAdapter('sqlite3*', aPtr) ('sqlite3_context*', aPtr) ('sqlite3_stmt*', aPtr) @@ -588,8 +607,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ 'version' ]){ for(const e of Object.entries(wasm.ctype[t])){ - // ^^^ [k,v] there triggers a buggy code transormation via one - // of the Emscripten-driven optimizers. + // ^^^ [k,v] there triggers a buggy code transformation via + // one of the Emscripten-driven optimizers. capi[e[0]] = e[1]; } } |