lib/covered/source.rb in covered-0.10.5 vs lib/covered/source.rb in covered-0.11.0
- old
+ new
@@ -16,15 +16,13 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
-require_relative 'eval'
require_relative 'wrapper'
require 'thread'
-
require 'parser/current'
module Covered
# The source map, loads the source file, parses the AST to generate which lines contain executable code.
class Source < Wrapper
@@ -33,32 +31,36 @@
@paths = {}
@mutex = Mutex.new
@annotations = {}
+
+ begin
+ @trace = TracePoint.new(:script_compiled) do |event|
+ if path = event.instruction_sequence&.path and source = event.eval_script
+ @mutex.synchronize do
+ @paths[path] = source
+ end
+ end
+ end
+ rescue ArgumentError
+ @trace = nil
+ end
end
def enable
super
- Eval::enable(self)
+ @trace&.enable
end
def disable
- Eval::disable(self)
+ @trace&.disable
super
end
attr :paths
-
- def intercept_eval(string, binding = nil, filename = nil, lineno = 1)
- return unless filename
-
- @mutex.synchronize do
- @paths[filename] = string
- end
- end
def executable?(node)
node.type == :send
end