Skip to content

Commit

Permalink
Avoid anonymous eval
Browse files Browse the repository at this point in the history
This makes it hard to track down the source of allocations
and such when profiling.
  • Loading branch information
byroot committed Jan 11, 2023
1 parent e553b3f commit 1c1770d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/execjs/external_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ def initialize(options)
@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

Expand Down Expand Up @@ -143,15 +149,6 @@ def locate_executable(command)
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")
Expand Down

0 comments on commit 1c1770d

Please sign in to comment.