Skip to content

Commit 2f40ad4

Browse files
ono-maxko1
authored andcommitted
CDP: support to show global variables
1 parent 182e779 commit 2f40ad4

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

lib/debug/server_cdp.rb

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

687687
class Session
688+
# FIXME: unify this method with ThreadClient#propertyDescriptor.
689+
def get_type obj
690+
case obj
691+
when Array
692+
['object', 'array']
693+
when Hash
694+
['object', 'map']
695+
when String
696+
['string']
697+
when TrueClass, FalseClass
698+
['boolean']
699+
when Symbol
700+
['symbol']
701+
when Integer, Float
702+
['number']
703+
when Exception
704+
['object', 'error']
705+
else
706+
['object']
707+
end
708+
end
709+
688710
def fail_response req, **result
689711
@ui.respond_fail req, **result
690712
return :retry
@@ -716,9 +738,28 @@ def process_protocol_request req
716738
frame_id = ref[1]
717739
fid = @frame_map[frame_id]
718740
request_tc [:cdp, :scope, req, fid]
741+
when 'global'
742+
vars = global_variables.sort.map do |name|
743+
gv = eval(name.to_s)
744+
prop = {
745+
name: name,
746+
value: {
747+
description: gv.inspect
748+
},
749+
configurable: true,
750+
enumerable: true
751+
}
752+
type, subtype = get_type(gv)
753+
prop[:value][:type] = type
754+
prop[:value][:subtype] = subtype if subtype
755+
prop
756+
end
757+
758+
@ui.respond req, result: vars
759+
return :retry
719760
when 'properties'
720761
request_tc [:cdp, :properties, req, oid]
721-
when 'script', 'global'
762+
when 'script'
722763
# TODO: Support script and global types
723764
@ui.respond req, result: []
724765
return :retry

0 commit comments

Comments
 (0)