diff options
author | stephan <stephan@noemail.net> | 2022-12-25 15:14:10 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-25 15:14:10 +0000 |
commit | 3494ec15e574fe752dbbca78cf2d21156f7da68b (patch) | |
tree | 82a4187b5b649c4f0bc34a3d95b78c5609da139e /ext/wasm/api/sqlite3-api-glue.js | |
parent | 04071524ae6e4e86a1c670a9432b016b40889100 (diff) | |
download | sqlite-3494ec15e574fe752dbbca78cf2d21156f7da68b.tar.gz sqlite-3494ec15e574fe752dbbca78cf2d21156f7da68b.zip |
Update the session-related JS bindings to account for today's internal API changes.
FossilOrigin-Name: be63944d4114f53f2dab65bc6c1b85f4766a4ea14ee7b2690acde239a2a0bf54
Diffstat (limited to 'ext/wasm/api/sqlite3-api-glue.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-glue.js | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index fc5e2823d..91be75b81 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -317,16 +317,23 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ // Add session/changeset APIs... if(wasm.bigIntEnabled && !!wasm.exports.sqlite3changegroup_add){ /* ACHTUNG: 2022-12-23: the session/changeset API bindings are - COMPLETELY UNTESTED. Additionally, the callback-taking APIs - have a shortcoming which will make using those which take - string-type arguments more painful than it should be. How best - to resolve that, such that we can perform the same type conversions - as we do when binding in "the other direction," is as yet - undetermined. + COMPLETELY UNTESTED. */ + /** + FuncPtrAdapter options for session-related callbacks with the + native signature "i(ps)". This proxy converts the 2nd argument + from a C string to a JS string before passing the arguments on + to the client-provided JS callback. */ - /* TODO: we need hand-written wrappers to adapt callbacks which - take string arguments. Or we need to find a way to do this sort - of reverse-binding which includes type conversions. */ + const __ipsProxy = { + signature: 'i(ps)', + callProxy:(callback)=>{ + return (p,s)=>{ + try{return callback(p, wasm.cstrToJs(s)) | 0} + catch(e){return e.resultCode || capi.SQLITE_ERROR} + } + } + }; + wasm.bindingSignatures.int64.push(...[ ['sqlite3changegroup_add', 'int', ['sqlite3_changegroup*', 'int', 'void*']], ['sqlite3changegroup_add_strm', 'int', [ @@ -349,7 +356,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ['sqlite3changeset_apply', 'int', [ 'sqlite3*', 'int', 'void*', new wasm.xWrap.FuncPtrAdapter({ - name: 'xFilter', signature: 'i(ps)', bindScope: 'transient' + name: 'xFilter', bindScope: 'transient', ...__ipsProxy }), new wasm.xWrap.FuncPtrAdapter({ name: 'xConflict', signature: 'i(pip)', bindScope: 'transient' @@ -363,7 +370,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }), 'void*', new wasm.xWrap.FuncPtrAdapter({ - name: 'xFilter', signature: 'i(ps)', bindScope: 'transient' + name: 'xFilter', bindScope: 'transient', ...__ipsProxy }), new wasm.xWrap.FuncPtrAdapter({ name: 'xConflict', signature: 'i(pip)', bindScope: 'transient' @@ -373,7 +380,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ['sqlite3changeset_apply_v2', 'int', [ 'sqlite3*', 'int', 'void*', new wasm.xWrap.FuncPtrAdapter({ - name: 'xFilter', signature: 'i(ps)', bindScope: 'transient' + name: 'xFilter', bindScope: 'transient', ...__ipsProxy }), new wasm.xWrap.FuncPtrAdapter({ name: 'xConflict', signature: 'i(pip)', bindScope: 'transient' @@ -384,7 +391,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ['sqlite3changeset_apply_v2', 'int', [ 'sqlite3*', 'int', 'void*', new wasm.xWrap.FuncPtrAdapter({ - name: 'xFilter', signature: 'i(ps)', bindScope: 'transient' + name: 'xFilter', bindScope: 'transient', ...__ipsProxy }), new wasm.xWrap.FuncPtrAdapter({ name: 'xConflict', signature: 'i(pip)', bindScope: 'transient' @@ -398,7 +405,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }), 'void*', new wasm.xWrap.FuncPtrAdapter({ - name: 'xFilter', signature: 'i(ps)', bindScope: 'transient' + name: 'xFilter', bindScope: 'transient', ...__ipsProxy }), new wasm.xWrap.FuncPtrAdapter({ name: 'xConflict', signature: 'i(pip)', bindScope: 'transient' @@ -487,8 +494,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ['sqlite3session_table_filter', undefined, [ 'sqlite3_session*', new wasm.xWrap.FuncPtrAdapter({ - name: 'xFilter', signature: 'i(ps)', - contextKey: (argIndex,argv)=>argv[0/* (sqlite3_session*) */] + name: 'xFilter', ...__ipsProxy, + contextKey: (argv,argIndex)=>argv[0/* (sqlite3_session*) */] }), '*' ]] |