Skip to content

Commit

Permalink
Check arity to support existing runtime classes
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 12, 2016
1 parent 0539b90 commit 24d0454
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/execjs/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,31 @@ def context_class
end

def exec(source, options = {})
context = context_class.new(self)
context.exec(source, options)
context = compile("", options)

if context.method(:exec).arity == 1
context.exec(source)
else
context.exec(source, options)
end
end

def eval(source, options = {})
context = context_class.new(self)
context.eval(source, options)
context = compile("", options)

if context.method(:eval).arity == 1
context.eval(source)
else
context.eval(source, options)
end
end

def compile(source, options = {})
context_class.new(self, source, options)
if context_class.instance_method(:initialize).arity == 2
context_class.new(self, source)
else
context_class.new(self, source, options)
end
end

def deprecated?
Expand Down

0 comments on commit 24d0454

Please sign in to comment.