Scene:
I want to run a js script in a runtime. The js code may be malformed. For example, infinite loop may happens in normal functions or Promise jobs.
I want to specify a timeout to shutdown context or runtime. When the context or runtime can't make any response after a timeout.
I want to know what's the best way to do this.
I have some thoughts in my mind:
- Use alarm signal: when the alarm is reached, do something to stop stack machine. Do we have this kind of approch to stop stack machine without droping performance like inserting a byte code or altering the PC to a particular location?
- Stop the runtime worker thread immediately when monitor thread detects it can't make any response. Which means that the runtime may stop at any instruction point. Can we make sure that we free all the resource after this?
Scene:
I want to run a js script in a runtime. The js code may be malformed. For example, infinite loop may happens in normal functions or Promise jobs.
I want to specify a timeout to shutdown context or runtime. When the context or runtime can't make any response after a timeout.
I want to know what's the best way to do this.
I have some thoughts in my mind: