diff --git a/ChangeLog b/ChangeLog index e6e8ab47ca..939f54e7c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,7 @@ Bangle.js: Fix terminal's repeated call to '.flip' that broke double buffering on Bangle.js 1 JIT: Ensure ternary block skips 'named' variables (and references them correctly) Fix for UNFINISHED REGEX syntax error when parsing `true / false` (fix #2424) + Allow `throw undefined` to still show an exception in the REPL (fix #2423) 2v19 : Fix Object.values/entries for numeric keys after 2v18 regression (fix #2375) nRF52: for SD>5 use static buffers for advertising and scan response data (#2367) diff --git a/src/jsinteractive.c b/src/jsinteractive.c index 11fb9caaa2..e692b5a592 100644 --- a/src/jsinteractive.c +++ b/src/jsinteractive.c @@ -1206,14 +1206,16 @@ void jsiCheckErrors() { jsiConsolePrint("Execution Interrupted during event processing.\n"); } bool reportedError = false; + bool hasException = (execInfo.execute & EXEC_EXCEPTION)!=0; JsVar *exception = jspGetException(); - if (exception) { + if (hasException) { if (jsiExecuteEventCallbackOn("process", JS_EVENT_PREFIX"uncaughtException", 1, &exception)) { jsvUnLock(exception); exception = jspGetException(); + if (!exception) hasException = false; } } - if (exception) { + if (hasException) { jsiConsoleRemoveInputLine(); jsiConsolePrintf("Uncaught %v\n", exception); reportedError = true; @@ -1224,8 +1226,8 @@ void jsiCheckErrors() { jsvUnLock(stackTrace); } } - jsvUnLock(exception); } + jsvUnLock(exception); if (jspIsInterrupted() #ifdef USE_DEBUGGER && !(jsiStatus & JSIS_EXIT_DEBUGGER) diff --git a/src/jsparse.c b/src/jsparse.c index 4cbc127084..ae91f922d5 100644 --- a/src/jsparse.c +++ b/src/jsparse.c @@ -267,7 +267,7 @@ void jspSetException(JsVar *value) { } -/** Return the reported exception if there was one (and clear it) */ +/** Return the reported exception if there was one (and clear it). May return undefined even if there was an exception - eg `throw undefined` */ JsVar *jspGetException() { JsVar *exceptionName = jsvFindChildFromString(execInfo.hiddenRoot, JSPARSE_EXCEPTION_VAR); if (exceptionName) { diff --git a/src/jsparse.h b/src/jsparse.h index cb5fe48284..413a137aaf 100644 --- a/src/jsparse.h +++ b/src/jsparse.h @@ -55,7 +55,7 @@ bool jspHasError(); void jspSetError(bool lineReported); /// We had an exception (argument is the exception's value) void jspSetException(JsVar *value); -/** Return the reported exception if there was one (and clear it) */ +/** Return the reported exception if there was one (and clear it). May return undefined even if there was an exception - eg `throw undefined` */ JsVar *jspGetException(); /** Return a stack trace string if there was one (and clear it) */ JsVar *jspGetStackTrace(); diff --git a/targets/linux/main.c b/targets/linux/main.c index b472299955..3b0d24ea24 100644 --- a/targets/linux/main.c +++ b/targets/linux/main.c @@ -382,12 +382,13 @@ void die(const char *txt) { int handleErrors() { int e = 0; + bool hasException = (execInfo.execute & EXEC_EXCEPTION)!=0; JsVar *exception = jspGetException(); - if (exception) { + if (hasException) { jsiConsolePrintf("Uncaught %v\n", exception); - jsvUnLock(exception); e = 1; } + jsvUnLock(exception); if (jspIsInterrupted()) { jsiConsoleRemoveInputLine();