Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Remove pure evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Mar 10, 2011
1 parent 8f1587f commit c595c07
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 39 deletions.
29 changes: 7 additions & 22 deletions lib/execjs/external_runtime.rb
Expand Up @@ -4,15 +4,9 @@
module ExecJS module ExecJS
class ExternalRuntime class ExternalRuntime
class Context class Context
def initialize(runtime) def initialize(runtime, source = "")
@runtime = runtime @runtime = runtime
@script = "" @source = source
end

def <<(script)
@script << script
@script << "\n"
self
end end


def eval(source, options = {}) def eval(source, options = {})
Expand All @@ -22,20 +16,13 @@ def eval(source, options = {})
end end


def exec(source, options = {}) def exec(source, options = {})
if options[:pure] compile_to_tempfile([@source, source].join("\n")) do |file|
source = @script + source
else
self << source
source = @script
end

compile_to_tempfile(source) do |file|
extract_result(@runtime.exec_runtime(file.path)) extract_result(@runtime.exec_runtime(file.path))
end end
end end


def call(properties, *args) def call(properties, *args)
eval "#{properties}.apply(this, #{args.to_json})", :pure => true eval "#{properties}.apply(this, #{args.to_json})"
end end


protected protected
Expand Down Expand Up @@ -81,18 +68,16 @@ def initialize(options)


def exec(source) def exec(source)
context = Context.new(self) context = Context.new(self)
context.exec(source, :pure => true) context.exec(source)
end end


def eval(source) def eval(source)
context = Context.new(self) context = Context.new(self)
context.eval(source, :pure => true) context.eval(source)
end end


def compile(source) def compile(source)
context = Context.new(self) Context.new(self, source)
context.exec(source)
context
end end


def available? def available?
Expand Down
11 changes: 5 additions & 6 deletions lib/execjs/ruby_racer_runtime.rb
@@ -1,8 +1,9 @@
module ExecJS module ExecJS
class RubyRacerRuntime class RubyRacerRuntime
class Context class Context
def initialize def initialize(source = "")
@v8_context = ::V8::Context.new @v8_context = ::V8::Context.new
@v8_context.eval(source)
end end


def exec(source, options = {}) def exec(source, options = {})
Expand Down Expand Up @@ -56,18 +57,16 @@ def name


def exec(source) def exec(source)
context = Context.new context = Context.new
context.exec(source, :pure => true) context.exec(source)
end end


def eval(source) def eval(source)
context = Context.new context = Context.new
context.eval(source, :pure => true) context.eval(source)
end end


def compile(source) def compile(source)
context = Context.new Context.new(source)
context.exec(source)
context
end end


def available? def available?
Expand Down
11 changes: 5 additions & 6 deletions lib/execjs/ruby_rhino_runtime.rb
@@ -1,8 +1,9 @@
module ExecJS module ExecJS
class RubyRhinoRuntime class RubyRhinoRuntime
class Context class Context
def initialize def initialize(source = "")
@rhino_context = ::Rhino::Context.new @rhino_context = ::Rhino::Context.new
@rhino_context.eval(source)
end end


def exec(source, options = {}) def exec(source, options = {})
Expand Down Expand Up @@ -54,18 +55,16 @@ def name


def exec(source) def exec(source)
context = Context.new context = Context.new
context.exec(source, :pure => true) context.exec(source)
end end


def eval(source) def eval(source)
context = Context.new context = Context.new
context.eval(source, :pure => true) context.eval(source)
end end


def compile(source) def compile(source)
context = Context.new Context.new(source)
context.exec(source)
context
end end


def available? def available?
Expand Down
5 changes: 0 additions & 5 deletions test/test_execjs.rb
Expand Up @@ -24,11 +24,6 @@ def test_compile
assert_equal "bar", context.eval("foo()") assert_equal "bar", context.eval("foo()")
end 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 def test_context_call
context = ExecJS.compile("id = function(v) { return v; }") context = ExecJS.compile("id = function(v) { return v; }")
assert_equal "bar", context.call("id", "bar") assert_equal "bar", context.call("id", "bar")
Expand Down

0 comments on commit c595c07

Please sign in to comment.