@@ -639,6 +639,33 @@ def cdp_event args
639639 code : INVALID_PARAMS ,
640640 message : message
641641 else
642+ src = req . dig ( 'params' , 'expression' )
643+ s_id = ( @src_map . size + 1 ) . to_s
644+ @src_map [ s_id ] = src
645+ lineno = src . lines . count
646+ @ui . fire_event 'Debugger.scriptParsed' ,
647+ scriptId : s_id ,
648+ url : '' ,
649+ startLine : 0 ,
650+ startColumn : 0 ,
651+ endLine : lineno ,
652+ endColumn : 0 ,
653+ executionContextId : 1 ,
654+ hash : src . hash
655+ if exc = result . dig ( :response , :exceptionDetails )
656+ exc [ :stackTrace ] [ :callFrames ] . each { |frame |
657+ if frame [ :url ] . empty?
658+ frame [ :scriptId ] = s_id
659+ else
660+ path = frame [ :url ]
661+ unless s_id = @scr_id_map [ path ]
662+ s_id = ( @scr_id_map . size + 1 ) . to_s
663+ @scr_id_map [ path ] = s_id
664+ end
665+ frame [ :scriptId ] = s_id
666+ end
667+ }
668+ end
642669 rs = result . dig ( :response , :result )
643670 [ rs ] . each { |obj |
644671 if oid = obj [ :objectId ]
@@ -796,13 +823,33 @@ def process_cdp args
796823 rescue Exception => e
797824 result = e
798825 b = result . backtrace . map { |e | " #{ e } \n " }
799- line = b . first . match ( '.*:(\d+):in .*' ) [ 1 ] . to_i
826+ frames = [
827+ {
828+ columnNumber : 0 ,
829+ functionName : 'eval' ,
830+ lineNumber : 0 ,
831+ url : ''
832+ }
833+ ]
834+ e . backtrace_locations &.each do |loc |
835+ break if loc . path == __FILE__
836+ path = loc . absolute_path || loc . path
837+ frames << {
838+ columnNumber : 0 ,
839+ functionName : loc . base_label ,
840+ lineNumber : loc . lineno - 1 ,
841+ url : path
842+ }
843+ end
800844 res [ :exceptionDetails ] = {
801845 exceptionId : 1 ,
802846 text : 'Uncaught' ,
803- lineNumber : line - 1 ,
847+ lineNumber : 0 ,
804848 columnNumber : 0 ,
805849 exception : evaluate_result ( result ) ,
850+ stackTrace : {
851+ callFrames : frames
852+ }
806853 }
807854 ensure
808855 output = $stdout. string
@@ -952,9 +999,12 @@ def variable name, obj
952999 when Integer , Float
9531000 variable_ name , obj , 'number'
9541001 when Exception
955- bt = nil
956- if log = obj . backtrace
957- bt = log . map { |e | " #{ e } \n " } . join
1002+ bt = ''
1003+ if log = obj . backtrace_locations
1004+ log . each do |loc |
1005+ break if loc . path == __FILE__
1006+ bt += " #{ loc } \n "
1007+ end
9581008 end
9591009 variable_ name , obj , 'object' , description : "#{ obj . inspect } \n #{ bt } " , subtype : 'error'
9601010 else
0 commit comments