Closed btruhand closed 6 years ago
@btruhand Yes... this is a good point, and a decision I had a bit of trouble with.
The problem, is here and here. In order to loop-protect the code, I was stuck in a situation where basically I have to eval
the code twice. I also made a note about this here.
You would think that I'd be able to get rid of the surrounding if
block add the loop-protect transform directly right here, without having the intermediate function wontTimeout
which eval
s the code first to check for infinite loops (and silences the console), like this:
import wontTimeout, { loopProtect } from './loop-protect'
// ... other code from eval-code-run-tests.js
// if (wontTimeout(code)) {
try {
eval(
loopProtect(code) +
tail +
tests +
executeTests
)
} catch (e) {
console.log(e.toString())
}
// }
However, when I did this (my first try), it would work correctly when an infinite-loop was detected, but when there was no loop in the user's code, it would cause some very strange behavior which I was totally unable to explain (basically the test-runner would think that there was 1000s tests, and it would loop over those tests and log them all as failing, basically creating an infinite loop that didn't exist!).
So... I silenced the console in the first eval to prevent everything from being logged twice. I suppose I could do some kind of regexp test to check for the presence of loops and only transform the code if they exist, but I haven't tested this. I do see how silencing the console could be a disadvantage though.
Oh, and this should only be for infinite loops, when other errors are caught, it should still log any messages prior to the error stopping exection of the code
☝️@btruhand this PR fixes things, but it's a bit of a hack! Also removes another hack, so I guess it all evens out 😕
When an error is caught it seems that user defined
console.log
statements are rendered mute. That is:Running the above would cause the console statement to not display the string. Instead you will only get:
Having console log statements can be very helpful during any sort of quick debugging