diff --git a/lib/execjs/disabled_runtime.rb b/lib/execjs/disabled_runtime.rb index dc67e82..86e6a6c 100644 --- a/lib/execjs/disabled_runtime.rb +++ b/lib/execjs/disabled_runtime.rb @@ -6,15 +6,15 @@ def name "Disabled" end - def exec(source) + def exec(source, options = {}) raise Error, "ExecJS disabled" end - def eval(source) + def eval(source, options = {}) raise Error, "ExecJS disabled" end - def compile(source) + def compile(source, options = {}) raise Error, "ExecJS disabled" end diff --git a/lib/execjs/duktape_runtime.rb b/lib/execjs/duktape_runtime.rb index cfbc7f9..8ae42a5 100644 --- a/lib/execjs/duktape_runtime.rb +++ b/lib/execjs/duktape_runtime.rb @@ -4,7 +4,7 @@ module ExecJS class DuktapeRuntime < Runtime class Context < Runtime::Context - def initialize(runtime, source = "") + def initialize(runtime, source = "", options = {}) @ctx = Duktape::Context.new(complex_object: nil) @ctx.exec_string(encode(source), '(execjs)') rescue Exception => e diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index 2133ce3..9a4b493 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -4,7 +4,7 @@ module ExecJS class ExternalRuntime < Runtime class Context < Runtime::Context - def initialize(runtime, source = "") + def initialize(runtime, source = "", options = {}) source = encode(source) @runtime = runtime diff --git a/lib/execjs/module.rb b/lib/execjs/module.rb index 8b2566a..b89dc22 100644 --- a/lib/execjs/module.rb +++ b/lib/execjs/module.rb @@ -15,16 +15,16 @@ def runtime=(runtime) @runtime = runtime end - def exec(source) - runtime.exec(source) + def exec(source, options = {}) + runtime.exec(source, options) end - def eval(source) - runtime.eval(source) + def eval(source, options = {}) + runtime.eval(source, options) end - def compile(source) - runtime.compile(source) + def compile(source, options = {}) + runtime.compile(source, options) end def root diff --git a/lib/execjs/ruby_racer_runtime.rb b/lib/execjs/ruby_racer_runtime.rb index eee99fb..cf8e1a2 100644 --- a/lib/execjs/ruby_racer_runtime.rb +++ b/lib/execjs/ruby_racer_runtime.rb @@ -3,7 +3,7 @@ module ExecJS class RubyRacerRuntime < Runtime class Context < Runtime::Context - def initialize(runtime, source = "") + def initialize(runtime, source = "", options = {}) source = encode(source) lock do diff --git a/lib/execjs/ruby_rhino_runtime.rb b/lib/execjs/ruby_rhino_runtime.rb index 13b7b3b..684d6cc 100644 --- a/lib/execjs/ruby_rhino_runtime.rb +++ b/lib/execjs/ruby_rhino_runtime.rb @@ -3,7 +3,7 @@ module ExecJS class RubyRhinoRuntime < Runtime class Context < Runtime::Context - def initialize(runtime, source = "") + def initialize(runtime, source = "", options = {}) source = encode(source) @rhino_context = ::Rhino::Context.new diff --git a/lib/execjs/runtime.rb b/lib/execjs/runtime.rb index f64b67f..ed06857 100644 --- a/lib/execjs/runtime.rb +++ b/lib/execjs/runtime.rb @@ -6,7 +6,7 @@ class Runtime class Context include Encoding - def initialize(runtime, source = "") + def initialize(runtime, source = "", options = {}) end def exec(source, options = {}) @@ -30,18 +30,18 @@ def context_class self.class::Context end - def exec(source) + def exec(source, options = {}) context = context_class.new(self) - context.exec(source) + context.exec(source, options) end - def eval(source) + def eval(source, options = {}) context = context_class.new(self) - context.eval(source) + context.eval(source, options) end - def compile(source) - context_class.new(self, source) + def compile(source, options = {}) + context_class.new(self, source, options) end def deprecated? diff --git a/test/test_execjs.rb b/test/test_execjs.rb index fb44350..7fd967f 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -139,6 +139,15 @@ def test_context_call_missing_function end end + def test_additional_options + assert ExecJS.eval("true", :foo => true) + assert ExecJS.exec("return true", :foo => true) + + context = ExecJS.compile("foo = true", :foo => true) + assert context.eval("foo", :foo => true) + assert context.exec("return foo", :foo => true) + end + def test_eval_blank assert_nil ExecJS.eval("") assert_nil ExecJS.eval(" ")