Skip to content

CDP: support to show global variables #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion lib/debug/server_cdp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,28 @@ def puts result
end

class Session
# FIXME: unify this method with ThreadClient#propertyDescriptor.
def get_type obj
case obj
when Array
['object', 'array']
when Hash
['object', 'map']
when String
['string']
when TrueClass, FalseClass
['boolean']
when Symbol
['symbol']
when Integer, Float
['number']
when Exception
['object', 'error']
else
['object']
end
end

def fail_response req, **result
@ui.respond_fail req, **result
return :retry
Expand Down Expand Up @@ -716,9 +738,28 @@ def process_protocol_request req
frame_id = ref[1]
fid = @frame_map[frame_id]
request_tc [:cdp, :scope, req, fid]
when 'global'
vars = global_variables.sort.map do |name|
gv = eval(name.to_s)
prop = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can extract ThreadClient#propertyDescriptor and use it here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I plan to refactor them after releasing the new version. I added the comment. Thank you.

name: name,
value: {
description: gv.inspect
},
configurable: true,
enumerable: true
}
type, subtype = get_type(gv)
prop[:value][:type] = type
prop[:value][:subtype] = subtype if subtype
prop
end

@ui.respond req, result: vars
return :retry
when 'properties'
request_tc [:cdp, :properties, req, oid]
when 'script', 'global'
when 'script'
# TODO: Support script and global types
@ui.respond req, result: []
return :retry
Expand Down