by chimeracoder · 11y ago · 0 comments
You can do this to test your own browser, but it's rather pointless in practice unless you can do it at runtime without crashing the browser or causing it to become unresponsive. Otherwise, you'll have to manually keep track of which (browser, version) combination supports it and which ones don't.
> Wouldn't it be possible for a language to make the stack grow without an arbitrary limit (besides the limit of physical memory)?
Yes, some languages already do this. For example, you'll never get a literal "stack overflow" error in Go[0]. (You'll never get one in Java either - it'll be an OutOfMemoryException or whatever they call it)
[0] http://dave.cheney.net/2013/06/02/why-is-a-goroutines-stack-...
The snippet i posted doesn't crash the browser and seems to take around 1 or 2 milliseconds to run. Considering usual page load times, and if detecting whether TCO works is important for an application, it doesn't seem like an unreasonable solution (albeit pretty ugly hehe).
Thanks for the pointers about languages that don't have this limitation. Unfortunately, it doesn't seem to be the case for Java. This simple recursive function throws a StackOverflowError in less than 100,000 iterations: http://ideone.com/Tf4n3I, and it's not because the program is consuming all physical memory:
/usr/bin/time -v java StackOverflowExample
Exception in thread "main" java.lang.StackOverflowError
at StackOverflowExample.rec(StackOverflowExample.java:7)
at StackOverflowExample.rec(StackOverflowExample.java:8)
at StackOverflowExample.rec(StackOverflowExample.java:8)
...
Command exited with non-zero status 1
Command being timed: "java StackOverflowExample"
User time (seconds): 0.13
System time (seconds): 0.01
...
Maximum resident set size (kbytes): 27000
...