aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_method.rb4
-rw-r--r--vm_eval.c6
3 files changed, 13 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a0b034d96..82cff7e61f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index ddeb6d6c87..86ab64feb1 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -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
diff --git a/vm_eval.c b/vm_eval.c
index 2bf640d978..d1e6352e03 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -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