[ruby/irb] Remove keyword exception from Context#evaluate because
the value is always nil (https://github.com/ruby/irb/pull/617) https://github.com/ruby/irb/commit/62691384f8
This commit is contained in:
parent
caddd0274b
commit
8aedfefb21
21
lib/irb.rb
21
lib/irb.rb
@ -506,8 +506,6 @@ module IRB
|
|||||||
|
|
||||||
# Evaluates input for this session.
|
# Evaluates input for this session.
|
||||||
def eval_input
|
def eval_input
|
||||||
exc = nil
|
|
||||||
|
|
||||||
@scanner.set_prompt do
|
@scanner.set_prompt do
|
||||||
|ltype, indent, continue, line_no|
|
|ltype, indent, continue, line_no|
|
||||||
if ltype
|
if ltype
|
||||||
@ -567,18 +565,18 @@ module IRB
|
|||||||
is_assignment = assignment_expression?(line)
|
is_assignment = assignment_expression?(line)
|
||||||
if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
|
if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
|
||||||
result = nil
|
result = nil
|
||||||
last_proc = proc{ result = evaluate_line(line, line_no, exception: exc) }
|
last_proc = proc{ result = evaluate_line(line, line_no) }
|
||||||
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) { |chain, item|
|
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) { |chain, item|
|
||||||
_name, callback, arg = item
|
_name, callback, arg = item
|
||||||
proc {
|
proc {
|
||||||
callback.(@context, line, line_no, arg, exception: exc) do
|
callback.(@context, line, line_no, arg) do
|
||||||
chain.call
|
chain.call
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}.call
|
}.call
|
||||||
@context.set_last_value(result)
|
@context.set_last_value(result)
|
||||||
else
|
else
|
||||||
evaluate_line(line, line_no, exception: exc)
|
evaluate_line(line, line_no)
|
||||||
end
|
end
|
||||||
if @context.echo?
|
if @context.echo?
|
||||||
if is_assignment
|
if is_assignment
|
||||||
@ -589,22 +587,17 @@ module IRB
|
|||||||
output_value
|
output_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Interrupt => exc
|
|
||||||
rescue SystemExit, SignalException
|
rescue SystemExit, SignalException
|
||||||
raise
|
raise
|
||||||
rescue Exception => exc
|
rescue Interrupt, Exception => exc
|
||||||
else
|
|
||||||
exc = nil
|
|
||||||
next
|
|
||||||
end
|
|
||||||
handle_exception(exc)
|
handle_exception(exc)
|
||||||
@context.workspace.local_variable_set(:_, exc)
|
@context.workspace.local_variable_set(:_, exc)
|
||||||
exc = nil
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate_line(line, line_no, exception: nil)
|
def evaluate_line(line, line_no)
|
||||||
# Transform a non-identifier alias (@, $) or keywords (next, break)
|
# Transform a non-identifier alias (@, $) or keywords (next, break)
|
||||||
command, args = line.split(/\s/, 2)
|
command, args = line.split(/\s/, 2)
|
||||||
if original = @context.command_aliases[command.to_sym]
|
if original = @context.command_aliases[command.to_sym]
|
||||||
@ -618,7 +611,7 @@ module IRB
|
|||||||
line = "#{command} #{command_class.transform_args(args)}"
|
line = "#{command} #{command_class.transform_args(args)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@context.evaluate(line, line_no, exception: exception)
|
@context.evaluate(line, line_no)
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_invalid_byte_sequence(str, enc)
|
def convert_invalid_byte_sequence(str, enc)
|
||||||
|
@ -473,15 +473,8 @@ module IRB
|
|||||||
@inspect_mode
|
@inspect_mode
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(line, line_no, exception: nil) # :nodoc:
|
def evaluate(line, line_no) # :nodoc:
|
||||||
@line_no = line_no
|
@line_no = line_no
|
||||||
|
|
||||||
if exception
|
|
||||||
line_no -= 1
|
|
||||||
line = "begin ::Kernel.raise _; rescue _.class\n#{line}\n""end"
|
|
||||||
@workspace.local_variable_set(:_, exception)
|
|
||||||
end
|
|
||||||
|
|
||||||
set_last_value(@workspace.evaluate(line, irb_path, line_no))
|
set_last_value(@workspace.evaluate(line, irb_path, line_no))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,20 +37,6 @@ module TestIRB
|
|||||||
assert_same(obj, @context.evaluate('_', 1))
|
assert_same(obj, @context.evaluate('_', 1))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_evaluate_with_exception
|
|
||||||
assert_nil(@context.evaluate("$!", 1))
|
|
||||||
e = assert_raise_with_message(RuntimeError, 'foo') {
|
|
||||||
@context.evaluate("raise 'foo'", 1)
|
|
||||||
}
|
|
||||||
assert_equal('foo', e.message)
|
|
||||||
assert_same(e, @context.evaluate('$!', 1, exception: e))
|
|
||||||
e = assert_raise(SyntaxError) {
|
|
||||||
@context.evaluate("1,2,3", 1, exception: e)
|
|
||||||
}
|
|
||||||
assert_match(/\A\(irb\):1:/, e.message)
|
|
||||||
assert_not_match(/rescue _\.class/, e.message)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_evaluate_with_encoding_error_without_lineno
|
def test_evaluate_with_encoding_error_without_lineno
|
||||||
assert_raise_with_message(EncodingError, /invalid symbol/) {
|
assert_raise_with_message(EncodingError, /invalid symbol/) {
|
||||||
@context.evaluate(%q[:"\xAE"], 1)
|
@context.evaluate(%q[:"\xAE"], 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user