Skip to content

Commit 9d01f3b

Browse files
committed
feat: support getting scopes.
1 parent 6de9bd8 commit 9d01f3b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

bridge/third_party/quickjs/src/core/debugger.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,32 +226,33 @@ static void js_send_stopped_event(JSDebuggerInfo* info, const char* reason) {
226226
js_transport_send_event(info, (Event*) event);
227227
}
228228

229-
static Scope* js_get_scopes(JSContext* ctx, int64_t frame) {
229+
static void js_get_scopes(JSContext* ctx, int64_t frame, ScopesResponseBody* body) {
230230
// for now this is always the same.
231231
// global, local, closure. may change in the future. can check if closure is empty.
232-
Scope* scope = js_malloc(ctx, sizeof(Scope) * 3);
232+
Scope* scopes = js_malloc(ctx, sizeof(Scope) * 3);
233233

234234
// Init scopes
235235
for(int i = 0; i < 3; i ++) {
236-
init_scope(&scope[i]);
236+
init_scope(&scopes[i]);
237237
}
238238

239239
// Get local scope
240-
scope[0].name = "Local";
241-
scope[0].variablesReference = (frame << 2) + 1;
242-
scope[0].expensive = 0;
240+
scopes[0].name = "Local";
241+
scopes[0].variablesReference = (frame << 2) + 1;
242+
scopes[0].expensive = 0;
243243

244244
// Get closure
245-
scope[1].name = "Closure";
246-
scope[1].variablesReference = (frame << 2) + 2;
247-
scope[1].expensive = 0;
245+
scopes[1].name = "Closure";
246+
scopes[1].variablesReference = (frame << 2) + 2;
247+
scopes[1].expensive = 0;
248248

249249
// Get global
250-
scope[2].name = "Global";
251-
scope[2].variablesReference = (frame << 2) + 0;
252-
scope[2].expensive = 0;
250+
scopes[2].name = "Global";
251+
scopes[2].variablesReference = (frame << 2) + 0;
252+
scopes[2].expensive = 0;
253253

254-
return scope;
254+
body->scopes = scopes;
255+
body->scopesLen = 3;
255256
}
256257

257258
static inline JS_BOOL JS_IsInteger(JSValueConst v) {
@@ -419,7 +420,7 @@ static void process_request(JSDebuggerInfo* info, struct DebuggerSuspendedState*
419420
ScopesArguments* arguments = (ScopesArguments*)request->arguments;
420421
int64_t frame = arguments->frameId;
421422
ScopesResponse* response = initialize_response(ctx, request, "scopes");
422-
response->body->scopes = js_get_scopes(ctx, frame);
423+
js_get_scopes(ctx, frame, response->body);
423424
js_transport_send_response(info, ctx, (Response*)response);
424425
} else if (strcmp(command, "setBreakpoints") == 0) {
425426
SetBreakpointsArguments* arguments = (SetBreakpointsArguments*)request->arguments;

0 commit comments

Comments
 (0)