mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix TAG_THROW through require [Bug #18562]
Previously this was being incorrectly swapped with TAG_RAISE in the next line. This would end up checking the T_IMEMO throw_data to the exception handling (which calls Module#===). This happened to not break existing tests because Module#=== returned false when klass is NULL. This commit handles throw from require correctly by jumping to the tag retaining the TAG_THROW state.
This commit is contained in:
parent
3e6c6c74dd
commit
c79d2e5474
Notes:
git
2022-02-06 11:10:47 +09:00
2 changed files with 22 additions and 1 deletions
2
load.c
2
load.c
|
@ -1155,7 +1155,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
|
|||
if (ftptr) load_unlock(th2->vm, RSTRING_PTR(path), !state);
|
||||
|
||||
if (state) {
|
||||
if (state == TAG_FATAL) {
|
||||
if (state == TAG_FATAL || state == TAG_THROW) {
|
||||
EC_JUMP_TAG(ec, state);
|
||||
}
|
||||
else if (exception) {
|
||||
|
|
|
@ -252,6 +252,27 @@ class TestException < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_catch_throw_in_require_cant_be_rescued
|
||||
bug18562 = '[ruby-core:107403]'
|
||||
Tempfile.create(["dep", ".rb"]) {|t|
|
||||
t.puts("throw :extdep, 42")
|
||||
t.close
|
||||
|
||||
rescue_all = Class.new(Exception)
|
||||
def rescue_all.===(_)
|
||||
raise "should not reach here"
|
||||
end
|
||||
|
||||
v = assert_throw(:extdep, bug18562) do
|
||||
require t.path
|
||||
rescue rescue_all => e
|
||||
assert(false, "should not reach here")
|
||||
end
|
||||
|
||||
assert_equal(42, v, bug18562)
|
||||
}
|
||||
end
|
||||
|
||||
def test_throw_false
|
||||
bug12743 = '[ruby-core:77229] [Bug #12743]'
|
||||
Thread.start {
|
||||
|
|
Loading…
Reference in a new issue