зеркало из https://github.com/github/ruby.git
merge revision(s) 6ade36c06b7cef948099b8f5f483763498705d12: [Backport #20414]
`Fiber#raise` recursively raises on nested resuming_fiber. (#10482) * Improve consistency of `Fiber.current.raise`.
This commit is contained in:
Родитель
b44c02ad5a
Коммит
5c06e93074
8
cont.c
8
cont.c
|
@ -3223,7 +3223,13 @@ rb_fiber_s_yield(int argc, VALUE *argv, VALUE klass)
|
|||
static VALUE
|
||||
fiber_raise(rb_fiber_t *fiber, VALUE exception)
|
||||
{
|
||||
if (FIBER_SUSPENDED_P(fiber) && !fiber->yielding) {
|
||||
if (fiber == fiber_current()) {
|
||||
rb_exc_raise(exception);
|
||||
}
|
||||
else if (fiber->resuming_fiber) {
|
||||
return fiber_raise(fiber->resuming_fiber, exception);
|
||||
}
|
||||
else if (FIBER_SUSPENDED_P(fiber) && !fiber->yielding) {
|
||||
return fiber_transfer_kw(fiber, -1, &exception, RB_NO_KEYWORDS);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -91,6 +91,40 @@ describe "Fiber#raise" do
|
|||
|
||||
fiber_two.resume.should == [:yield_one, :rescued]
|
||||
end
|
||||
|
||||
ruby_version_is "3.4" do
|
||||
it "raises on the resumed fiber" do
|
||||
root_fiber = Fiber.current
|
||||
f1 = Fiber.new { root_fiber.transfer }
|
||||
f2 = Fiber.new { f1.resume }
|
||||
f2.transfer
|
||||
|
||||
-> do
|
||||
f2.raise(RuntimeError, "Expected error")
|
||||
end.should raise_error(RuntimeError, "Expected error")
|
||||
end
|
||||
|
||||
it "raises on itself" do
|
||||
-> do
|
||||
Fiber.current.raise(RuntimeError, "Expected error")
|
||||
end.should raise_error(RuntimeError, "Expected error")
|
||||
end
|
||||
|
||||
it "should raise on parent fiber" do
|
||||
f2 = nil
|
||||
f1 = Fiber.new do
|
||||
# This is equivalent to Kernel#raise:
|
||||
f2.raise(RuntimeError, "Expected error")
|
||||
end
|
||||
f2 = Fiber.new do
|
||||
f1.resume
|
||||
end
|
||||
|
||||
-> do
|
||||
f2.resume
|
||||
end.should raise_error(RuntimeError, "Expected error")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||
#define RUBY_VERSION_TEENY 1
|
||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||
#define RUBY_PATCHLEVEL 70
|
||||
#define RUBY_PATCHLEVEL 71
|
||||
|
||||
#include "ruby/version.h"
|
||||
#include "ruby/internal/abi.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче