eval.c: pass unknown options
* eval.c (extract_raise_opts): pass unknown options to the exception, so that exception class can receive a hash argument. [ruby-core:63203] [Feature #8257] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b905ac81a0
commit
d689dca633
@ -1,3 +1,9 @@
|
|||||||
|
Tue Jun 17 12:35:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* eval.c (extract_raise_opts): pass unknown options to the
|
||||||
|
exception, so that exception class can receive a hash argument.
|
||||||
|
[ruby-core:63203] [Feature #8257]
|
||||||
|
|
||||||
Tue Jun 17 12:24:57 2014 Koichi Sasada <ko1@atdot.net>
|
Tue Jun 17 12:24:57 2014 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* gc.c (obj_memsize_of): memsize_of(T_ZOMBIE) returns 0, not a rb_bug.
|
* gc.c (obj_memsize_of): memsize_of(T_ZOMBIE) returns 0, not a rb_bug.
|
||||||
|
7
eval.c
7
eval.c
@ -606,12 +606,11 @@ extract_raise_opts(int argc, VALUE *argv, VALUE *opts)
|
|||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
VALUE opt = argv[argc-1];
|
VALUE opt = argv[argc-1];
|
||||||
if (RB_TYPE_P(opt, T_HASH)) {
|
if (RB_TYPE_P(opt, T_HASH)) {
|
||||||
VALUE kw = rb_extract_keywords(&opt);
|
if (!RHASH_EMPTY_P(opt)) {
|
||||||
if (!opt) --argc;
|
|
||||||
if (kw) {
|
|
||||||
ID keywords[1];
|
ID keywords[1];
|
||||||
CONST_ID(keywords[0], "cause");
|
CONST_ID(keywords[0], "cause");
|
||||||
rb_get_kwargs(kw, keywords, 0, 1, opts);
|
rb_get_kwargs(opt, keywords, 0, -1-raise_max_opt, opts);
|
||||||
|
if (RHASH_EMPTY_P(opt)) --argc;
|
||||||
return argc;
|
return argc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -596,4 +596,25 @@ end.join
|
|||||||
raise cause: cause
|
raise cause: cause
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_unknown_option
|
||||||
|
bug = '[ruby-core:63203] [Feature #8257] should pass unknown options'
|
||||||
|
|
||||||
|
exc = Class.new(RuntimeError) do
|
||||||
|
attr_reader :arg
|
||||||
|
def initialize(msg = nil)
|
||||||
|
@arg = msg
|
||||||
|
super(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar"}
|
||||||
|
assert_equal({"foo" => "bar", foo: "bar"}, e.arg, bug)
|
||||||
|
|
||||||
|
e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar", cause: "zzz"}
|
||||||
|
assert_equal({"foo" => "bar", foo: "bar"}, e.arg, bug)
|
||||||
|
|
||||||
|
e = assert_raise(exc, bug) {raise exc, {}}
|
||||||
|
assert_equal({}, e.arg, bug)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user