Trying to solve the halting problem are we. Remember that one of the most dangerous JavaScript APIs turned out to be a sub-millisecond monotonically increasing time source.
You can do it the right way, by using total functional programming. Or you can do it the wrong way, by providing a time budget or "gas", and yanking the process if and when it's exceeded.
No, this is more of a Rice's Theorem kind of situation...
Why do you think using 'gas' is the wrong way? Not only does it solve this problem, it solves it in a deterministic way, which has many applications, for example deterministic debugging and replicable computation!