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

add seeds for passing javascript objects back to ruby

This commit is contained in:
Charles Lowell 2009-10-22 21:45:41 -05:00
parent 68c968e109
commit c0d8d85b95
3 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,7 @@
#define __ruby_data_h__
#include <ruby.h>
#include <v8.h>
#include <stdio.h>
#include <string>
@ -87,6 +88,10 @@ class RubyDest {
VALUE pushUndefined(const char* name=0) {
return Qnil;
}
VALUE pushObject(v8::Handle<v8::Value>& value, const char* name = 0) {
return Qnil;
}
};

View file

@ -41,6 +41,14 @@ describe "The Ruby Racer" do
eval("true").should be(true)
eval("false").should be(false)
end
it "can pass objects back to ruby" do
eval("({foo: 'bar', baz: 'bang'})").tap do |object|
object.should_not be_nil
object['foo'].should == 'bar'
object['baz'].should == 'bang'
end
end
end

View file

@ -54,6 +54,12 @@ template<class T, class R> class V8HandleSource {
if(value->IsNumber()) {
return dest.pushDouble(value->NumberValue(), name);
}
if (value->IsObject()) {
return dest.pushObject(value, name);
}
return dest.pushNull(name);
}
};