1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

0.10.0 branch sees incompatible changes to lambda embeddings.

This commit is contained in:
Charles Lowell 2011-10-06 15:06:48 -05:00
parent ba8a9dd92a
commit 52df3776b0
5 changed files with 33 additions and 17 deletions

View file

@ -2,11 +2,11 @@
module V8
class Portal
class Caller
def initialize(portal)
@portal = portal
end
def raw
yield
rescue Exception => e
@ -28,6 +28,7 @@ module V8
def invoke(code, *args, &block)
protect do
args = args.slice(0, code.arity) if code.arity >= 0
code.call(*args, &block)
end
end

View file

@ -6,7 +6,11 @@ module V8
def initialize(portal, code)
@portal = portal
@caller = code.respond_to?(:call) ? Call.new(portal) : BindAndCall.new(portal)
@caller = case code
when Method then BoundCall.new(portal)
when UnboundMethod then BindAndCall.new(portal)
else Call.new(portal)
end
@code = code
@template = V8::C::FunctionTemplate::New(@caller, @code)
end
@ -14,12 +18,23 @@ module V8
def function
@template.GetFunction()
end
class Call
def initialize(portal)
@portal = portal
end
def call(arguments)
proc = arguments.Data()
rbargs = [@portal.rb(arguments.This())]
for i in 0..arguments.Length() - 1
rbargs << @portal.rb(arguments[i])
end
@portal.caller.invoke(proc, *rbargs)
end
end
class BoundCall < Call
def call(arguments)
proc = arguments.Data()
rbargs = []
@ -29,7 +44,7 @@ module V8
@portal.caller.invoke(proc, *rbargs)
end
end
class BindAndCall < Call
def call(arguments)
method = arguments.Data()

View file

@ -1,3 +1,3 @@
module V8
VERSION = "0.9.9"
VERSION = "0.10.0beta1"
end

View file

@ -5,25 +5,25 @@ 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"
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|
@ -31,22 +31,22 @@ describe C::Function do
f.methodcall(this).should be(this)
end
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['say'] = lambda {|this, word, times| word * times}
cxt.eval('say("Hello", 3)').should == "HelloHelloHello"
end
end
it "has a name" do
Context.new do |cxt|
f = cxt.eval('(function hi() {return "Hello World"})', '<eval>')

@ -1 +1 @@
Subproject commit 5f0fb158e65d2723c32145891529ff9c3d2585e9
Subproject commit 1ebcd2a5766cec58f93d80308682ff7858320d3e