mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-eval: fixed receiver value in eval context; close #3072
This commit is contained in:
@@ -130,8 +130,10 @@ patch_irep(mrb_state *mrb, mrb_irep *irep, int bnest)
|
||||
}
|
||||
}
|
||||
|
||||
void mrb_codedump_all(mrb_state*, struct RProc*);
|
||||
|
||||
static struct RProc*
|
||||
create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, char *file, mrb_int line)
|
||||
create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, char *file, mrb_int line, mrb_bool nest)
|
||||
{
|
||||
mrbc_context *cxt;
|
||||
struct mrb_parser_state *p;
|
||||
@@ -150,7 +152,6 @@ create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, cha
|
||||
}
|
||||
cxt->capture_errors = TRUE;
|
||||
cxt->no_optimize = TRUE;
|
||||
// cxt->dump_result = TRUE;
|
||||
|
||||
p = mrb_parse_nstring(mrb, s, len, cxt);
|
||||
|
||||
@@ -184,7 +185,12 @@ create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, cha
|
||||
e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass*)e);
|
||||
e->mid = c->ci[-1].mid;
|
||||
e->cioff = c->ci - c->cibase - 1;
|
||||
e->stack = c->ci->stackent;
|
||||
if (nest) {
|
||||
e->stack = c->stack;
|
||||
}
|
||||
else {
|
||||
e->stack = c->ci->stackent;
|
||||
}
|
||||
MRB_SET_ENV_STACK_LEN(e, c->ci[-1].proc->body.irep->nlocals);
|
||||
c->ci->env = e;
|
||||
proc->env = e;
|
||||
@@ -209,8 +215,8 @@ f_eval(mrb_state *mrb, mrb_value self)
|
||||
|
||||
mrb_get_args(mrb, "s|ozi", &s, &len, &binding, &file, &line);
|
||||
|
||||
proc = create_proc_from_string(mrb, s, len, binding, file, line);
|
||||
ret = mrb_toplevel_run(mrb, proc);
|
||||
proc = create_proc_from_string(mrb, s, len, binding, file, line, FALSE);
|
||||
ret = mrb_top_run(mrb, proc, mrb->c->stack[0], 0);
|
||||
if (mrb->exc) {
|
||||
mrb_exc_raise(mrb, mrb_obj_value(mrb->exc));
|
||||
}
|
||||
@@ -237,12 +243,14 @@ f_instance_eval(mrb_state *mrb, mrb_value self)
|
||||
char *file = NULL;
|
||||
mrb_int line = 1;
|
||||
mrb_value cv;
|
||||
struct RProc *proc;
|
||||
|
||||
mrb_get_args(mrb, "s|zi", &s, &len, &file, &line);
|
||||
c->ci->acc = CI_ACC_SKIP;
|
||||
cv = mrb_singleton_class(mrb, self);
|
||||
c->ci->target_class = mrb_class_ptr(cv);
|
||||
return mrb_run(mrb, create_proc_from_string(mrb, s, len, mrb_nil_value(), file, line), self);
|
||||
proc = create_proc_from_string(mrb, s, len, mrb_nil_value(), file, line, TRUE);
|
||||
return mrb_run(mrb, proc, self);
|
||||
}
|
||||
else {
|
||||
mrb_get_args(mrb, "&", &b);
|
||||
|
||||
Reference in New Issue
Block a user