Sha256: 8b2fdfe845c4e5f02de5e065f812b0a952a41e6950c4627a53637ff04392ee80

Contents?: true

Size: 1.29 KB

Versions: 17

Compression:

Stored size: 1.29 KB

Contents

require "#{File.dirname(__FILE__)}/../spec_helper.rb"

include V8

describe C::Function do
  it "is callable" do
    Context.new do |cxt|
      f = cxt.eval('(function() {return "Hello World"})', '<eval>');      
      f.call().should == "Hello World"      
    end
  end
  
  it "receives proper argument length from ruby" do
    Context.new do |cxt|
      f = cxt.eval('(function() {return arguments.length})', 'eval')
      f.call(1, 2, 3).should == 3
    end
  end
  
  it "maps all arguments from ruby" do
    Context.new do |cxt|
      f = cxt.eval('(function(one, two, three) {return one + two + three})', 'eval')
      f.call(1,2,3).should == 6
    end
  end
  
  it "properly maps ruby objects back and forth from arguments to return value" do
    Context.new do |cxt|
      Object.new.tap do |this|
         f = cxt.eval('(function() {return this})', 'eval')
         f.methodcall(this).should be(this)
      end
    end
  end 
  
  it "can be called outside of a context" do
    Context.new do |cxt|
      @f = cxt.eval('(function() {return "Call Me"})', 'eval')
    end
    @f.call().should == "Call Me"
  end
  
  it "is reflected properly" do
    Context.new do |cxt|
      cxt['say'] = lambda {|word, times| word * times}
      cxt.eval('say("Hello", 3)').should == "HelloHelloHello"
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
therubyracer-0.8.2.pre spec/ext/func_spec.rb
therubyracer-0.8.1 spec/ext/func_spec.rb
therubyracer-0.8.1.pre2 spec/ext/func_spec.rb
therubyracer-heroku-0.8.1.pre3 spec/ext/func_spec.rb
therubyracer-heroku-0.8.1.pre2 spec/ext/func_spec.rb
therubyracer-0.8.1.pre1 spec/ext/func_spec.rb
therubyracer-0.8.0 spec/ext/func_spec.rb
therubyracer-0.8.0.pre3 spec/ext/func_spec.rb
therubyracer-0.8.0.pre2 spec/ext/func_spec.rb
therubyracer-0.8.0.pre spec/ext/func_spec.rb
therubyracer-0.7.5 spec/ext/func_spec.rb
therubyracer-0.7.4 spec/ext/func_spec.rb
therubyracer-0.7.3 spec/ext/func_spec.rb
therubyracer-0.7.2 spec/ext/func_spec.rb
therubyracer-0.7.2.pre spec/ext/func_spec.rb
therubyracer-0.7.1 spec/ext/func_spec.rb
therubyracer-0.7.1.pre spec/ext/func_spec.rb