Commit 432e8e9e authored by Satoshi Odawara's avatar Satoshi Odawara

fixed evaluation context of eval(string) and instance_eval(string)

parent 569c7dec
...@@ -132,6 +132,9 @@ create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, cha ...@@ -132,6 +132,9 @@ create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, cha
} }
proc = mrb_generate_code(mrb, p); proc = mrb_generate_code(mrb, p);
if (mrb->c->ci[-1].proc->target_class) {
proc->target_class = mrb->c->ci[-1].proc->target_class;
}
e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass*)mrb->c->ci[-1].proc->env); e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass*)mrb->c->ci[-1].proc->env);
e->mid = mrb->c->ci[-1].mid; e->mid = mrb->c->ci[-1].mid;
e->cioff = mrb->c->ci - mrb->c->cibase - 1; e->cioff = mrb->c->ci - mrb->c->cibase - 1;
......
...@@ -60,3 +60,16 @@ assert('String instance_eval') do ...@@ -60,3 +60,16 @@ assert('String instance_eval') do
assert_equal('test') { obj.instance_eval('@test') } assert_equal('test') { obj.instance_eval('@test') }
assert_equal('test') { obj.instance_eval { @test } } assert_equal('test') { obj.instance_eval { @test } }
end end
assert('Kernel.#eval(string) context') do
class TestEvalConstScope
EVAL_CONST_CLASS = 'class'
def const_string
eval 'EVAL_CONST_CLASS'
end
end
obj = TestEvalConstScope.new
assert_raise(NameError) { eval 'EVAL_CONST_CLASS' }
assert_equal('class') { obj.const_string }
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment