Iroh
Iroh copied to clipboard
Doesn't throw in functions
Example code: `
const Iroh = require("iroh");
let stage = new Iroh.Stage(function foo() { throw "banana"; } foo();
);
eval(stage.script);
` The exception will be ignored!
I've tracked it to function DEBUG_FUNCTION_CALL, where theres a try catch ... Maybe make it possible to listen for errors ... !? hmm
I'm working on it
Errors shouldn't be suppressed anymore with https://github.com/maierfelix/Iroh/commit/3edc548f433fdd32362cc9d0b1f54652eb7f874e
I think "throw" outside a try should generate an Iroh.PROGRAM "exception" event
That way you can listen for it and get the source location and maybe even a call stack.
This would require to patch a try {}
around the submitted code, which would break global variable/function support. However I experimented a bit and came up with this:
let stage = new Iroh.Stage(code);
stage.addListener(Iroh.PROGRAM)
.on("error", (e) => {
console.error(e.error);
});
try {
eval(stage.script);
} catch (e) {
let event = stage.createEvent(Iroh.PROGRAM_ERROR);
event.indent = stage.indent;
event.error = e;
event.trigger("error");
}
So if you want to listen for uncatched errors in your program, you have to evaluate your program this way, which remains global support but requires some additional code lines.