4848#include "libregexp.h"
4949#include "dtoa.h"
5050
51- #if defined(EMSCRIPTEN) || defined(_MSC_VER)
51+ #if defined(EMSCRIPTEN) || defined(_MSC_VER) || defined(QJS_ENABLE_DEBUGGER)
5252#define DIRECT_DISPATCH 0
5353#else
5454#define DIRECT_DISPATCH 1
@@ -535,9 +535,10 @@ struct JSContext {
535535 const char *input, size_t input_len,
536536 const char *filename, int line, int flags, int scope_idx);
537537 void *user_opaque;
538-
538+ #ifdef QJS_ENABLE_DEBUGGER
539539 JSOPChangedHandler *operation_changed;
540540 void *oc_opaque;
541+ #endif
541542};
542543
543544typedef union JSFloat64Union {
@@ -2560,6 +2561,8 @@ JSValue JS_GetFunctionProto(JSContext *ctx)
25602561 return js_dup(ctx->function_proto);
25612562}
25622563
2564+ #ifdef QJS_ENABLE_DEBUGGER
2565+
25632566void JS_SetOPChangedHandler(JSContext *ctx, JSOPChangedHandler *cb, void *opaque)
25642567{
25652568 ctx->operation_changed = cb;
@@ -2595,7 +2598,7 @@ int JS_GetStackDepth(JSContext *ctx)
25952598}
25962599
25972600/* Get local variables at a specific stack level */
2598- JSLocalVar *JS_GetLocalVariablesAtLevel(JSContext *ctx, int level, int *pcount)
2601+ JSDebugLocalVar *JS_GetLocalVariablesAtLevel(JSContext *ctx, int level, int *pcount)
25992602{
26002603 if (pcount)
26012604 *pcount = 0;
@@ -2618,7 +2621,7 @@ JSLocalVar *JS_GetLocalVariablesAtLevel(JSContext *ctx, int level, int *pcount)
26182621 if (total_vars == 0)
26192622 return NULL;
26202623
2621- JSLocalVar *vars = js_malloc(ctx, sizeof(JSLocalVar ) * total_vars);
2624+ JSDebugLocalVar *vars = js_malloc(ctx, sizeof(JSDebugLocalVar ) * total_vars);
26222625 if (!vars)
26232626 return NULL;
26242627
@@ -2648,7 +2651,7 @@ JSLocalVar *JS_GetLocalVariablesAtLevel(JSContext *ctx, int level, int *pcount)
26482651}
26492652
26502653/* Free local variables array */
2651- void JS_FreeLocalVariables(JSContext *ctx, JSLocalVar *vars, int count)
2654+ void JS_FreeLocalVariables(JSContext *ctx, JSDebugLocalVar *vars, int count)
26522655{
26532656 if (!vars)
26542657 return;
@@ -2659,6 +2662,8 @@ void JS_FreeLocalVariables(JSContext *ctx, JSLocalVar *vars, int count)
26592662 js_free(ctx, vars);
26602663}
26612664
2665+ #endif /* QJS_ENABLE_DEBUGGER */
2666+
26622667typedef enum JSFreeModuleEnum {
26632668 JS_FREE_MODULE_ALL,
26642669 JS_FREE_MODULE_NOT_RESOLVED,
@@ -17573,34 +17578,29 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1757317578 int call_argc;
1757417579 JSValue *call_argv;
1757517580
17576- {
17577- if (b && ctx->operation_changed != NULL) {
17578- int col_num = 0;
17579- int line_num = -1;
17580- const char *filename = NULL;
17581- const char *funcname = NULL;
17581+ #ifdef QJS_ENABLE_DEBUGGER
17582+ if (b && ctx->operation_changed != NULL) {
17583+ int col_num = 0;
17584+ int line_num = -1;
1758217585
17583- uint32_t pc_index = (uint32_t)(pc - b->byte_code_buf);
17584- if (b->pc2line_buf) {
17585- line_num = find_line_num(ctx, b, pc_index, &col_num);
17586- }
17587- filename = b->filename ? JS_AtomToCString(ctx, b->filename) : NULL;
17588- funcname = b->func_name ? JS_AtomToCString(ctx, b->func_name) : NULL;
17586+ uint32_t pc_index = (uint32_t)(pc - b->byte_code_buf);
17587+ if (b->pc2line_buf) {
17588+ line_num = find_line_num(ctx, b, pc_index, &col_num);
17589+ }
17590+ const char * filename = b->filename ? JS_AtomToCString(ctx, b->filename) : NULL;
17591+ const char * funcname = b->func_name ? JS_AtomToCString(ctx, b->func_name) : NULL;
1758917592
17590- int ret = 0;
17591- ret = ctx->operation_changed(ctx, *pc, filename, funcname, line_num, col_num, ctx->oc_opaque);
17592- if (filename) {
17593- // fprintf(stderr, "op:%d %d at %s %s:%d:%d\n", *pc, OP_return, funcname, filename, line_num, col_num);
17594- JS_FreeCString(ctx, filename);
17595- JS_FreeCString(ctx, funcname);
17596- }
17593+ int ret = ctx->operation_changed(ctx, *pc, filename, funcname,
17594+ line_num, col_num, ctx->oc_opaque);
17595+ if (filename)
17596+ JS_FreeCString(ctx, filename);
17597+ if (funcname)
17598+ JS_FreeCString(ctx, funcname);
1759717599
17598- if(ret != 0)
17599- {
17600- goto exception;
17601- }
17602- }
17600+ if (ret != 0)
17601+ goto exception;
1760317602 }
17603+ #endif /* QJS_ENABLE_DEBUGGER */
1760417604
1760517605 SWITCH(pc) {
1760617606 CASE(OP_push_i32):
0 commit comments