mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
eval.c: copy before cause setup
* eval.c (setup_exception): copy frozen exception before setting up a cause not only a backtrace. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e601e77590
commit
61ea519dc0
2 changed files with 22 additions and 11 deletions
26
eval.c
26
eval.c
|
@ -481,18 +481,17 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
|
||||||
mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
|
mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
|
||||||
nocause = 0;
|
nocause = 0;
|
||||||
}
|
}
|
||||||
if (cause != Qundef) {
|
if (cause == Qundef) {
|
||||||
exc_setup_cause(mesg, cause);
|
if (nocause) {
|
||||||
}
|
cause = Qnil;
|
||||||
else if (nocause) {
|
}
|
||||||
exc_setup_cause(mesg, Qnil);
|
else if (!rb_ivar_defined(mesg, id_cause)) {
|
||||||
}
|
cause = get_thread_errinfo(th);
|
||||||
else if (!rb_ivar_defined(mesg, id_cause)) {
|
}
|
||||||
exc_setup_cause(mesg, get_thread_errinfo(th));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file = rb_source_loc(&line);
|
file = rb_source_loc(&line);
|
||||||
if (file && !NIL_P(mesg)) {
|
if ((file && !NIL_P(mesg)) || (cause != Qundef)) {
|
||||||
VALUE at;
|
VALUE at;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
@ -501,11 +500,16 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
|
||||||
VALUE bt;
|
VALUE bt;
|
||||||
if (rb_threadptr_set_raised(th)) goto fatal;
|
if (rb_threadptr_set_raised(th)) goto fatal;
|
||||||
bt = rb_get_backtrace(mesg);
|
bt = rb_get_backtrace(mesg);
|
||||||
if (NIL_P(bt)) {
|
if (!NIL_P(bt) || cause == Qundef) {
|
||||||
at = rb_threadptr_backtrace_object(th);
|
|
||||||
if (OBJ_FROZEN(mesg)) {
|
if (OBJ_FROZEN(mesg)) {
|
||||||
mesg = rb_obj_dup(mesg);
|
mesg = rb_obj_dup(mesg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (cause != Qundef) {
|
||||||
|
exc_setup_cause(mesg, cause);
|
||||||
|
}
|
||||||
|
if (NIL_P(bt)) {
|
||||||
|
at = rb_threadptr_backtrace_object(th);
|
||||||
rb_ivar_set(mesg, idBt_locations, at);
|
rb_ivar_set(mesg, idBt_locations, at);
|
||||||
set_backtrace(mesg, at);
|
set_backtrace(mesg, at);
|
||||||
}
|
}
|
||||||
|
|
|
@ -799,6 +799,13 @@ end.join
|
||||||
assert_nil(orig_error.cause, bug13043)
|
assert_nil(orig_error.cause, bug13043)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_cause_with_frozen_exception
|
||||||
|
exc = ArgumentError.new("foo").freeze
|
||||||
|
assert_raise_with_message(ArgumentError, exc.message) {
|
||||||
|
raise exc, cause: RuntimeError.new("bar")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_anonymous_message
|
def test_anonymous_message
|
||||||
assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/)
|
assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue