diff --git a/com/isoterminal/feat/javascript.js b/com/isoterminal/feat/javascript.js index f42e91a..9ba2be0 100644 --- a/com/isoterminal/feat/javascript.js +++ b/com/isoterminal/feat/javascript.js @@ -19,16 +19,39 @@ if( typeof emulator != 'undefined' ){ }else{ // inside browser-thread - + + + /* + * here we're going to execute javascript in the browser, + * both a terrible and great idea depending on a corporate vs personal computing angle. + * + * if a function-string gets evaluated, and it returns a promise..then we assume async. + */ ISOTerminal.addEventListener('javascript-eval', async function(e){ const {script,PID} = e.detail let res; + let error = false; + + const output = (res,PID) => { + if( res && typeof res != 'string' ) res = JSON.stringify(res,null,2) + // update output to 9p with PID as filename (in /mnt/run) + if( PID ){ + this.worker.update_file(`run/${PID}.exit`, error ? "1" : "0") + this.worker.update_file(`run/${PID}`, this.convert.toUint8Array(res) ) + } + } try{ let f = new Function(`${script}`); res = f(); - if( res && typeof res != 'string' ) res = JSON.stringify(res,null,2) + if( res && typeof res.then == 'function' ){ // if we got a promise + res.then( (res) => output(res,PID) ) + res.catch( (e) => output(e,PID) ) + }else{ // normal sync function + output(res,PID) + } }catch(err){ + error = true console.error(err) console.dir(err) res = "error: "+err.toString() @@ -41,10 +64,7 @@ if( typeof emulator != 'undefined' ){ res += script.split("\n")[lnr-1] }else console.dir(script) console.error(res) - } - // update output to 9p with PID as filename (in /mnt/run) - if( PID ){ - this.worker.update_file(`run/${PID}`, this.convert.toUint8Array(res) ) + output(res,PID) } }) diff --git a/com/isoterminal/feat/term.js b/com/isoterminal/feat/term.js index cd1cf31..e26141f 100644 --- a/com/isoterminal/feat/term.js +++ b/com/isoterminal/feat/term.js @@ -34,6 +34,7 @@ ISOTerminal.prototype.TermInit = function(){ Term.prototype.keyDownHandler = function(original){ return function (e){ if ((e.ctrlKey || e.metaKey) && e.key === 'v') { + debugger return true; // bubble up to pasteHandler (see pastedrop.js) } original.apply(this,[e]) diff --git a/com/isoterminal/term.js b/com/isoterminal/term.js index 0af741f..d0fc3a2 100644 --- a/com/isoterminal/term.js +++ b/com/isoterminal/term.js @@ -1259,6 +1259,7 @@ Term.prototype.blurHandler = function (ev) Term.prototype.pasteHandler = function (ev) { + debugger var c, str; if (!this.textarea_has_focus) { c = ev.clipboardData;