Detect JS out-of-memory condition and exit.