diff --git a/lib/execjs/runtime.rb b/lib/execjs/runtime.rb index ed06857..eba424c 100644 --- a/lib/execjs/runtime.rb +++ b/lib/execjs/runtime.rb @@ -31,17 +31,31 @@ module ExecJS 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?