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:
parent
0539b906aa
commit
24d0454d6d
1 changed files with 19 additions and 5 deletions
|
@ -31,17 +31,31 @@ module ExecJS
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec(source, options = {})
|
def exec(source, options = {})
|
||||||
context = context_class.new(self)
|
context = compile("", options)
|
||||||
context.exec(source, options)
|
|
||||||
|
if context.method(:exec).arity == 1
|
||||||
|
context.exec(source)
|
||||||
|
else
|
||||||
|
context.exec(source, options)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def eval(source, options = {})
|
def eval(source, options = {})
|
||||||
context = context_class.new(self)
|
context = compile("", options)
|
||||||
context.eval(source, options)
|
|
||||||
|
if context.method(:eval).arity == 1
|
||||||
|
context.eval(source)
|
||||||
|
else
|
||||||
|
context.eval(source, options)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile(source, options = {})
|
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
|
end
|
||||||
|
|
||||||
def deprecated?
|
def deprecated?
|
||||||
|
|
Loading…
Reference in a new issue