mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Allow for runtime specific option flags
This commit is contained in:
parent
b4fdd58cea
commit
0539b906aa
8 changed files with 29 additions and 20 deletions
|
@ -6,15 +6,15 @@ module ExecJS
|
|||
"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
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require "json"
|
|||
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
|
||||
|
|
|
@ -4,7 +4,7 @@ require "execjs/runtime"
|
|||
module ExecJS
|
||||
class ExternalRuntime < Runtime
|
||||
class Context < Runtime::Context
|
||||
def initialize(runtime, source = "")
|
||||
def initialize(runtime, source = "", options = {})
|
||||
source = encode(source)
|
||||
|
||||
@runtime = runtime
|
||||
|
|
|
@ -15,16 +15,16 @@ module ExecJS
|
|||
@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
|
||||
|
|
|
@ -3,7 +3,7 @@ require "execjs/runtime"
|
|||
module ExecJS
|
||||
class RubyRacerRuntime < Runtime
|
||||
class Context < Runtime::Context
|
||||
def initialize(runtime, source = "")
|
||||
def initialize(runtime, source = "", options = {})
|
||||
source = encode(source)
|
||||
|
||||
lock do
|
||||
|
|
|
@ -3,7 +3,7 @@ require "execjs/runtime"
|
|||
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
|
||||
|
|
|
@ -6,7 +6,7 @@ module ExecJS
|
|||
class Context
|
||||
include Encoding
|
||||
|
||||
def initialize(runtime, source = "")
|
||||
def initialize(runtime, source = "", options = {})
|
||||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
|
@ -30,18 +30,18 @@ module ExecJS
|
|||
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?
|
||||
|
|
|
@ -139,6 +139,15 @@ class TestExecJS < Test
|
|||
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(" ")
|
||||
|
|
Loading…
Reference in a new issue