1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/spec/ext/func_spec.rb
2010-04-22 11:46:21 -05:00

42 lines
No EOL
1.2 KiB
Ruby

require "#{File.dirname(__FILE__)}/../spec_helper.rb"
include V8
describe C::Function do
it "is callable" do
C::Context.new.open do |cxt|
f = cxt.eval('(function() {return "Hello World"})', '<eval>');
f.Call(cxt.Global).should == "Hello World"
end
end
it "receives proper argument length from ruby" do
C::Context.new.open do |cxt|
f = cxt.eval('(function() {return arguments.length})', 'eval')
f.Call(nil,1, 2, 3).should == 3
end
end
it "maps all arguments from ruby" do
C::Context.new.open do |cxt|
f = cxt.eval('(function(one, two, three) {return one + two + three})', 'eval')
f.Call(nil, 1,2,3).should == 6
end
end
it "properly maps ruby objects back and forth from arguments to return value" do
C::Context.new.open do |cxt|
Object.new.tap do |this|
f = cxt.eval('(function() {return this})', 'eval')
f.Call(this).should be(this)
end
end
end
it "can be called outside of a context" do
C::Context.new.open do |cxt|
@f = cxt.eval('(function() {return "Call Me"})', 'eval')
end
@f.Call(nil).should == "Call Me"
end
end