Ensure we don't try and save errors to Storage if they're from code that's been run from the REPL

This commit is contained in:
Gordon Williams 2025-05-23 14:11:37 +01:00
parent bec9266224
commit 1263857ebd
3 changed files with 13 additions and 13 deletions

View File

@ -1416,7 +1416,7 @@ bool jsfLoadBootCodeFromFlash(bool isReset) {
JsVar *code = jsfReadFile(jsfNameFromString(".bootPowerOn"),0,0);
if (code) {
jsvUnLock2(jspEvaluateVar(code,0,".bootPowerOn",0), code);
jsiCheckErrors();
jsiCheckErrors(false);
}
}
#endif
@ -1438,7 +1438,7 @@ bool jsfLoadBootCodeFromFlash(bool isReset) {
JsVar *code = jsfReadFile(jsfNameFromString(filename),0,0);
if (code) {
jsvUnLock2(jspEvaluateVar(code,0,filename,0), code);
jsiCheckErrors();
jsiCheckErrors(false);
}
}
}
@ -1446,7 +1446,7 @@ bool jsfLoadBootCodeFromFlash(bool isReset) {
JsVar *code = jsfGetBootCodeFromFlash(isReset);
if (!code) return false;
jsvUnLock2(jspEvaluateVar(code,0,"boot code",0), code);
jsiCheckErrors();
jsiCheckErrors(false);
return true;
}

View File

@ -540,7 +540,7 @@ void jsiSoftInit(bool hasBeenReset) {
JsVar *initCode = jsvObjectGetChildIfExists(execInfo.hiddenRoot, JSI_INIT_CODE_NAME);
if (initCode) {
jsvUnLock2(jspEvaluateVar(initCode, 0, "initcode", 0), initCode);
jsiCheckErrors();
jsiCheckErrors(false);
jsvObjectRemoveChild(execInfo.hiddenRoot, JSI_INIT_CODE_NAME);
}
@ -566,13 +566,13 @@ void jsiSoftInit(bool hasBeenReset) {
// Execute `init` events on `E`
jsiExecuteEventCallbackOn("E", INIT_CALLBACK_NAME, 0, 0);
jsiCheckErrors();
jsiCheckErrors(false);
// Execute the `onInit` function
JsVar *onInit = jsvObjectGetChildIfExists(execInfo.root, JSI_ONINIT_NAME);
if (onInit) {
if (jsiEcho()) jsiConsolePrint("Running onInit()...\n");
jsiExecuteEventCallback(0, onInit, 0, 0);
jsiCheckErrors();
jsiCheckErrors(false);
jsvUnLock(onInit);
}
}
@ -789,7 +789,7 @@ void jsiSoftKill() {
jsiPacketExit();
// Execute `kill` events on `E`
jsiExecuteEventCallbackOn("E", KILL_CALLBACK_NAME, 0, 0);
jsiCheckErrors();
jsiCheckErrors(false);
// Clear input line...
inputCursorPos = 0;
jsiInputLineCursorMoved();
@ -1276,7 +1276,7 @@ bool jsiAtEndOfInputLine() {
return true;
}
void jsiCheckErrors() {
void jsiCheckErrors(bool wasREPL) {
if (jsiStatus & JSIS_EVENTEMITTER_INTERRUPTED) {
jspSetInterrupted(false);
jsiStatus &= ~JSIS_EVENTEMITTER_INTERRUPTED;
@ -1573,7 +1573,7 @@ void jsiHandleNewLine(bool execute) {
}
jsvUnLock(v);
}
jsiCheckErrors();
jsiCheckErrors(true/*repl*/);
// console will be returned next time around the input loop
// if we had echo off just for this line, reinstate it!
jsiStatus &= ~JSIS_ECHO_OFF_FOR_LINE;
@ -1695,7 +1695,7 @@ static void jsiPacketProcess() {
JsVar *result = jspEvaluateExpressionVar(inputLine);
if (jspHasError()) {
jsiConsolePrintChar(ASCII_NAK);
jsiCheckErrors();
jsiCheckErrors(true/*repl*/);
} else {
jsiConsolePrintChar(ASCII_ACK);
JsVar *v = jswrap_espruino_toJS(result);
@ -2647,7 +2647,7 @@ bool jsiLoop() {
// Do general idle stuff
jsiIdle();
// check for and report errors
jsiCheckErrors();
jsiCheckErrors(false);
// If Ctrl-C was pressed, clear the line (unless doing packet transfer)
if ((execInfo.execute & EXEC_CTRL_C_MASK) && !IS_PACKET_TRANSFER(inputState)) {

View File

@ -63,8 +63,8 @@ bool jsiExecuteEventCallbackName(JsVar *obj, const char *cbName, unsigned int ar
/// Utility version of jsiExecuteEventCallback for calling events on global variables
bool jsiExecuteEventCallbackOn(const char *objectName, const char *cbName, unsigned int argCount, JsVar **argPtr);
/// Check for and report/handle interpreter errors (can be called after executing JS code)
void jsiCheckErrors();
/// Check for and report/handle interpreter errors (can be called after executing JS code). If wasREPL we won't save errors to storage as we assume they've been seen
void jsiCheckErrors(bool wasREPL);
/// Create a timeout in JS to execute the given native function (outside of an IRQ). Returns the index
JsVar *jsiSetTimeout(void (*functionPtr)(void), JsVarFloat milliseconds);