Class: Evilution::Integration::Loading::SourceEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/integration/loading/source_evaluator.rb

Overview

Evaluate source with __FILE__ set to the absolute original path so that ‘require_relative` and `__dir__` resolve against the real source tree, where sibling files actually exist.

Trust boundary: ‘source` is never user-supplied. It is always the original on-disk source from a file the user already pointed Evilution at, with byte-level mutations applied by AST::SourceSurgeon. The only difference between this eval path and a plain `require` of the same file is that we substitute the mutated bytes — the privilege level is identical.

Instance Method Summary collapse

Instance Method Details

#call(source, file_path) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/evilution/integration/loading/source_evaluator.rb', line 15

def call(source, file_path)
  # When the isolator has chdir'd into a per-mutation sandbox (EV-wqxu /
  # GH #1278), anchor the eval __FILE__ against PROJECT_ROOT so siblings
  # `require_relative` can find each other from the real source tree.
  base = Evilution.in_isolated_worker? ? Evilution::PROJECT_ROOT : Dir.pwd
  absolute = File.expand_path(file_path, base)
  eval(source, TOPLEVEL_BINDING, absolute, 1)
end