839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
|
# File 'lib/debug/server_cdp.rb', line 839
def process_protocol_result args
type, req, result = args
case type
when :backtrace
result[:callFrames].each.with_index do |frame, i|
frame_id = frame[:callFrameId]
@frame_map[frame_id] = i
path = frame[:url]
unless s_id = @scr_id_map[path]
s_id = (@scr_id_map.size + 1).to_s
@scr_id_map[path] = s_id
lineno = 0
src = ''
if path && File.exist?(path)
src = File.read(path)
@src_map[s_id] = src
lineno = src.lines.count
end
@ui.fire_event 'Debugger.scriptParsed',
scriptId: s_id,
url: path,
startLine: 0,
startColumn: 0,
endLine: lineno,
endColumn: 0,
executionContextId: 1,
hash: src.hash.inspect
end
frame[:location][:scriptId] = s_id
frame[:functionLocation][:scriptId] = s_id
frame[:scopeChain].each {|s|
oid = s.dig(:object, :objectId)
@obj_map[oid] = [s[:type], frame_id]
}
end
if oid = result.dig(:data, :objectId)
@obj_map[oid] = ['properties']
end
@ui.fire_event 'Debugger.paused', **result
when :evaluate
message = result.delete :message
if message
fail_response req,
code: INVALID_PARAMS,
message: message
else
src = req.dig('params', 'expression')
s_id = (@src_map.size + 1).to_s
@src_map[s_id] = src
lineno = src.lines.count
@ui.fire_event 'Debugger.scriptParsed',
scriptId: s_id,
url: '',
startLine: 0,
startColumn: 0,
endLine: lineno,
endColumn: 0,
executionContextId: 1,
hash: src.hash.inspect
if exc = result.dig(:response, :exceptionDetails)
exc[:stackTrace][:callFrames].each{|frame|
if frame[:url].empty?
frame[:scriptId] = s_id
else
path = frame[:url]
unless s_id = @scr_id_map[path]
s_id = (@scr_id_map.size + 1).to_s
@scr_id_map[path] = s_id
end
frame[:scriptId] = s_id
end
}
if oid = exc[:exception][:objectId]
@obj_map[oid] = ['exception']
end
end
rs = result.dig(:response, :result)
[rs].each{|obj|
if oid = obj[:objectId]
@obj_map[oid] = ['properties']
end
}
@ui.respond req, **result[:response]
out = result[:output]
if out && !out.empty?
@ui.fire_event 'Runtime.consoleAPICalled',
type: 'log',
args: [
type: out.class,
value: out
],
executionContextId: 1,
timestamp: Time.now.to_f
end
end
when :scope
result.each{|obj|
if oid = obj.dig(:value, :objectId)
@obj_map[oid] = ['properties']
end
}
@ui.respond req, result: result
when :properties
result.each_value{|v|
v.each{|obj|
if oid = obj.dig(:value, :objectId)
@obj_map[oid] = ['properties']
end
}
}
@ui.respond req, **result
when :exception
@ui.respond req, **result
end
end
|