mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #2519 from SatoshiOdawara/fix_context_of_eval
fixed evaluation context of eval(string) and instance_eval(string)
This commit is contained in:
@@ -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);
|
||||
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->mid = mrb->c->ci[-1].mid;
|
||||
e->cioff = mrb->c->ci - mrb->c->cibase - 1;
|
||||
|
||||
@@ -60,3 +60,16 @@ assert('String instance_eval') do
|
||||
assert_equal('test') { obj.instance_eval('@test') }
|
||||
assert_equal('test') { obj.instance_eval { @test } }
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user