@@ -295,12 +295,63 @@ static void js_debugger_get_variable_type(JSContext* ctx,
295
295
sprintf (buffer , "ƒ %s ()" , func_name );
296
296
variable_type -> value = copy_string (buffer , strlen (buffer ));
297
297
JS_FreeCString (ctx , func_name );
298
+ } else if (JS_IsArray (ctx , var_val )) {
299
+ variable_type -> type = "array" ;
300
+ char buf [12 ];
301
+ int64_t length ;
302
+ js_get_length64 (ctx , & length , var_val );
303
+ sprintf (buf , "Array(%lld)" , length );
304
+ variable_type -> value = copy_string (buf , strlen (buf ));
298
305
} else {
299
306
JSValue object_proto = JS_GetPrototype (ctx , var_val );
300
307
JSValue constructor_func = JS_GetPropertyStr (ctx , object_proto , "constructor" );
301
308
char buffer [64 ];
302
309
sprintf (buffer , "%s" , get_func_name (ctx , constructor_func ));
303
- variable_type -> value = copy_string (buffer , strlen (buffer ));
310
+
311
+ if (strcmp (buffer , "Object" ) == 0 ) {
312
+ if (is_short ) {
313
+ variable_type -> value = "{..}" ;
314
+ } else {
315
+ JSPropertyEnum * property_enum ;
316
+ uint32_t property_len ;
317
+ if (!JS_GetOwnPropertyNames (ctx , & property_enum , & property_len , var_val , JS_GPN_SYMBOL_MASK | JS_GPN_STRING_MASK )) {
318
+ size_t buf_len = 256 ;
319
+ char * buf = js_malloc (ctx , 256 );
320
+ buf [0 ] = '{' ;
321
+ size_t index = 1 ;
322
+ for (int i = 0 ; i < property_len ; i ++ ) {
323
+ JSValue v = JS_GetProperty (ctx , var_val , property_enum [i ].atom );
324
+ const char * key = atom_to_string (ctx , property_enum [i ].atom );
325
+ VariableType object_var_type ;
326
+ js_debugger_get_variable_type (ctx , state , & object_var_type , v , depth + 1 , 1 );
327
+ const char * tmp = object_var_type .value ;
328
+ size_t tmp_len = strlen (tmp );
329
+ if (index + tmp_len > buf_len ) {
330
+ buf_len = buf_len * 2 ;
331
+ js_realloc (ctx , buf , buf_len );
332
+ }
333
+ strcpy (buf + index , key );
334
+ index += strlen (key );
335
+ strcpy (buf + index , ": " );
336
+ index += 2 ;
337
+ strcpy (buf + index , tmp );
338
+ index += tmp_len ;
339
+
340
+ if (i + 1 < property_len ) {
341
+ strcpy (buf + index , ", " );
342
+ index += 2 ;
343
+ }
344
+ JS_FreeValue (ctx , v );
345
+ }
346
+ buf [index ] = '}' ;
347
+ buf [index + 1 ] = 0 ;
348
+ variable_type -> value = buf ;
349
+ }
350
+ }
351
+ } else {
352
+ variable_type -> value = copy_string (buffer , strlen (buffer ));
353
+ }
354
+
304
355
JS_FreeValue (ctx , object_proto );
305
356
JS_FreeValue (ctx , constructor_func );
306
357
}
@@ -366,7 +417,7 @@ static void process_request(JSDebuggerInfo* info, struct DebuggerSuspendedState*
366
417
const char * evaluate_result = JS_ToCStringLen (ctx , & len , result );
367
418
response -> body -> result = copy_string (evaluate_result , len );
368
419
VariableType variable_type ;
369
- js_debugger_get_variable_type (ctx , state , & variable_type , result );
420
+ js_debugger_get_variable_type (ctx , state , & variable_type , result , 0 , 0 );
370
421
response -> body -> type = variable_type .type ;
371
422
response -> body -> variablesReference = variable_type .variablesReference ;
372
423
@@ -489,7 +540,7 @@ static void process_request(JSDebuggerInfo* info, struct DebuggerSuspendedState*
489
540
for (uint32_t i = 0 ; i < count ; i ++ ) {
490
541
JSValue value = JS_GetPropertyUint32 (ctx , variable , start + i );
491
542
VariableType variable_type ;
492
- js_debugger_get_variable_type (ctx , state , & variable_type , value );
543
+ js_debugger_get_variable_type (ctx , state , & variable_type , value , 0 , 0 );
493
544
494
545
sprintf (name_buf , "%d" , i );
495
546
init_variable (& variables [i ]);
@@ -506,49 +557,50 @@ static void process_request(JSDebuggerInfo* info, struct DebuggerSuspendedState*
506
557
}
507
558
508
559
unfiltered :
509
- if (!JS_GetOwnPropertyNames (ctx , & tab_atom , & tab_atom_count , variable , JS_GPN_ENUM_ONLY | JS_GPN_STRING_MASK )) {
560
+ if (!JS_GetOwnPropertyNames (ctx , & tab_atom , & tab_atom_count , variable , JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK )) {
510
561
if (tab_atom_count == 0 ) {
511
562
variables = NULL ;
512
563
variableLen = 0 ;
513
564
goto done ;
514
565
}
515
566
516
- int offset = 0 ;
517
567
variables = js_malloc (ctx , sizeof (Variable ) * (tab_atom_count + (skip_proto ? 0 : 1 )));
518
568
569
+ for (int i = 0 ; i < tab_atom_count ; i ++ ) {
570
+ JSValue value = JS_GetProperty (ctx , variable , tab_atom [i ].atom );
571
+ VariableType variable_type ;
572
+ js_debugger_get_variable_type (ctx , state , & variable_type , value , 0 , 0 );
573
+ init_variable (& variables [i ]);
574
+ variables [i ].name = atom_to_string (ctx , tab_atom [i ].atom );
575
+ variables [i ].type = variable_type .type ;
576
+ variables [i ].variablesReference = variable_type .variablesReference ;
577
+ variables [i ].value = variable_type .value ;
578
+ assert (variables [i ].name != NULL );
579
+ assert (variables [i ].value != NULL );
580
+ JS_FreeValue (ctx , value );
581
+ }
582
+
519
583
if (!skip_proto ) {
520
584
const JSValue proto = JS_GetPrototype (ctx , variable );
521
585
if (!JS_IsException (proto )) {
522
586
VariableType variable_type ;
523
- js_debugger_get_variable_type (ctx , state , & variable_type , proto );
524
- int i = offset ++ ;
525
- init_variable (& variables [i ]);
526
- variables [i ].name = "[[Prototype]]" ;
527
- variables [i ].value = variable_type .type ;
528
- variables [i ].type = variable_type .value ;
529
- variables [i ].variablesReference = variable_type .variablesReference ;
530
- assert (variables [i ].name != NULL );
531
- assert (variables [i ].value != NULL );
587
+ js_debugger_get_variable_type (ctx , state , & variable_type , proto , 0 , 0 );
588
+ init_variable (& variables [tab_atom_count ]);
589
+ variables [tab_atom_count ].name = "[[Prototype]]" ;
590
+ variables [tab_atom_count ].value = variable_type .type ;
591
+ variables [tab_atom_count ].type = variable_type .value ;
592
+ variables [tab_atom_count ].variablesReference = variable_type .variablesReference ;
593
+ VariablePresentationHint * presentation_hint = js_malloc (ctx , sizeof (VariablePresentationHint ));
594
+ presentation_hint -> visibility = "internal" ;
595
+ presentation_hint -> lazy = 0 ;
596
+ variables [tab_atom_count ].presentationHint = presentation_hint ;
597
+ assert (variables [tab_atom_count ].name != NULL );
598
+ assert (variables [tab_atom_count ].value != NULL );
532
599
}
533
600
JS_FreeValue (ctx , proto );
534
601
}
535
602
536
- for (int i = 0 ; i < tab_atom_count ; i ++ ) {
537
- JSValue value = JS_GetProperty (ctx , variable , tab_atom [i ].atom );
538
- printf ("atom %s %p\n" , info -> runtime -> atom_array [tab_atom [i ].atom ]-> u .str8 , JS_VALUE_GET_PTR (value ));
539
- VariableType variable_type ;
540
- js_debugger_get_variable_type (ctx , state , & variable_type , value );
541
- init_variable (& variables [i + offset ]);
542
- variables [i + offset ].name = atom_to_string (ctx , tab_atom [i ].atom );
543
- variables [i + offset ].type = variable_type .type ;
544
- variables [i + offset ].variablesReference = variable_type .variablesReference ;
545
- variables [i + offset ].value = variable_type .value ;
546
- assert (variables [i + offset ].name != NULL );
547
- assert (variables [i + offset ].value != NULL );
548
- JS_FreeValue (ctx , value );
549
- }
550
-
551
- variableLen = offset + tab_atom_count ;
603
+ variableLen = tab_atom_count + (skip_proto ? 0 : 1 );
552
604
js_free_prop_enum (ctx , tab_atom , tab_atom_count );
553
605
}
554
606
@@ -614,7 +666,7 @@ static void js_process_debugger_messages(JSDebuggerInfo* info, const uint8_t* cu
614
666
Request * request = js_malloc (ctx , sizeof (Request ));
615
667
parse_request (ctx , request , item .buf , item .length );
616
668
process_request (info , & state , request );
617
- free_request (ctx , request );
669
+ // free_request(ctx, request);
618
670
619
671
js_free (ctx , item .buf );
620
672
} while (info -> is_paused );
0 commit comments