summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-09-17 20:19:57 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-09-22 22:19:12 +1200
commit9434a7333c2a23c680a977331a60ca7c502c1ac0 (patch)
treea0715dd55cdab3816b7065a56815017d2d0139c6 /iseq.c
parent4c37eaa979d89be14c2142659daba0588aa64912 (diff)
downloadruby-9434a7333c2a23c680a977331a60ca7c502c1ac0.tar.gz
Enable coverage for eval.
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/iseq.c b/iseq.c
index 4892d93df1..9359fcfe4e 100644
--- a/iseq.c
+++ b/iseq.c
@@ -697,7 +697,6 @@ prepare_iseq_build(rb_iseq_t *iseq,
ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = NULL;
ISEQ_COMPILE_DATA(iseq)->builtin_function_table = GET_VM()->builtin_function_table;
-
if (option->coverage_enabled) {
VALUE coverages = rb_get_coverages();
if (RTEST(coverages)) {
@@ -928,6 +927,18 @@ rb_iseq_new_main(const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_
rb_iseq_t *
rb_iseq_new_eval(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, int isolated_depth)
{
+ VALUE coverages = rb_get_coverages();
+ if (RTEST(coverages) && RTEST(path) && !RTEST(rb_hash_has_key(coverages, path))) {
+ int line_offset = RB_NUM2INT(first_lineno) - 1;
+ int line_count = line_offset + ast_line_count(ast);
+
+ if (line_count >= 0) {
+ int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count;
+ VALUE coverage = rb_default_coverage(len);
+ rb_hash_aset(coverages, path, coverage);
+ }
+ }
+
return rb_iseq_new_with_opt(ast, name, path, realpath, first_lineno,
parent, isolated_depth, ISEQ_TYPE_EVAL, &COMPILE_OPTION_DEFAULT);
}