Skip to content
Browse files

Remove pure evaluation

  • Loading branch information...
1 parent 8f1587f commit c595c079cea689aa12313de0c51d422540682b24 @josh josh committed Mar 10, 2011
Showing with 17 additions and 39 deletions.
  1. +7 −22 lib/execjs/external_runtime.rb
  2. +5 −6 lib/execjs/ruby_racer_runtime.rb
  3. +5 −6 lib/execjs/ruby_rhino_runtime.rb
  4. +0 −5 test/test_execjs.rb
View
29 lib/execjs/external_runtime.rb
@@ -4,15 +4,9 @@
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 @@ def eval(source, options = {})
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 @@ def initialize(options)
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?
View
11 lib/execjs/ruby_racer_runtime.rb
@@ -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 @@ def name
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?
View
11 lib/execjs/ruby_rhino_runtime.rb
@@ -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 @@ def name
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?
View
5 test/test_execjs.rb
@@ -24,11 +24,6 @@ def test_compile
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")

0 comments on commit c595c07

Please sign in to comment.
Something went wrong with that request. Please try again.