From 24d0454d6d05fc3b2c6a952a9d48574199b85815 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 11 Apr 2016 21:49:10 -0700 Subject: [PATCH] Check arity to support existing runtime classes --- lib/execjs/runtime.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) 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?