Skip to content

Commit

Permalink
Allow for runtime specific option flags
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 12, 2016
1 parent b4fdd58 commit 0539b90
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 20 deletions.
6 changes: 3 additions & 3 deletions lib/execjs/disabled_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/execjs/duktape_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/execjs/external_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/execjs/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/execjs/ruby_racer_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/execjs/ruby_rhino_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/execjs/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Runtime
class Context
include Encoding

def initialize(runtime, source = "")
def initialize(runtime, source = "", options = {})
end

def exec(source, options = {})
Expand All @@ -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?
Expand Down
9 changes: 9 additions & 0 deletions test/test_execjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")
Expand Down

0 comments on commit 0539b90

Please sign in to comment.