Fix REPL crashing on execution error

See #2716 and the commit log for more info. This also fixes a strange behavior where a blank line in the REPL triggered an error, yet still passed the "empty command evaluates to undefined" test because erroring statements that didn't crash the REPL returned undefined.