2022-10-12 15:54:28 +00:00
<!doctype html>
< html lang = "en-us" >
< head >
< meta charset = "utf-8" >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" >
< link rel = "shortcut icon" href = "data:image/x-icon;," type = "image/x-icon" >
< link rel = "stylesheet" href = "../common/emscripten.css" / >
< link rel = "stylesheet" href = "../common/testing.css" / >
2022-11-19 16:16:40 +00:00
< title > sqlite3 tester #1: Worker thread< / title >
2022-12-05 14:13:55 +00:00
< style > < / style >
2022-10-12 15:54:28 +00:00
< / head >
< body >
2022-11-19 16:16:40 +00:00
< h1 id = 'color-target' > sqlite3 tester #1: Worker thread< / h1 >
2023-01-28 04:20:46 +00:00
< div > Variants:
< a href = 'tester1.html' target = 'tester1.html' > conventional UI thread< / a > ,
< a href = 'tester1-worker.html' target = 'tester1-worker.html' > conventional worker< / a > ,
< a href = 'tester1-esm.html' target = 'tester1-esm.html' > ESM in UI thread< / a > ,
< a href = 'tester1-worker.html?esm' target = 'tester1-worker.html?esm' > ESM worker< / a >
< / div >
2022-10-21 06:58:27 +00:00
< div class = 'input-wrapper' >
2022-10-25 08:15:57 +00:00
< input type = 'checkbox' id = 'cb-log-reverse' >
2022-10-21 06:58:27 +00:00
< label for = 'cb-log-reverse' > Reverse log order?< / label >
< / div >
2022-10-13 08:03:31 +00:00
< div id = 'test-output' > < / div >
2022-10-12 15:54:28 +00:00
< script > ( f u n c t i o n ( ) {
2022-10-13 08:03:31 +00:00
const logTarget = document.querySelector('#test-output');
2022-10-12 15:54:28 +00:00
const logHtml = function(cssClass,...args){
const ln = document.createElement('div');
2022-10-21 06:26:17 +00:00
if(cssClass){
for(const c of (Array.isArray(cssClass) ? cssClass : [cssClass])){
ln.classList.add(c);
}
}
2022-10-12 15:54:28 +00:00
ln.append(document.createTextNode(args.join(' ')));
2022-10-13 08:03:31 +00:00
logTarget.append(ln);
2022-10-12 15:54:28 +00:00
};
2022-10-21 06:58:27 +00:00
const cbReverse = document.querySelector('#cb-log-reverse');
const cbReverseIt = ()=>{
logTarget.classList[cbReverse.checked ? 'add' : 'remove']('reverse');
};
cbReverse.addEventListener('change',cbReverseIt,true);
cbReverseIt();
2022-11-19 16:16:40 +00:00
const urlParams = new URL(self.location.href).searchParams;
const workerArgs = [];
if(urlParams.has('esm')){
logHtml('warning',"Attempting to run an ES6 Worker Module, "+
"which is not supported by all browsers! "+
2023-05-19 15:54:41 +00:00
"e.g. Firefox (as of 2023-05) cannot do this.");
2022-11-20 05:36:52 +00:00
workerArgs.push("tester1.mjs",{type:"module"});
2022-11-19 16:16:40 +00:00
document.querySelectorAll('title,#color-target').forEach((e)=>{
e.innerText = "sqlite3 tester #1: ES6 Worker Module";
});
}else{
workerArgs.push("tester1.js?sqlite3.dir=jswasm");
}
const w = new Worker(...workerArgs);
2022-10-12 15:54:28 +00:00
w.onmessage = function({data}){
switch(data.type){
case 'log':
logHtml(data.payload.cssClass, ...data.payload.args);
break;
2022-11-01 07:49:49 +00:00
case 'error':
logHtml('error', ...data.payload.args);
break;
2022-12-02 07:14:56 +00:00
case 'test-result':{
document.querySelector('#color-target').classList.add(
data.payload.pass ? 'tests-pass' : 'tests-fail'
);
const e = document.querySelector('title');
e.innerText = (
data.payload.pass ? 'PASS' : 'FAIL'
) + ': ' + e.innerText;
break;
}
2022-10-12 15:54:28 +00:00
default:
logHtml('error',"Unhandled message:",data.type);
};
};
})();< / script >
< / body >
< / html >