1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Check arity to support existing runtime classes

This commit is contained in:
Joshua Peek 2016-04-11 21:49:10 -07:00
parent 0539b906aa
commit 24d0454d6d
No known key found for this signature in database
GPG key ID: 2852ABCC729F67DA

View file

@ -31,18 +31,32 @@ module ExecJS
end end
def exec(source, options = {}) def exec(source, options = {})
context = context_class.new(self) context = compile("", options)
if context.method(:exec).arity == 1
context.exec(source)
else
context.exec(source, options) context.exec(source, options)
end end
end
def eval(source, options = {}) def eval(source, options = {})
context = context_class.new(self) context = compile("", options)
if context.method(:eval).arity == 1
context.eval(source)
else
context.eval(source, options) context.eval(source, options)
end end
end
def compile(source, options = {}) def compile(source, options = {})
if context_class.instance_method(:initialize).arity == 2
context_class.new(self, source)
else
context_class.new(self, source, options) context_class.new(self, source, options)
end end
end
def deprecated? def deprecated?
false false