diff options
Diffstat (limited to 'site/main.mjs')
| -rw-r--r-- | site/main.mjs | 26 |
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); |
