Skip to content

Commit c64d489

Browse files
committed
refactor: change last_filename and last_funcname from JSAtom to char arrays in debug trace
Update api-test.c to match the new signature, converting to string inside the callback while the atoms are still guaranteed to be valid.
1 parent db61e3c commit c64d489

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

api-test.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,8 @@ static struct {
10171017
int call_count;
10181018
int last_line;
10191019
int last_col;
1020-
JSAtom last_filename;
1021-
JSAtom last_funcname;
1020+
char last_filename[256];
1021+
char last_funcname[256];
10221022
int stack_depth;
10231023
int max_local_count;
10241024
int abort_at; /* abort (return -1) on this call, 0 = never */
@@ -1034,8 +1034,21 @@ static int debug_trace_cb(JSContext *ctx,
10341034
trace_state.call_count++;
10351035
trace_state.last_line = line;
10361036
trace_state.last_col = col;
1037-
trace_state.last_filename = filename;
1038-
trace_state.last_funcname = funcname;
1037+
/* Convert while the atom is still valid (within callback lifetime).
1038+
Embedders who only need to compare against known breakpoint atoms
1039+
can skip this conversion entirely. */
1040+
const char *fn = JS_AtomToCString(ctx, filename);
1041+
if (fn) {
1042+
snprintf(trace_state.last_filename, sizeof(trace_state.last_filename),
1043+
"%s", fn);
1044+
JS_FreeCString(ctx, fn);
1045+
}
1046+
const char *fnn = JS_AtomToCString(ctx, funcname);
1047+
if (fnn) {
1048+
snprintf(trace_state.last_funcname, sizeof(trace_state.last_funcname),
1049+
"%s", fnn);
1050+
JS_FreeCString(ctx, fnn);
1051+
}
10391052
trace_state.stack_depth = JS_GetStackDepth(ctx);
10401053
int count = 0;
10411054
JSDebugLocalVar *vars = NULL;
@@ -1070,11 +1083,7 @@ static void debug_trace(void)
10701083
assert(!JS_IsException(ret));
10711084
JS_FreeValue(ctx, ret);
10721085
assert(trace_state.call_count > 0);
1073-
{
1074-
const char *fn = JS_AtomToCString(ctx, trace_state.last_filename);
1075-
assert(fn && !strcmp(fn, "<input>"));
1076-
JS_FreeCString(ctx, fn);
1077-
}
1086+
assert(!strcmp(trace_state.last_filename, "<input>"));
10781087
}
10791088

10801089
{

0 commit comments

Comments
 (0)