mounted, else it returns an empty string.
*/
const wasmfsDir = function f(wasmUtil){
- if(undefined !== f._) return f._;
- const pdir = '/persistent';
- if( !self.FileSystemHandle
- || !self.FileSystemDirectoryHandle
- || !self.FileSystemFileHandle){
- return f._ = "";
- }
- try{
- if(0===wasmUtil.xCallWrapped(
- 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], pdir
- )){
- return f._ = pdir;
- }else{
- return f._ = "";
- }
- }catch(e){
- // sqlite3_wasm_init_wasmfs() is not available
- return f._ = "";
+ if(undefined !== f._) return f._;
+ const pdir = '/persistent';
+ if( !self.FileSystemHandle
+ || !self.FileSystemDirectoryHandle
+ || !self.FileSystemFileHandle){
+ return f._ = "";
+ }
+ try{
+ if(0===wasmUtil.xCallWrapped(
+ 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], pdir
+ )){
+ return f._ = pdir;
+ }else{
+ return f._ = "";
}
+ }catch(e){
+ // sqlite3_wasm_init_wasmfs() is not available
+ return f._ = "";
+ }
};
wasmfsDir._ = undefined;
- const eOut = document.querySelector('#test-output');
- const log2 = function(cssClass,...args){
- const ln = document.createElement('div');
- if(cssClass) ln.classList.add(cssClass);
- ln.append(document.createTextNode(args.join(' ')));
- eOut.append(ln);
- //this.e.output.lastElementChild.scrollIntoViewIfNeeded();
- };
- const logList = [];
- const dumpLogList = function(){
- logList.forEach((v)=>log2('',v));
- logList.length = 0;
- };
- /* we cannot update DOM while speedtest is running unless we run
- speedtest in a worker thread. */;
- const log = (...args)=>{
- console.log(...args);
- logList.push(args.join(' '));
- };
- const logErr = function(...args){
- console.error(...args);
- logList.push('ERROR: '+args.join(' '));
- };
+ const eOut = document.querySelector('#test-output');
+ const log2 = function(cssClass,...args){
+ const ln = document.createElement('div');
+ if(cssClass) ln.classList.add(cssClass);
+ ln.append(document.createTextNode(args.join(' ')));
+ eOut.append(ln);
+ //this.e.output.lastElementChild.scrollIntoViewIfNeeded();
+ };
+ const logList = [];
+ const dumpLogList = function(){
+ logList.forEach((v)=>log2('',v));
+ logList.length = 0;
+ };
+ /* we cannot update DOM while speedtest is running unless we run
+ speedtest in a worker thread. */;
+ const log = (...args)=>{
+ console.log(...args);
+ logList.push(args.join(' '));
+ };
+ const logErr = function(...args){
+ console.error(...args);
+ logList.push('ERROR: '+args.join(' '));
+ };
+
+ const runTests = function(sqlite3){
+ globalThis.S = sqlite3;
+ const capi = sqlite3.capi, wasm = sqlite3.wasm;
+ //console.debug('sqlite3 (global S) =',sqlite3);
+ const pDir = wasmfsDir(wasm);
+ if(pDir){
+ console.warn("wasmfs storage:",pDir);
+ }
+ const scope = wasm.scopedAllocPush();
+ let dbFile = pDir+"/speedtest1.db";
+ const urlParams = new URL(self.location.href).searchParams;
+ const argv = ["speedtest1"];
+ if(urlParams.has('flags')){
+ argv.push(...(urlParams.get('flags').split(',')));
+ }
- const runTests = function(sqlite3){
- const capi = sqlite3.capi, wasm = sqlite3.wasm;
- //console.debug('sqlite3 =',sqlite3);
- const pDir = wasmfsDir(wasm);
- if(pDir){
- console.warn("Persistent storage:",pDir);
+ let forceSize = 0;
+ let vfs, pVfs = 0;
+ if(urlParams.has('vfs')){
+ vfs = urlParams.get('vfs');
+ pVfs = capi.sqlite3_vfs_find(vfs);
+ if(!pVfs){
+ log2('error',"Unknown VFS:",vfs);
+ return;
}
- const scope = wasm.scopedAllocPush();
- let dbFile = pDir+"/speedtest1.db";
- const urlParams = new URL(self.location.href).searchParams;
- const argv = ["speedtest1"];
- if(urlParams.has('flags')){
- argv.push(...(urlParams.get('flags').split(',')));
+ argv.push("--vfs", vfs);
+ log2('',"Using VFS:",vfs);
+ if('kvvfs' === vfs){
+ //forceSize = 10
+ /* --size > 2 is too big for local/session storage
+ as of mid-2025, but kvvfs v2 (late 2025)
+ lets us use transient storage. */;
+ dbFile = 'transient';
+ log2('warning',"kvvfs VFS: forcing --size",forceSize,
+ "and filename '"+dbFile+"'.");
+ capi.sqlite3_js_kvvfs_clear(dbFile);
}
-
- let forceSize = 0;
- let vfs, pVfs = 0;
- if(urlParams.has('vfs')){
- vfs = urlParams.get('vfs');
- pVfs = capi.sqlite3_vfs_find(vfs);
- if(!pVfs){
- log2('error',"Unknown VFS:",vfs);
- return;
- }
- argv.push("--vfs", vfs);
- log2('',"Using VFS:",vfs);
- if('kvvfs' === vfs){
- //forceSize = 10
- /* --size > 2 is too big for local/session storage
- as of mid-2025, but kvvfs v2 (late 2025)
- lets us use transient storage. */;
- dbFile = 'transient';
- log2('warning',"kvvfs VFS: forcing --size",forceSize,
- "and filename '"+dbFile+"'.");
- capi.sqlite3_js_kvvfs_clear(dbFile);
- }
- }
- if(forceSize){
- argv.push('--size',forceSize);
- }else{
- [
- 'size'
- ].forEach(function(k){
- const v = urlParams.get(k);
- if(v) argv.push('--'+k, urlParams[k]);
- });
+ }
+ if(forceSize){
+ argv.push('--size',forceSize);
+ }else{
+ [
+ 'size'
+ ].forEach(function(k){
+ const v = urlParams.get(k);
+ if(v) argv.push('--'+k, urlParams[k]);
+ });
+ }
+ argv.push(
+ "--singlethread",
+ //"--nomutex",
+ //"--nosync",
+ //"--memdb", // note that memdb trumps the filename arg
+ "--nomemstat"
+ );
+ argv.push("--big-transactions"/*important for tests 410 and 510!*/,
+ dbFile);
+ console.log("argv =",argv);
+ // These log messages are not emitted to the UI until after main() returns. Fixing that
+ // requires moving the main() call and related cleanup into a timeout handler.
+ if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile);
+ log2('',"WASM heap size:",sqlite3.wasm.heap8().byteLength,"bytes");
+ log2('',"WASM pointer size:",sqlite3.wasm.ptr.size);
+ log2('',"Starting native app:\n ",argv.join(' '));
+ log2('',"This will take a while and the browser might warn about the runaway JS.",
+ "Give it time...");
+ logList.length = 0;
+ setTimeout(function(){
+ wasm.xCall('wasm_main', argv.length,
+ wasm.scopedAllocMainArgv(argv));
+ wasm.scopedAllocPop(scope);
+ if('kvvfs'===vfs){
+ logList.unshift("KVVFS "+dbFile+" size = "+
+ capi.sqlite3_js_kvvfs_size(dbFile));
}
- argv.push(
- "--singlethread",
- //"--nomutex",
- //"--nosync",
- //"--memdb", // note that memdb trumps the filename arg
- "--nomemstat"
- );
- argv.push("--big-transactions"/*important for tests 410 and 510!*/,
- dbFile);
- console.log("argv =",argv);
- // These log messages are not emitted to the UI until after main() returns. Fixing that
- // requires moving the main() call and related cleanup into a timeout handler.
if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile);
+ logList.unshift("Done running native main(). Output:");
+ dumpLogList();
log2('',"WASM heap size:",sqlite3.wasm.heap8().byteLength,"bytes");
- log2('',"WASM pointer size:",sqlite3.wasm.ptr.size);
- log2('',"Starting native app:\n ",argv.join(' '));
- log2('',"This will take a while and the browser might warn about the runaway JS.",
- "Give it time...");
- logList.length = 0;
- setTimeout(function(){
- wasm.xCall('wasm_main', argv.length,
- wasm.scopedAllocMainArgv(argv));
- wasm.scopedAllocPop(scope);
- if('kvvfs'===vfs){
- logList.unshift("KVVFS "+dbFile+" size = "+
- capi.sqlite3_js_kvvfs_size(dbFile));
- }
- if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile);
- logList.unshift("Done running native main(). Output:");
- dumpLogList();
- log2('',"WASM heap size:",sqlite3.wasm.heap8().byteLength,"bytes");
- }, 50);
- }/*runTests()*/;
+ }, 50);
+ }/*runTests()*/;
self.sqlite3TestModule.print = log;
self.sqlite3TestModule.printErr = logErr;
+ sqlite3InitModule.__isUnderTest = true;
sqlite3InitModule(self.sqlite3TestModule).then(runTests);
})();</script>
</body>