mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Remove pure evaluation
This commit is contained in:
parent
8f1587f15d
commit
c595c079ce
4 changed files with 17 additions and 39 deletions
|
@ -4,15 +4,9 @@ require "tempfile"
|
|||
module ExecJS
|
||||
class ExternalRuntime
|
||||
class Context
|
||||
def initialize(runtime)
|
||||
def initialize(runtime, source = "")
|
||||
@runtime = runtime
|
||||
@script = ""
|
||||
end
|
||||
|
||||
def <<(script)
|
||||
@script << script
|
||||
@script << "\n"
|
||||
self
|
||||
@source = source
|
||||
end
|
||||
|
||||
def eval(source, options = {})
|
||||
|
@ -22,20 +16,13 @@ module ExecJS
|
|||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
if options[:pure]
|
||||
source = @script + source
|
||||
else
|
||||
self << source
|
||||
source = @script
|
||||
end
|
||||
|
||||
compile_to_tempfile(source) do |file|
|
||||
compile_to_tempfile([@source, source].join("\n")) do |file|
|
||||
extract_result(@runtime.exec_runtime(file.path))
|
||||
end
|
||||
end
|
||||
|
||||
def call(properties, *args)
|
||||
eval "#{properties}.apply(this, #{args.to_json})", :pure => true
|
||||
eval "#{properties}.apply(this, #{args.to_json})"
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -81,18 +68,16 @@ module ExecJS
|
|||
|
||||
def exec(source)
|
||||
context = Context.new(self)
|
||||
context.exec(source, :pure => true)
|
||||
context.exec(source)
|
||||
end
|
||||
|
||||
def eval(source)
|
||||
context = Context.new(self)
|
||||
context.eval(source, :pure => true)
|
||||
context.eval(source)
|
||||
end
|
||||
|
||||
def compile(source)
|
||||
context = Context.new(self)
|
||||
context.exec(source)
|
||||
context
|
||||
Context.new(self, source)
|
||||
end
|
||||
|
||||
def available?
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
module ExecJS
|
||||
class RubyRacerRuntime
|
||||
class Context
|
||||
def initialize
|
||||
def initialize(source = "")
|
||||
@v8_context = ::V8::Context.new
|
||||
@v8_context.eval(source)
|
||||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
|
@ -56,18 +57,16 @@ module ExecJS
|
|||
|
||||
def exec(source)
|
||||
context = Context.new
|
||||
context.exec(source, :pure => true)
|
||||
context.exec(source)
|
||||
end
|
||||
|
||||
def eval(source)
|
||||
context = Context.new
|
||||
context.eval(source, :pure => true)
|
||||
context.eval(source)
|
||||
end
|
||||
|
||||
def compile(source)
|
||||
context = Context.new
|
||||
context.exec(source)
|
||||
context
|
||||
Context.new(source)
|
||||
end
|
||||
|
||||
def available?
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
module ExecJS
|
||||
class RubyRhinoRuntime
|
||||
class Context
|
||||
def initialize
|
||||
def initialize(source = "")
|
||||
@rhino_context = ::Rhino::Context.new
|
||||
@rhino_context.eval(source)
|
||||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
|
@ -54,18 +55,16 @@ module ExecJS
|
|||
|
||||
def exec(source)
|
||||
context = Context.new
|
||||
context.exec(source, :pure => true)
|
||||
context.exec(source)
|
||||
end
|
||||
|
||||
def eval(source)
|
||||
context = Context.new
|
||||
context.eval(source, :pure => true)
|
||||
context.eval(source)
|
||||
end
|
||||
|
||||
def compile(source)
|
||||
context = Context.new
|
||||
context.exec(source)
|
||||
context
|
||||
Context.new(source)
|
||||
end
|
||||
|
||||
def available?
|
||||
|
|
|
@ -24,11 +24,6 @@ class TestExecJS < Test::Unit::TestCase
|
|||
assert_equal "bar", context.eval("foo()")
|
||||
end
|
||||
|
||||
def test_pure_evaluation
|
||||
context = ExecJS.compile("foo = function() { return \"bar\"; }")
|
||||
assert_equal "bar", context.eval("foo()", :pure => true)
|
||||
end
|
||||
|
||||
def test_context_call
|
||||
context = ExecJS.compile("id = function(v) { return v; }")
|
||||
assert_equal "bar", context.call("id", "bar")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue