@@ -137,7 +137,6 @@ JsErrorFlags lastJsErrorFlags = 0; ///< Compare with jsErrorFlags in order to re
137137#ifdef USE_DEBUGGER
138138void jsiDebuggerLine (JsVar * line );
139139#endif
140- void jsiCheckErrors ();
141140
142141static void jsiPacketFileEnd ();
143142static void jsiPacketExit ();
@@ -535,11 +534,13 @@ void jsiSoftInit(bool hasBeenReset) {
535534
536535 // Run 'boot code' - textual JS in flash
537536 jsfLoadBootCodeFromFlash (hasBeenReset );
537+ // jsiCheckErrors is performed internally
538538
539539 // Now run initialisation code
540540 JsVar * initCode = jsvObjectGetChildIfExists (execInfo .hiddenRoot , JSI_INIT_CODE_NAME );
541541 if (initCode ) {
542- jsvUnLock2 (jspEvaluateVar (initCode , 0 , 0 ), initCode );
542+ jsvUnLock2 (jspEvaluateVar (initCode , 0 , "initcode" , 0 ), initCode );
543+ jsiCheckErrors ();
543544 jsvObjectRemoveChild (execInfo .hiddenRoot , JSI_INIT_CODE_NAME );
544545 }
545546
@@ -565,11 +566,13 @@ void jsiSoftInit(bool hasBeenReset) {
565566
566567 // Execute `init` events on `E`
567568 jsiExecuteEventCallbackOn ("E" , INIT_CALLBACK_NAME , 0 , 0 );
569+ jsiCheckErrors ();
568570 // Execute the `onInit` function
569571 JsVar * onInit = jsvObjectGetChildIfExists (execInfo .root , JSI_ONINIT_NAME );
570572 if (onInit ) {
571573 if (jsiEcho ()) jsiConsolePrint ("Running onInit()...\n" );
572574 jsiExecuteEventCallback (0 , onInit , 0 , 0 );
575+ jsiCheckErrors ();
573576 jsvUnLock (onInit );
574577 }
575578}
@@ -1528,7 +1531,7 @@ void jsiHandleNewLine(bool execute) {
15281531#endif
15291532 {
15301533 // execute!
1531- JsVar * v = jspEvaluateVar (lineToExecute , 0 , jsiLineNumberOffset );
1534+ JsVar * v = jspEvaluateVar (lineToExecute , 0 , "REPL" , jsiLineNumberOffset );
15321535 // add input line to history
15331536 bool isEmpty = jsvIsEmptyString (lineToExecute );
15341537 // Don't store history if we're not echoing back to the console (it probably wasn't typed by the user)
@@ -2040,7 +2043,7 @@ static NO_INLINE bool jsiExecuteEventCallbackInner(JsVar *thisVar, JsVar *callba
20402043 } else if (jsvIsFunction (callbackNoNames )) {
20412044 jsvUnLock (jspExecuteFunction (callbackNoNames , thisVar , (int )argCount , argPtr ));
20422045 } else if (jsvIsString (callbackNoNames )) {
2043- jsvUnLock (jspEvaluateVar (callbackNoNames , 0 , 0 ));
2046+ jsvUnLock (jspEvaluateVar (callbackNoNames , 0 , "event" , 0 ));
20442047 } else
20452048 jsError ("Unknown type of callback in Event Queue" );
20462049 return ok ;
@@ -2146,7 +2149,7 @@ void jsiCtrlC() {
21462149/** Take an event for a UART and handle the characters we're getting, potentially
21472150 * grabbing more characters as well if it's easy. If more character events are
21482151 * grabbed, the number of extra events (not characters) is returned */
2149- int jsiHandleIOEventForSerial (JsVar * usartClass , IOEventFlags eventFlags , uint8_t * data , int length ) {
2152+ int jsiHandleIOEventForSerial (JsVar * usartClass , IOEventFlags eventFlags , uint8_t * data , unsigned int length ) {
21502153 int eventsHandled = length + 2 ;
21512154 JsVar * stringData = length ? jsvNewStringOfLength (length , (char * )data ) : NULL ;
21522155 if (stringData ) {
@@ -2178,7 +2181,7 @@ void jsiIdle() {
21782181 bool wasBusy = false;
21792182 IOEventFlags eventFlags ;
21802183 uint8_t eventData [IOEVENT_MAX_LEN ];
2181- int eventLen ;
2184+ unsigned int eventLen ;
21822185 // ensure we can't get totally swamped by having more events than we can process.
21832186 // Just process what was in the event queue at the start
21842187 int maxEvents = jshGetEventsUsed ();
@@ -2564,8 +2567,8 @@ void jsiIdle() {
25642567 jsiSemiInit (false, & filename ); // don't autoload code
25652568 // load the code we specified
25662569 JsVar * code = jsfReadFile (filename ,0 ,0 );
2567- if (code )
2568- jsvUnLock2 (jspEvaluateVar (code ,0 ,0 ), code );
2570+ if (code ) // only supply the filename if we're sure it's zero terminated
2571+ jsvUnLock2 (jspEvaluateVar (code ,0 ,filename . c [ sizeof ( filename . c ) - 1 ] ? filename . c : "load" , 0 ), code );
25692572 } else {
25702573 jsiSoftKill ();
25712574 jspSoftKill ();
@@ -2805,14 +2808,14 @@ void jsiDebuggerLoop() {
28052808 itostr ((JsVarInt )jslGetLineNumber () + (JsVarInt )lex -> lineNumberOffset - 1 , lineStr , 10 );
28062809 } else
28072810#endif
2808- {
2811+ { // FIXME: Maybe if executing from a Storage file we use line numbers within that file?
28092812 lineStr [0 ]= 0 ;
28102813 }
28112814 size_t lineLen = strlen (lineStr );
28122815 while (lineLen < sizeof (lineStr )- 1 ) lineStr [lineLen ++ ]= ' ' ;
28132816 lineStr [lineLen ] = 0 ;
28142817 // print the line of code, prefixed by the line number, and with a pointer to the exact character in question
2815- jslPrintTokenLineMarker (vcbprintf_callback_jsiConsolePrintString , 0 , lex -> tokenLastStart , lineStr );
2818+ jslPrintTokenLineMarker (vcbprintf_callback_jsiConsolePrintString , 0 , lex , lex -> tokenLastStart , lineStr );
28162819 }
28172820
28182821 while (!(jsiStatus & JSIS_EXIT_DEBUGGER ) &&
@@ -2822,7 +2825,7 @@ void jsiDebuggerLoop() {
28222825 jshIdle ();
28232826 // If we have too many events (> half full) drain the queue
28242827 uint8_t eventData [IOEVENT_MAX_LEN ];
2825- int eventLen ;
2828+ unsigned int eventLen ;
28262829 while (jshGetEventsUsed ()> IOBUFFERMASK * 1 /2 &&
28272830 !(jsiStatus & JSIS_EXIT_DEBUGGER ) &&
28282831 !(execInfo .execute & EXEC_CTRL_C_MASK )) {
@@ -2906,7 +2909,8 @@ void jsiDebuggerLine(JsVar *line) {
29062909 "finish / f - finish execution of the function call\n"
29072910 "print ... / p ... - evaluate and print the next argument\n"
29082911 "info locals / i l) - output local variables\n"
2909- "info scopechain / i s - output all variables in all scopes\n" );
2912+ "info scopechain / i s - output all variables in all scopes\n"
2913+ "bt - print backtrace\n" );
29102914 } else if (!strcmp (id ,"quit" ) || !strcmp (id ,"q" )) {
29112915 jsiStatus |= JSIS_EXIT_DEBUGGER ;
29122916 execInfo .execute |= EXEC_INTERRUPTED ;
@@ -2962,6 +2966,8 @@ void jsiDebuggerLine(JsVar *line) {
29622966 } else {
29632967 jsiConsolePrint ("Unknown command\n" );
29642968 }
2969+ } else if (!strcmp (id ,"bt" )) {
2970+ jslPrintStackTrace (vcbprintf_callback_jsiConsolePrintString , NULL , oldLex );
29652971 } else
29662972 handled = false;
29672973 }
0 commit comments