Skip to content
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

Move IRB::TOPLEVEL_BINDING from exe/irb to lib/irb/workspace.rb #287

Merged
merged 3 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
require "bundler/setup"
require_relative "../lib/irb"

IRB::TOPLEVEL_BINDING = binding
IRB.start(__FILE__)
1 change: 0 additions & 1 deletion exe/irb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

require "irb"

IRB::TOPLEVEL_BINDING = binding
IRB.start(__FILE__)
2 changes: 2 additions & 0 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ def handle_exception(exc)
lines = lines.reverse if order == :bottom
lines.map{ |l| l + "\n" }.join
}
# The "<top (required)>" in "(irb)" may be the top level of IRB so imitate the main object.
message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
puts message
end
print "Maybe IRB bug!\n" if irb_bug
Expand Down
3 changes: 2 additions & 1 deletion lib/irb/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

require "delegate"

IRB::TOPLEVEL_BINDING = binding
module IRB # :nodoc:
class WorkSpace
# Creates a new workspace.
Expand Down Expand Up @@ -57,7 +58,7 @@ def initialize(*main)
__FILE__,
__LINE__ - 3)
when 4 # binding is a copy of TOPLEVEL_BINDING (default)
# Note that this will typically be IRB::TOPLEVEL_BINDING (see exe/irb)
# Note that this will typically be IRB::TOPLEVEL_BINDING
# This is to avoid RubyGems' local variables (see issue #17623)
@binding = TOPLEVEL_BINDING.dup
end
Expand Down
3 changes: 2 additions & 1 deletion test/irb/test_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ def test_code_around_binding_on_irb


def test_toplevel_binding_local_variables
pend if RUBY_ENGINE == 'truffleruby'
bug17623 = '[ruby-core:102468]'
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
status = assert_in_out_err(bundle_exec + ['-W0', '-e', <<~RUBY , '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
assert_in_out_err(bundle_exec + ['-W0', '-e', <<~RUBY , '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
version = 'xyz' # typical rubygems loading file
load('./exe/irb')
RUBY
Expand Down