Skip to content

Commit

Permalink
suppress warnings about deprecated global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
arika authored and ko1 committed Dec 6, 2022
1 parent ec5ae5a commit b4ec2d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/debug/server_cdp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ def puts result
end

class Session
include GlobalVariablesHelper

# FIXME: unify this method with ThreadClient#propertyDescriptor.
def get_type obj
case obj
Expand Down Expand Up @@ -750,7 +752,7 @@ def process_protocol_request req
fid = @frame_map[frame_id]
request_tc [:cdp, :scope, req, fid]
when 'global'
vars = global_variables.sort.map do |name|
vars = safe_global_variables.sort.map do |name|
gv = eval(name.to_s)
prop = {
name: name,
Expand Down Expand Up @@ -1040,7 +1042,7 @@ def process_cdp args
case expr
# Chrome doesn't read instance variables
when /\A\$\S/
global_variables.each{|gvar|
safe_global_variables.each{|gvar|
if gvar.to_s == expr
result = eval(gvar.to_s)
break false
Expand Down
8 changes: 5 additions & 3 deletions lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ def event type, *args
end

class Session
include GlobalVariablesHelper

def find_waiting_tc id
@th_clients.each{|th, tc|
return tc if tc.id == id && tc.waiting?
Expand Down Expand Up @@ -562,7 +564,7 @@ def process_protocol_request req
if ref = @var_map[varid]
case ref[0]
when :globals
vars = global_variables.sort.map do |name|
vars = safe_global_variables.sort.map do |name|
gv = eval(name.to_s)
{
name: name,
Expand Down Expand Up @@ -800,7 +802,7 @@ def process_dap args
name: 'Global variables',
presentationHint: 'globals',
variablesReference: 1, # GLOBAL
namedVariables: global_variables.size,
namedVariables: safe_global_variables.size,
indexedVariables: 0,
expensive: false,
}]
Expand Down Expand Up @@ -887,7 +889,7 @@ def process_dap args
message = "Error: Not defined instance variable: #{expr.inspect}"
end
when /\A\$\S/
global_variables.each{|gvar|
safe_global_variables.each{|gvar|
if gvar.to_s == expr
result = eval(gvar.to_s)
break false
Expand Down
11 changes: 9 additions & 2 deletions lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def skip_location?(loc)
end
end

module GlobalVariablesHelper
SKIP_GLOBAL_LIST = %i[$= $KCODE $-K $SAFE].freeze
def safe_global_variables
global_variables.reject{|name| SKIP_GLOBAL_LIST.include? name }
end
end

class ThreadClient
def self.current
if thc = Thread.current[:DEBUGGER__ThreadClient]
Expand All @@ -50,6 +57,7 @@ def self.current

include Color
include SkipPathHelper
include GlobalVariablesHelper

attr_reader :thread, :id, :recorder, :check_bp_fulfillment_map

Expand Down Expand Up @@ -636,9 +644,8 @@ def show_consts pat, expr = nil, only_self: false
end
end

SKIP_GLOBAL_LIST = %i[$= $KCODE $-K $SAFE].freeze
def show_globals pat
global_variables.sort.each{|name|
safe_global_variables.sort.each{|name|
next if SKIP_GLOBAL_LIST.include? name

value = eval(name.to_s)
Expand Down

0 comments on commit b4ec2d7

Please sign in to comment.