1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Improved handling/reporting of conditions which trigger an exit() from native code, e.g. calling the '.read' command. Added a Help button which simply submits the '.help' command. Added commented-out variants of various -Ox flags to simplify experimenting with them.

FossilOrigin-Name: bf06ddf4125d2726019fa16d312726c8551094be991509499b5688f6a68a7747
This commit is contained in:
stephan
2022-05-18 21:18:21 +00:00
parent 0076e49700
commit b0dae2b3c3
4 changed files with 60 additions and 33 deletions

View File

@ -56,6 +56,10 @@
label {
cursor: pointer;
}
.error {
color: red;
background-color: yellow;
}
</style>
</head>
<body>
@ -81,6 +85,7 @@ select * from t;</textarea>
<div class='ta-wrapper'>
<textarea id="output" readonly rows="18" placeholder="Shell output"></textarea>
<div class='button-bar'>
<button data-cmd='.help' disabled>Help</button>
<button id='btn-clear-output' disabled>Clear</button>
</div>
</div>
@ -92,7 +97,6 @@ select * from t;</textarea>
<label for='opt-cb-sbs'>Side-by-side</label>
</div>
</fieldset>
<hr>
<script type='text/javascript'>
(function(){
/**
@ -130,23 +134,30 @@ select * from t;</textarea>
doExec(sql);
}
},false);
doExec()/*sets up the db and outputs the header*/;
doExec(null)/*sets up the db and outputs the header*/;
let e = document.querySelector('#opt-cb-sbs');
const mainWrapper = document.querySelector('#main-wrapper');
e.addEventListener('change', function(){
mainWrapper.classList[this.checked ? 'add' : 'remove']('side-by-side');
}, false);
/* For all buttons with data-cmd=X, map a click handler which
calls doExec(X). */
const cmdClick = function(){doExec(this.dataset.cmd);};
document.querySelectorAll('button[data-cmd]').forEach(
e => e.addEventListener('click', cmdClick, false)
);
};
/**
What follow is part of the emscripten core setup. Do not modify without
understanding what it's doing...
What follows is part of the emscripten core setup. Do not
modify without understanding what it's doing...
*/
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');
window.Module = {
const statusElement = document.getElementById('status');
const progressElement = document.getElementById('progress');
const spinnerElement = document.getElementById('spinner');
const Module = window.Module = {
preRun: [],
postRun: [],
onRuntimeInitialized: function(){
@ -158,7 +169,7 @@ select * from t;</textarea>
}
f._.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
if(arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&amp;");
//text = text.replace(/</g, "&lt;");
@ -170,15 +181,15 @@ select * from t;</textarea>
f._.scrollTop = f._.scrollHeight; // focus on bottom
};
})(),
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.last.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon
Module.setStatus.last.time = now;
Module.setStatus.last.text = text;
if (m) {
setStatus: function f(text) {
if(!f.last) f.last = { time: Date.now(), text: '' };
if(text === f.last.text) return;
const m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
const now = Date.now();
if(m && now - f.last.time < 30) return; // if this is a progress update, skip it if too soon
f.last.time = now;
f.last.text = text;
if(m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
@ -188,23 +199,33 @@ select * from t;</textarea>
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
if (!text) spinnerElement.hidden = true;
if(!text) spinnerElement.hidden = true;
}
statusElement.innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
this.setStatus(left
? ('Preparing... (' + (this.totalDependencies-left)
+ '/' + this.totalDependencies + ')')
: 'All downloads complete.');
}
};
Module.printErr = Module.print/*redirect stderr*/;
Module.printErr = Module.print/*capture stderr output*/;
Module.setStatus('Downloading...');
window.onerror = function() {
window.onerror = function(/*message, source, lineno, colno, error*/) {
const err = arguments[4];
if(err && 'ExitStatus'==err.name){
Module.printErr("FATAL ERROR:", err.message);
Module.printErr("Restarting the app requires reloading the page.");
const taOutput = document.querySelector('#output');
if(taOutput) taOutput.classList.add('error');
}
Module.setStatus('Exception thrown, see JavaScript console');
spinnerElement.style.display = 'none';
Module.setStatus = function(text) {
if (text) console.error('[post-exception status] ' + text);
if(text) console.error('[post-exception status] ' + text);
};
};
})();