diff options
author | stephan <stephan@noemail.net> | 2022-12-13 08:25:28 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-13 08:25:28 +0000 |
commit | 30f50a2d34a0859cbd7d9424bd53eb6cd1306c3a (patch) | |
tree | af06959f2ced3efd93a47d29cb0ea6ecf147e12c /ext/wasm/api/sqlite3-api-glue.js | |
parent | 7ca4312ff2dc94bed3897275eeb822aa286f96bb (diff) | |
download | sqlite-30f50a2d34a0859cbd7d9424bd53eb6cd1306c3a.tar.gz sqlite-30f50a2d34a0859cbd7d9424bd53eb6cd1306c3a.zip |
Extend the sqlite3.wasm function pointer argument converter to be able to handle the "two-layered context" of sqlite3_create_collation() and friends and make use of FuncPtrAdapter to perform JS-to-WASM function conversion for them.
FossilOrigin-Name: 0a60b7215e433f8c50027c70731b11e58d74c90ec5903e66ae42f9c98e40b044
Diffstat (limited to 'ext/wasm/api/sqlite3-api-glue.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-glue.js | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index 91b42cd93..21dd34d13 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -462,22 +462,11 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ const __collationContextKey = (argIndex,argv)=>{ return 'argv['+argIndex+']:sqlite3@'+argv[0]+ - ':'+((/*THIS IS WRONG. We can't sensibly use a converted-to-C-string - address here and don't have access to the JS string (IF ANY) - which the user passed in.*/ - ''+argv[1] - ).toLowerCase()); + ':'+wasm.cstrToJs(argv[1]).toLowerCase() }; const __ccv2 = wasm.xWrap( 'sqlite3_create_collation_v2', 'int', - 'sqlite3*','string','int','*','*','*' - /* int(*xCompare)(void*,int,const void*,int,const void*) */ - /* void(*xDestroy(void*) */ - ); - if(0){ - // Problem: we cannot, due to xWrap() arg-passing limitations, - // currently easily/efficiently get a per-collation distinct - // key for purposes of creating distinct FuncPtrAdapter contexts. + 'sqlite3*','string','int','*', new wasm.xWrap.FuncPtrAdapter({ /* int(*xCompare)(void*,int,const void*,int,const void*) */ name: 'xCompare', @@ -492,7 +481,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ bindScope: 'context', contextKey: __collationContextKey }) - } + ); /** Works exactly like C's sqlite3_create_collation_v2() except that: @@ -518,18 +507,9 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ); } let rc, pfCompare, pfDestroy; - try{ - if(xCompare instanceof Function){ - pfCompare = wasm.installFunction(xCompare, 'i(pipip)'); - } - if(xDestroy instanceof Function){ - pfDestroy = wasm.installFunction(xDestroy, 'v(p)'); - } - rc = __ccv2(pDb, zName, eTextRep, pArg, - pfCompare || xCompare, pfDestroy || xDestroy); + try{ + rc = __ccv2(pDb, zName, eTextRep, pArg, xCompare, xDestroy); }catch(e){ - if(pfCompare) wasm.uninstallFunction(pfCompare); - if(pfDestroy) wasm.uninstallFunction(pfDestroy); rc = util.sqlite3_wasm_db_error(pDb, e); } return rc; @@ -539,7 +519,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return (5===arguments.length) ? capi.sqlite3_create_collation_v2(pDb,zName,eTextRep,pArg,xCompare,0) : __dbArgcMismatch(pDb, 'sqlite3_create_collation', 5); - } + }; }/*sqlite3_create_collation() and friends*/ |