Skip to content

Commit bffcf12

Browse files
committed
CDP: support to show global variables
1 parent 5bb2ff1 commit bffcf12

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

lib/debug/server_cdp.rb

+41-1
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,27 @@ def puts result
685685
end
686686

687687
class Session
688+
def get_type obj
689+
case obj
690+
when Array
691+
['object', 'array']
692+
when Hash
693+
['object', 'map']
694+
when String
695+
['string']
696+
when TrueClass, FalseClass
697+
['boolean']
698+
when Symbol
699+
['symbol']
700+
when Integer, Float
701+
['number']
702+
when Exception
703+
['object', 'error']
704+
else
705+
['object']
706+
end
707+
end
708+
688709
def fail_response req, **result
689710
@ui.respond_fail req, **result
690711
return :retry
@@ -716,9 +737,28 @@ def process_protocol_request req
716737
frame_id = ref[1]
717738
fid = @frame_map[frame_id]
718739
request_tc [:cdp, :scope, req, fid]
740+
when 'global'
741+
vars = global_variables.sort.map do |name|
742+
gv = eval(name.to_s)
743+
prop = {
744+
name: name,
745+
value: {
746+
description: gv.inspect
747+
},
748+
configurable: true,
749+
enumerable: true
750+
}
751+
type, subtype = get_type(gv)
752+
prop[:value][:type] = type
753+
prop[:value][:subtype] = subtype if subtype
754+
prop
755+
end
756+
757+
@ui.respond req, result: vars
758+
return :retry
719759
when 'properties'
720760
request_tc [:cdp, :properties, req, oid]
721-
when 'script', 'global'
761+
when 'script'
722762
# TODO: Support script and global types
723763
@ui.respond req, result: []
724764
return :retry

0 commit comments

Comments
 (0)