diff --git a/ChangeLog b/ChangeLog index 25bbc16510..6268bf2fa3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Oct 10 17:25:28 2013 Koichi Sasada + + * vm.c (vm_exec): support :b_return event for "lambda{return}.call". + [Bug #8622] + + * test/ruby/test_settracefunc.rb: add a test. + Thu Oct 10 13:52:37 2013 Koichi Sasada * vm_trace.c (postponed_job): use preallocated buffer. diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index 4319c8fc75..56700fc71b 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -966,4 +966,29 @@ class TestSetTraceFunc < Test::Unit::TestCase assert_equal 4, n end + + def test_tracepoint_b_return_with_lambda + n = 0 + TracePoint.new(:b_return){ + n+=1 + }.enable{ + lambda{ + return + }.call # n += 1 #=> 1 + 3.times{ + lambda{ + return # n += 3 #=> 4 + }.call + } # n += 3 #=> 7 + begin + lambda{ + raise + }.call # n += 1 #=> 8 + rescue + # ignore + end # n += 1 #=> 9 + } + + assert_equal 9, n + end end diff --git a/vm.c b/vm.c index 0ade176c42..0193b7b75a 100644 --- a/vm.c +++ b/vm.c @@ -1290,6 +1290,13 @@ vm_exec(rb_thread_t *th) if (!catch_iseqval) { result = GET_THROWOBJ_VAL(err); th->errinfo = Qnil; + + switch (VM_FRAME_TYPE(cfp)) { + case VM_FRAME_MAGIC_LAMBDA: + EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil); + break; + } + vm_pop_frame(th); goto finish_vme; } @@ -1435,6 +1442,7 @@ vm_exec(rb_thread_t *th) EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil); break; case VM_FRAME_MAGIC_BLOCK: + case VM_FRAME_MAGIC_LAMBDA: EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil); break; case VM_FRAME_MAGIC_CLASS: