From c182903ea0ee5c904725f336373f608962059996 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 26 Jun 2021 10:52:56 +0900 Subject: Fixed finding variables from `proc` in `binding.eval` failed Previously the following code did not produce the expected results: ```ruby bx = binding block = bx.eval("a = 1; proc { a }") bx.eval("a = 2") p block.call # Expect 2 but return 1 due to a bug ``` The previous implementation of `Binding#eval` evaluated the code and then merged the top layer variables. This patch will parse and expand the variable space before making a call to `eval`. This means that the call to `Binding#eval` will do the parsing twice. In addition, the following changes will be made: - Make `mrb_parser_foreach_top_variable()`, `mrb_binding_extract_proc()` and `mrb_binding_extract_env()` functions private global functions. - Remove the `posthook` argument from `mrb_exec_irep()`. The `posthook` argument was introduced to implement the `binding` method. This patch is unnecessary because it uses a different implementation method. ref #5362 fixed #5491 --- mrbgems/mruby-method/src/method.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mrbgems/mruby-method') diff --git a/mrbgems/mruby-method/src/method.c b/mrbgems/mruby-method/src/method.c index 7410f007e..02131050d 100644 --- a/mrbgems/mruby-method/src/method.c +++ b/mrbgems/mruby-method/src/method.c @@ -7,7 +7,7 @@ #include "mruby/presym.h" mrb_noreturn void mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args); -mrb_value mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p, mrb_func_t posthook); +mrb_value mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p); static mrb_value args_shift(mrb_state *mrb) @@ -242,7 +242,7 @@ mcall(mrb_state *mrb, mrb_value self, mrb_value recv) mrb->c->ci->mid = mid; mrb->c->ci->u.target_class = tc; - return mrb_exec_irep(mrb, recv, proc, NULL); + return mrb_exec_irep(mrb, recv, proc); } static mrb_value -- cgit v1.2.3