Skip to content

Commit

Permalink
Allow throw undefined to still show an exception in the REPL (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Nov 2, 2023
1 parent 0f1b5b0 commit 5b7e9db
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/jsinteractive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1224,8 +1226,8 @@ void jsiCheckErrors() {
jsvUnLock(stackTrace);
}
}
jsvUnLock(exception);
}
jsvUnLock(exception);
if (jspIsInterrupted()
#ifdef USE_DEBUGGER
&& !(jsiStatus & JSIS_EXIT_DEBUGGER)
Expand Down
2 changes: 1 addition & 1 deletion src/jsparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/jsparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions targets/linux/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5b7e9db

Please sign in to comment.