diff options
author | Koichi Sasada <[email protected]> | 2022-07-29 16:02:10 +0900 |
---|---|---|
committer | Koichi Sasada <[email protected]> | 2022-08-01 17:48:05 +0900 |
commit | 5bbba76489628f4509495ebf4ba0a7aad4c0b560 (patch) | |
tree | 10cdc8fb1474b43122a132501feb05f4032ec271 /vm_eval.c | |
parent | 1520936aa760e6b2747d31c37854f22a63591667 (diff) |
respect current frame of `rb_eval_string`
`self` is nearest Ruby method's `self`.
If there is no ruby frame, use toplevel `self` (`main`).
https://bugs.ruby-lang.org/issues/18780
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6199
Diffstat (limited to 'vm_eval.c')
-rw-r--r-- | vm_eval.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -1828,7 +1828,10 @@ VALUE ruby_eval_string_from_file(const char *str, const char *filename) { VALUE file = filename ? rb_str_new_cstr(filename) : 0; - return eval_string_with_cref(rb_vm_top_self(), rb_str_new2(str), NULL, file, 1); + rb_execution_context_t *ec = GET_EC(); + rb_control_frame_t *cfp = ec ? rb_vm_get_ruby_level_next_cfp(ec, ec->cfp) : NULL; + VALUE self = cfp ? cfp->self : rb_vm_top_self(); + return eval_string_with_cref(self, rb_str_new2(str), NULL, file, 1); } VALUE |