diff options
author | stephan <stephan@noemail.net> | 2025-02-26 03:32:52 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2025-02-26 03:32:52 +0000 |
commit | 69eaadbee3dc5912aba995288bfb20eeeb1222e6 (patch) | |
tree | 57dc2e0367a821171ea93add79f965300084042e /ext/wasm/tester1.c-pp.js | |
parent | d2f7dfa6190f529f7e543380b6663074e9078207 (diff) | |
parent | d804893762174d23017921ddbf233fa90ae5015f (diff) | |
download | sqlite-69eaadbee3dc5912aba995288bfb20eeeb1222e6.tar.gz sqlite-69eaadbee3dc5912aba995288bfb20eeeb1222e6.zip |
Merge trunk into the sahpool-digest branch.
FossilOrigin-Name: fc1eeb7d1f2880907b0fe71a8c572dd7cd74a5d65ec0177332976ad2f8c2b216
Diffstat (limited to 'ext/wasm/tester1.c-pp.js')
-rw-r--r-- | ext/wasm/tester1.c-pp.js | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 6d603752b..d30e59e38 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -3189,8 +3189,25 @@ globalThis.sqlite3InitModule = sqlite3InitModule; db.close(); T.assert(1 === u1.getFileCount()); db = new u2.OpfsSAHPoolDb(dbName); - T.assert(1 === u1.getFileCount()); + T.assert(1 === u1.getFileCount()) + .mustThrowMatching( + ()=>u1.pauseVfs(), + (err)=>{ + return capi.SQLITE_MISUSE===err.resultCode + && /^SQLITE_MISUSE: Cannot pause VFS /.test(err.message); + }, + "Cannot pause VFS with opened db." + ); db.close(); + T.assert( u2===u2.pauseVfs() ) + .assert( u2.isPaused() ) + .assert( 0===capi.sqlite3_vfs_find(u2.vfsName) ) + .mustThrowMatching(()=>new u2.OpfsSAHPoolDb(dbName), + /.+no such vfs: .+/, + "VFS is not available") + .assert( u2===await u2.unpauseVfs() ) + .assert( u2===await u1.unpauseVfs(), "unpause is a no-op if the VFS is not paused" ) + .assert( 0!==capi.sqlite3_vfs_find(u2.vfsName) ); const fileNames = u1.getFileNames(); T.assert(1 === fileNames.length) .assert(dbName === fileNames[0]) @@ -3445,7 +3462,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule; const stack = wasm.pstack.pointer; const pAux = wasm.pstack.alloc(4); let pAuxDestructed = 0; - const args = []; const pAuxDtor = wasm.installFunction('v(p)', function(ptr){ //log("freeing auxdata"); ++pAuxDestructed; @@ -3457,10 +3473,11 @@ globalThis.sqlite3InitModule = sqlite3InitModule; wasm.uninstallFunction(pAuxDtor); } }; + let nAuxSet = 0 /* how many times we set aux data */; + let nAuxReused = 0 /* how many times we reused aux data */; try{ db.createFunction("auxtest",{ xFunc: function(pCx, x, y){ - args.push(x); T.assert(wasm.isPtr(pCx)); const localAux = capi.sqlite3_get_auxdata(pCx, 0); if( !localAux ){ @@ -3469,23 +3486,20 @@ globalThis.sqlite3InitModule = sqlite3InitModule; We do not currently an automated way to clean up auxdata finalizer functions (the 4th argument to sqlite3_set_auxdata()) which get automatically - converted from JS to WASM. Because of that, relying - on automated conversions for those is not - recommended. Instead, follow the pattern show in + converted from JS to WASM. Because of that, enabling + automated conversions here would lead to leaks more + often than not. Instead, follow the pattern show in this function: use wasm.installFunction() to create the function, then pass the resulting function pointer this function, and cleanup (at some point) using wasm.uninstallFunction(). */ + ++nAuxSet; capi.sqlite3_set_auxdata(pCx, 0, pAux, pAuxDtor); }else{ - /* This is never actually hit in this example and it's - not entirely clear how to cause it to. The point of - this test, however, is to demonstrate that the - finalizer impl gets triggered, so we're not going to - fret over this at the moment. */ - //log("seen auxdata",localAux); + //log("reusing auxdata",localAux); T.assert(pAux===localAux); + ++nAuxReused; } return x; } @@ -3493,13 +3507,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule; db.exec([ "create table t(a);", "insert into t(a) values(1),(2),(1);", - "select auxtest(a,a), auxtest(a,a) from t order by a" + "select auxtest(1,a), auxtest(1,a) from t order by a" ]); }finally{ db.close(); wasm.pstack.restore(stack); } - T.assert(6===args.length); + T.assert(nAuxSet>0).assert(nAuxReused>0) + .assert(6===nAuxReused+nAuxSet); T.assert(pAuxDestructed>0); T.assert(pAuxDtorDestructed); } |