1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* vm_eval.c (rb_f_caller): return [] instead of nil when the function

is called on toplevel.  [ruby-dev:41348]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2010-05-19 11:18:12 +00:00
parent 61086883b6
commit 56036e3514
3 changed files with 13 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Wed May 19 20:09:38 2010 Yusuke Endoh <mame@tsg.ne.jp>
* vm_eval.c (rb_f_caller): return [] instead of nil when the function
is called on toplevel. [ruby-dev:41348]
Wed May 19 19:58:01 2010 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/socket/extconf.rb: mswin/mingw ruby has socketpair(), but it's

View file

@ -228,6 +228,10 @@ class TestMethod < Test::Unit::TestCase
assert_in_out_err([], "p __callee__", %w(nil), [])
end
def test_caller_top_level
assert_in_out_err([], "p caller", %w([]), [])
end
def test_caller_negative_level
assert_raise(ArgumentError) { caller(-1) }
end

View file

@ -1562,7 +1562,7 @@ rb_catch_obj(VALUE tag, VALUE (*func)(), VALUE data)
static VALUE
rb_f_caller(int argc, VALUE *argv)
{
VALUE level;
VALUE level, ary;
int lev;
rb_scan_args(argc, argv, "01", &level);
@ -1574,7 +1574,9 @@ rb_f_caller(int argc, VALUE *argv)
if (lev < 0)
rb_raise(rb_eArgError, "negative level (%d)", lev);
return vm_backtrace(GET_THREAD(), lev);
ary = vm_backtrace(GET_THREAD(), lev);
if (NIL_P(ary)) ary = rb_ary_new();
return ary;
}
static int