summaryrefslogtreecommitdiffstats
path: root/site/main.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-08-25 13:35:12 -0400
committerBrian Cully <bjc@spork.org>2025-08-25 13:57:21 -0400
commit37c0a0b5e4d3939656cac8d103b5a22963fbc9dd (patch)
tree8843628b991ac39991d22f80df9aa1d2a22cffc4 /site/main.mjs
parentf2bcc1df6ef43a6021adfcd380fc899ca8e6533a (diff)
downloadautomathon-37c0a0b5e4d3939656cac8d103b5a22963fbc9dd.tar.gz
automathon-37c0a0b5e4d3939656cac8d103b5a22963fbc9dd.zip
load forth from server
Diffstat (limited to 'site/main.mjs')
-rw-r--r--site/main.mjs26
1 files changed, 26 insertions, 0 deletions
diff --git a/site/main.mjs b/site/main.mjs
index 3add1fe..22d1f96 100644
--- a/site/main.mjs
+++ b/site/main.mjs
@@ -85,12 +85,38 @@ function tick(vm) {
renderTextHighlight(vm);
}
+function loadForth(taintedPath) {
+ // ascii only + ‘-’, ‘_’, ‘.’, and ‘/’, but no ‘../’
+ const path =
+ taintedPath
+ .replace(/[^-_A-Za-z./]/g, '')
+ .replace(/\.\.\//g, '');
+ fetch(`./samples/${path}`)
+ .then(resp => {
+ if (!resp.ok) {
+ throw `http status ${resp.status}`
+ }
+ return resp.text()
+ })
+ .then(text => {
+ document.querySelector('#src').textContent = text;
+ })
+ .catch(e => {
+ console.error(`couldn't fetch ‘${path}’`, e);
+ });
+}
+
async function loaded() {
console.debug('running init');
const mod = await init();
console.debug('init done', mod);
const vm = make_vm();
+ document.querySelectorAll('#src-select').forEach(async sel => {
+ sel.onchange = _ => loadForth(sel.value);
+ loadForth(sel.value);
+ });
+
document.querySelector('#compile').onclick = e => {
console.debug('compile clicked', e);