From 1c1770d8b0a959b22bd514fd31bf227827aaf4b0 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 11 Jan 2023 12:59:15 +0100 Subject: [PATCH] Avoid anonymous eval This makes it hard to track down the source of allocations and such when profiling. --- lib/execjs/external_runtime.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index 164587c..8e49a25 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -103,7 +103,13 @@ module ExecJS @popen_options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8' if @runner_path - instance_eval generate_compile_method(@runner_path) + instance_eval <<~RUBY, __FILE__, __LINE__ + def compile_source(source) + <<-RUNNER + #{IO.read(@runner_path)} + RUNNER + end + RUBY end end @@ -143,15 +149,6 @@ module ExecJS end protected - def generate_compile_method(path) - <<-RUBY - def compile_source(source) - <<-RUNNER - #{IO.read(path)} - RUNNER - end - RUBY - end def json2_source @json2_source ||= IO.read(ExecJS.root + "/support/json2.js")