MCPcopy Create free account
hub / github.com/BruceDevices/firmware / js_fatal_error_handler

Function js_fatal_error_handler

src/modules/bjs_interpreter/helpers_js.cpp:26–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26void js_fatal_error_handler(JSContext *ctx) {
27 JSValue obj;
28 JSCStringBuf sb;
29 obj = JS_GetException(ctx);
30
31 JSValue jsvMessage = JS_GetPropertyStr(ctx, obj, "message");
32 if (strcmp(JS_ToCString(ctx, jsvMessage, &sb), "Script exited") == 0) { return; }
33
34 tft.fillScreen(bruceConfig.bgColor);
35 tft.setTextSize(FM);
36 tft.setTextColor(TFT_RED, bruceConfig.bgColor);
37 tft.drawCentreString("Error", tftWidth / 2, 10, 1);
38 tft.setTextColor(TFT_WHITE, bruceConfig.bgColor);
39 tft.setTextSize(FP);
40 tft.setCursor(0, 33);
41
42 JSValue jsvStack = JS_GetPropertyStr(ctx, obj, "stack");
43 const char *stackTrace = NULL;
44 if (!JS_IsUndefined(jsvStack) && JS_IsString(ctx, jsvStack)) {
45 stackTrace = JS_ToCString(ctx, jsvStack, &sb);
46 } else {
47 /* fallback to exception's string representation */
48 stackTrace = JS_ToCString(ctx, obj, &sb);
49 }
50
51 JS_PrintValueF(ctx, obj, JS_DUMP_LONG);
52 const char *msg = JS_ToCString(ctx, obj, &sb);
53
54 print_errorMessage(msg != NULL ? msg : "JS Error", stackTrace);
55}
56
57bool JS_IsTypedArray(JSContext *ctx, JSValue val) {
58 int classId = JS_GetClassID(ctx, val);

Callers 1

interpreterHandlerFunction · 0.85

Calls 6

print_errorMessageFunction · 0.85
fillScreenMethod · 0.45
setTextSizeMethod · 0.45
setTextColorMethod · 0.45
drawCentreStringMethod · 0.45
setCursorMethod · 0.45

Tested by

no test coverage detected