diff --git a/assets/disk0/inttest.js b/assets/disk0/inttest.js new file mode 100644 index 0000000..4ddf188 --- /dev/null +++ b/assets/disk0/inttest.js @@ -0,0 +1 @@ +throw new InterruptedException("lol"); diff --git a/assets/disk0/tvdos/TVDOS.SYS b/assets/disk0/tvdos/TVDOS.SYS index 21ff776..164e096 100644 --- a/assets/disk0/tvdos/TVDOS.SYS +++ b/assets/disk0/tvdos/TVDOS.SYS @@ -128,7 +128,18 @@ var GL = eval(filesystem.readAll("A")); // @param args arguments for the program, must be Array, and args[0] is always the name of the program, e.g. // for command line 'echo foo bar', args[0] must be 'echo' var execApp = (cmdsrc, args) => { - var execAppPrg = eval("var _appStub=function(exec_args){\n"+cmdsrc+"\n};_appStub;"); // making 'exec_args' a app-level global + var execAppPrg = eval( +`function InterruptedException(m){this.message=m;this.stack=(new Error()).stack;};` + +`InterruptedException.prototype=Object.create(Error.prototype);` + +`InterruptedException.prototype.name='InterruptedException';` + +`InterruptedException.prototype.constructor=InterruptedException;` + +`var _appStub=function(exec_args){${cmdsrc} +};try {_appStub;} +catch (e){ + if (e instanceof InterruptedException) 'SIGTERM'; + else 1; +}`); // making 'exec_args' a app-level global + return execAppPrg(args); } diff --git a/assets/disk0/tvdos/bin/command.js b/assets/disk0/tvdos/bin/command.js index 81c7957..6941892 100644 --- a/assets/disk0/tvdos/bin/command.js +++ b/assets/disk0/tvdos/bin/command.js @@ -380,13 +380,13 @@ shell.execute = function(line) { sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]); //serial.println(_G.shellProgramTitles); - let ret = execApp(programCode, tokens)|0; // return value of undefined will cast into 0 + let ret = execApp(programCode, tokens); // return value of undefined will cast into 0 _G.shellProgramTitles.pop(); sendLcdMsg(_G.shellProgramTitles[_G.shellProgramTitles.length - 1]); //serial.println(_G.shellProgramTitles); - return ret; + return (ret == undefined) ? 0 : ret; } } } @@ -457,13 +457,14 @@ if (goInteractive) { try { errorlevel = 0; // reset the number errorlevel = shell.execute(cmdbuf); - if (isNaN(errorlevel)) errorlevel = 2; + //if (isNaN(errorlevel)) errorlevel = 2; + serial.printerr(`errorlevel: ${errorlevel}`); } catch (e) { printerrln("\n"+(e.stack || e)); - if (errorlevel === 0 || isNaN(errorlevel)) { - errorlevel = 1; // generic failure - } + //if (errorlevel === 0 || isNaN(errorlevel)) { + // errorlevel = 1; // generic failure + //} } finally { if (cmdbuf.trim().length > 0)