File tree Expand file tree Collapse file tree 1 file changed +36
-5
lines changed Expand file tree Collapse file tree 1 file changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -355,12 +355,43 @@ unsafe fn emit_frame_as_json(
355355    // to a valid RuntimeStackFrame. 
356356    let  frame_ref = & * frame; 
357357
358-     // TODO: this allocates a new StackFrame. Avoid this by just emitting the JSON directly here. 
359-     let  stack_frame:  StackFrame  = frame_ref. into ( ) ; 
358+     write ! ( writer,  "{{" ) ?; 
360359
361-     // Serialize to JSON and write 
362-     let  json = serde_json:: to_string ( & stack_frame) . map_err ( std:: io:: Error :: other) ?; 
363-     writeln ! ( writer,  "{}" ,  json) ?; 
360+     let  mut  first_field = true ; 
361+ 
362+     if  let  Ok ( Some ( function_name) )  = frame_ref. function_name . try_to_string_option ( )  { 
363+         write ! ( 
364+             writer, 
365+             "\" function\" : \" {}\" " , 
366+             function_name. replace( '"' ,  "\\ \" " ) 
367+         ) ?; 
368+         first_field = false ; 
369+     } 
370+ 
371+     if  let  Ok ( Some ( file_name) )  = frame_ref. file_name . try_to_string_option ( )  { 
372+         if  !first_field { 
373+             write ! ( writer,  ", " ) ?; 
374+         } 
375+         write ! ( writer,  "\" file\" : \" {}\" " ,  file_name. replace( '"' ,  "\\ \" " ) ) ?; 
376+         first_field = false ; 
377+     } 
378+ 
379+     if  frame_ref. line_number  != 0  { 
380+         if  !first_field { 
381+             write ! ( writer,  ", " ) ?; 
382+         } 
383+         write ! ( writer,  "\" line\" : {}" ,  frame_ref. line_number) ?; 
384+         first_field = false ; 
385+     } 
386+ 
387+     if  frame_ref. column_number  != 0  { 
388+         if  !first_field { 
389+             write ! ( writer,  ", " ) ?; 
390+         } 
391+         write ! ( writer,  "\" column\" : {}" ,  frame_ref. column_number) ?; 
392+     } 
393+ 
394+     writeln ! ( writer,  "}}" ) ?; 
364395    Ok ( ( ) ) 
365396} 
366397
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments